Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mattansb/analysis-of-factorial-designs-for-psychologists
Lesson files used in the Analysis of Factorial Designs for Psychologists.
https://github.com/mattansb/analysis-of-factorial-designs-for-psychologists
afex anova aov bgu-university emmeans psychologists rstats statistics teaching-materials
Last synced: 9 days ago
JSON representation
Lesson files used in the Analysis of Factorial Designs for Psychologists.
- Host: GitHub
- URL: https://github.com/mattansb/analysis-of-factorial-designs-for-psychologists
- Owner: mattansb
- License: other
- Created: 2020-02-02T14:45:23.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-01-31T07:15:09.000Z (almost 3 years ago)
- Last Synced: 2024-10-11T18:23:17.775Z (25 days ago)
- Topics: afex, anova, aov, bgu-university, emmeans, psychologists, rstats, statistics, teaching-materials
- Language: R
- Homepage:
- Size: 1.9 MB
- Stars: 75
- Watchers: 4
- Forks: 14
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---```{r setup, include=FALSE}
library(knitr)opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)
extract_pkgs <- function(fl) {
if (length(fl) == 1) {
txt <- read.delim(fl, header = FALSE)[[1]] |>
paste0(collapse = "\n")
pkg_lib <- stringr::str_extract_all(txt, pattern = "(?<=library\\().{1,}?(?=\\))")
pkg_req <- stringr::str_extract_all(txt, pattern = "(?<=require\\().{1,}?(?=\\))")
pkg_name <- stringr::str_extract_all(txt, pattern = "[a-z|A-Z|0-9]{1,}(?=\\:\\:)")
pkgs <- c(pkg_lib, pkg_req, pkg_name)
} else if (length(fl) > 1) {
pkgs <- sapply(fl, extract_pkgs)
}
pkgs |>
unlist(recursive = TRUE) |>
as.vector() |>
unique()
}make_pkg_table <- function(pkgs) {
# pkgs <- pkgs[sapply(pkgs, function(x) length(x) > 0)]
new_pkgs <- lapply(seq_along(pkgs), function(i) {
lesson_pkgs <- pkgs[[i]]
prev_lesson_pkgs <- unlist(head(pkgs,i-1))
!lesson_pkgs %in% prev_lesson_pkgs
})
ps <- sapply(seq_along(pkgs), function(idx) {
x <- pkgs[[idx]]
is_new <- ifelse(new_pkgs[[idx]], "**", "")
paste0(
glue::glue("[{is_new}`{x}`{is_new}](https://CRAN.R-project.org/package={x})"),
collapse = ", "
)
})
c("|Lesson|Packages|\n|----|----|\n", # header
glue::glue("|[{folder}](/{folder})|{ps}|\n\n",
folder = names(pkgs))) |>
paste0(collapse = "")
}get_src <- function(pkg) {
pd <- packageDescription(pkg)
if (is.null(src <- pd$Repository)) {
if (!is.null(src <- pd$GithubRepo)) {
src <- paste0("Github: ",pd$GithubUsername,"/",src)
} else {
src <- "Local version"
}
}
return(src)
}
```# Analysis of Factorial Designs foR Psychologists
[![](https://img.shields.io/badge/Open%20Educational%20Resources-Compatable-brightgreen)](https://creativecommons.org/about/program-areas/education-oer/)
[![](https://img.shields.io/badge/CC-BY--NC%204.0-lightgray)](http://creativecommons.org/licenses/by-nc/4.0/)
[![](https://img.shields.io/badge/Language-R-blue)](http://cran.r-project.org/)*Last updated `r Sys.Date()`.*
This Github repo contains all lesson files for *Analysis of Factorial Designs foR Psychologists*. The goal is to impart students with the basic tools to fit and evaluate **statistical models for factorial designs (w/ plots) using [`afex`](https://afex.singmann.science/)**, and and conduct **follow-up analyses (simple effects, planned contrasts, post-hoc test; w/ plots) using [`emmeans`](https://cran.r-project.org/package=emmeans)**. Although the focus is on ANOVAs, the materials regarding follow-up analyses (\~80\% of the course) are applicable to linear mixed models, and even regression with factorial predictors.
These topics were taught in the graduate-level course ***Analyses of Variance*** (Psych Dep., Ben-Gurion University of the Negev, *Spring, 2019*). This course assumes basic competence in R (importing, regression modeling, plotting, etc.), along the lines of [*Practical Applications in R for Psychologists*](https://github.com/mattansb/Practical-Applications-in-R-for-Psychologists).
**Notes:**
- This repo contains only materials relating to *Practical Applications in R*, and does not contain any theoretical or introductory materials.
- Please note that some code does not work *on purpose*, to force students to learn to debug.## Setup
You will need:
1. A fresh installation of [**`R`**](https://cran.r-project.org/) (preferably version 4.1 or above).
2. [RStudio IDE](https://www.rstudio.com/products/rstudio/download/) (optional, but recommended).
3. The following packages, listed by lesson:```{r, echo=FALSE}
r_list <- list.files(pattern = ".(R|r)$", recursive = TRUE, full.names = TRUE) |>
Filter(f = \(x) !stringr::str_detect(x, pattern = "(SOLUTION|logo)"))lesson_names <- stringr::str_extract(r_list, pattern = "(?<=(/)).{1,}(?=(/))")
r_list <- split(r_list, lesson_names)
pkgs <- lapply(r_list, extract_pkgs)
print_pkgs <- make_pkg_table(pkgs)
````r print_pkgs`
*(Bold denotes the first lesson in which the package was used.)*
You can install all the packages used by running:
```{r echo=FALSE, comment = "", warning=FALSE}
unique_pkgs <- pkgs |>
unlist(recursive = TRUE) |>
unique() |> sort()packinfo <- installed.packages(fields = c("Package", "Version"))
V <- packinfo[unique_pkgs,"Version"]
src <- sapply(unique_pkgs, get_src)cat("# in alphabetical order:")
cat("pkgs <-", dput(unique_pkgs) |> capture.output(), fill = 80) |>
capture.output() |>
styler::style_text()cat('install.packages(pkgs, repos = c("https://easystats.r-universe.dev", getOption("repos")))')
```Package Versions
Run on `r osVersion`, with R version `r packageVersion("base")`.
The packages used here:
```{r, echo=FALSE}
v_info <- paste0(glue::glue(" - `{unique_pkgs}` {V} (*{src}*)"), collapse = "\n")
````r v_info`