diff --git a/05-linear-mixed-effects-intro.Rmd b/05-linear-mixed-effects-intro.Rmd index 663b9f1..dae1b71 100644 --- a/05-linear-mixed-effects-intro.Rmd +++ b/05-linear-mixed-effects-intro.Rmd @@ -749,5 +749,5 @@ ggplot(sleep2, aes(x = days_deprived, y = Reaction)) + ## Multi-level app -[Try out the multi-level web app](https://shiny.psy.gla.ac.uk/Dale/multilevel){target="_blank"} to sharpen your understanding of the three different approaches to multi-level modeling. +[Try out the multi-level web app](https://rstudio-connect.psy.gla.ac.uk/multilevel){target="_blank"} to sharpen your understanding of the three different approaches to multi-level modeling. diff --git a/06-linear-mixed-effects-one.Rmd b/06-linear-mixed-effects-one.Rmd index 43cb3d8..ee1d329 100644 --- a/06-linear-mixed-effects-one.Rmd +++ b/06-linear-mixed-effects-one.Rmd @@ -84,7 +84,7 @@ One of the main selling points of the general linear models / regression framewo Let's consider a situation where you are testing the effect of alcohol consumption on simple reaction time (e.g., press a button as fast as you can after a light appears). To keep it simple, let's assume that you have collected data from 14 participants randomly assigned to perform a set of 10 simple RT trials after one of two interventions: drinking a pint of alcohol (treatment condition) or a placebo drink (placebo condition). You have 7 participants in each of the two groups. Note that you would need more than this for a real study. -This [web app](https://shiny.psy.gla.ac.uk/Dale/icc){target="_blank"} presents simulated data from such a study. Subjects P01-P07 are from the placebo condition, while subjects T01-T07 are from the treatment condition. Please stop and have a look! +This [web app](https://rstudio-connect.psy.gla.ac.uk/icc){target="_blank"} presents simulated data from such a study. Subjects P01-P07 are from the placebo condition, while subjects T01-T07 are from the treatment condition. Please stop and have a look! If we were going to run a t-test on these data, we would first need to calculate subject means, because otherwise the observations are not independent. You could do this as follows. (If you want to run the code below, you can download sample data from the web app above and save it as `independent_samples.csv`). diff --git a/07-crossed-random-factors.Rmd b/07-crossed-random-factors.Rmd index d0a7c53..b988c6e 100644 --- a/07-crossed-random-factors.Rmd +++ b/07-crossed-random-factors.Rmd @@ -231,7 +231,7 @@ For more technical details about convergence problems and what to do, see `?lme4 ## Simulating data with crossed random factors -For these exercises, we will generate simulated data corresponding to an experiment with a single, two-level factor (independent variable) that is within-subjects and between-items. Let's imagine that the experiment involves lexical decisions to a set of words (e.g., is "PINT" a word or nonword?), and the dependent variable is response time (in milliseconds), and the independent variable is word type (noun vs verb). We want to treat both subjects and words as random factors (so that we can generalize to the population of events where subjects encounter words). You can play around with the web app (or [click here to open it in a new window](https://shiny.psy.gla.ac.uk/Dale/crossed){target="_blank"}), which allows you to manipulate the data-generating parameters and see their effect on the data. +For these exercises, we will generate simulated data corresponding to an experiment with a single, two-level factor (independent variable) that is within-subjects and between-items. Let's imagine that the experiment involves lexical decisions to a set of words (e.g., is "PINT" a word or nonword?), and the dependent variable is response time (in milliseconds), and the independent variable is word type (noun vs verb). We want to treat both subjects and words as random factors (so that we can generalize to the population of events where subjects encounter words). You can play around with the web app (or [click here to open it in a new window](https://rstudio-connect.psy.gla.ac.uk/crossed){target="_blank"}), which allows you to manipulate the data-generating parameters and see their effect on the data. By now, you should have all the pieces of the puzzle that you need to simulate data from a study with crossed random effects. @Debruine_Barr_2020 provides a more detailed, step-by-step walkthrough of the exercise below. diff --git a/08-generalized-linear-models.Rmd b/08-generalized-linear-models.Rmd index 1d1b20d..612eb99 100644 --- a/08-generalized-linear-models.Rmd +++ b/08-generalized-linear-models.Rmd @@ -151,8 +151,8 @@ $$np(1 - p).$$ The app below allows you to manipulate the intercept and slope of a line in log odds space and to see the projection of the line back into response space. Note the S-shaped ("sigmoidal") shape of the function in the response shape. -```{r logit-app, echo=FALSE, fig.cap="**Logistic regression web app** "} -knitr::include_app("https://shiny.psy.gla.ac.uk/Dale/logit", "800px") +```{r logit-app, echo=FALSE, fig.cap="**Logistic regression web app** "} +knitr::include_app("https://rstudio-connect.psy.gla.ac.uk/logit", "800px") ``` ### Estimating logistic regression models in R diff --git a/docs/01-introduction_files/figure-html/basic-glm-1.png b/docs/01-introduction_files/figure-html/basic-glm-1.png index 885ec60..1a2f196 100644 Binary files a/docs/01-introduction_files/figure-html/basic-glm-1.png and b/docs/01-introduction_files/figure-html/basic-glm-1.png differ diff --git a/docs/01-introduction_files/figure-html/tryptych-1.png b/docs/01-introduction_files/figure-html/tryptych-1.png index 4f8e227..8b50c22 100644 Binary files a/docs/01-introduction_files/figure-html/tryptych-1.png and b/docs/01-introduction_files/figure-html/tryptych-1.png differ diff --git a/docs/02-correlation-regression.md b/docs/02-correlation-regression.md index 7f79b41..6b35a58 100644 --- a/docs/02-correlation-regression.md +++ b/docs/02-correlation-regression.md @@ -44,18 +44,18 @@ starwars %>% ``` ``` -## -## Correlation method: 'pearson' -## Missing treated using: 'pairwise.complete.obs' +## Correlation computed with +## • Method: 'pearson' +## • Missing treated using: 'pairwise.complete.obs' ``` ``` ## # A tibble: 3 × 4 ## term height mass birth_year ## -## 1 height NA 0.134 -0.400 -## 2 mass 0.134 NA 0.478 -## 3 birth_year -0.400 0.478 NA +## 1 height NA 0.131 -0.404 +## 2 mass 0.131 NA 0.478 +## 3 birth_year -0.404 0.478 NA ``` You can look up any bivariate correlation at the intersection of any given row or column. So the correlation between `height` and `mass` is .134, which you can find in row 1, column 2 or row 2, column 1; the values are the same. Note that there are only `choose(3, 2)` = 3 unique bivariate relationships, but each appears twice in the table. We might want to show only the unique pairs. We can do this by appending `corrr::shave()` to our pipeline. @@ -69,9 +69,9 @@ starwars %>% ``` ``` -## -## Correlation method: 'pearson' -## Missing treated using: 'pairwise.complete.obs' +## Correlation computed with +## • Method: 'pearson' +## • Missing treated using: 'pairwise.complete.obs' ``` ``` @@ -79,8 +79,8 @@ starwars %>% ## term height mass birth_year ## ## 1 height NA NA NA -## 2 mass 0.134 NA NA -## 3 birth_year -0.400 0.478 NA +## 2 mass 0.131 NA NA +## 3 birth_year -0.404 0.478 NA ``` Now we've only got the lower triangle of the correlation matrix, but the `NA` values are ugly and so are the leading zeroes. The **`corrr`** package also provides the `fashion()` function that cleans things up (see `?corrr::fashion` for more options). @@ -95,9 +95,9 @@ starwars %>% ``` ``` -## -## Correlation method: 'pearson' -## Missing treated using: 'pairwise.complete.obs' +## Correlation computed with +## • Method: 'pearson' +## • Missing treated using: 'pairwise.complete.obs' ``` ``` @@ -193,16 +193,16 @@ starwars3 %>% ``` ``` -## -## Correlation method: 'pearson' -## Missing treated using: 'pairwise.complete.obs' +## Correlation computed with +## • Method: 'pearson' +## • Missing treated using: 'pairwise.complete.obs' ``` ``` ## term height mass birth_year ## 1 height -## 2 mass .74 -## 3 birth_year .45 .24 +## 2 mass .73 +## 3 birth_year .44 .24 ``` Note that these values are quite different from the ones we started with. @@ -219,16 +219,16 @@ starwars %>% ``` ``` -## -## Correlation method: 'spearman' -## Missing treated using: 'pairwise.complete.obs' +## Correlation computed with +## • Method: 'spearman' +## • Missing treated using: 'pairwise.complete.obs' ``` ``` ## term height mass birth_year ## 1 height -## 2 mass .75 -## 3 birth_year .16 .15 +## 2 mass .72 +## 3 birth_year .15 .15 ``` Incidentally, if you are generating a report from R Markdown and want your tables to be nicely formatted you can use `knitr::kable()`. @@ -261,13 +261,13 @@ starwars %>% mass - .75 + .72 birth_year - .16 + .15 .15 diff --git a/docs/02-correlation-regression_files/figure-html/bye-yoda-1.png b/docs/02-correlation-regression_files/figure-html/bye-yoda-1.png index b6feef2..ec13c9d 100644 Binary files a/docs/02-correlation-regression_files/figure-html/bye-yoda-1.png and b/docs/02-correlation-regression_files/figure-html/bye-yoda-1.png differ diff --git a/docs/02-correlation-regression_files/figure-html/correlation-relationships-1.png b/docs/02-correlation-regression_files/figure-html/correlation-relationships-1.png index 543e55d..33d921a 100644 Binary files a/docs/02-correlation-regression_files/figure-html/correlation-relationships-1.png and b/docs/02-correlation-regression_files/figure-html/correlation-relationships-1.png differ diff --git a/docs/02-correlation-regression_files/figure-html/handw-log-1.png b/docs/02-correlation-regression_files/figure-html/handw-log-1.png index 6ecc891..619cd5f 100644 Binary files a/docs/02-correlation-regression_files/figure-html/handw-log-1.png and b/docs/02-correlation-regression_files/figure-html/handw-log-1.png differ diff --git a/docs/02-correlation-regression_files/figure-html/heights-and-weights-1.png b/docs/02-correlation-regression_files/figure-html/heights-and-weights-1.png index 9b3bb0c..4f0eafa 100644 Binary files a/docs/02-correlation-regression_files/figure-html/heights-and-weights-1.png and b/docs/02-correlation-regression_files/figure-html/heights-and-weights-1.png differ diff --git a/docs/02-correlation-regression_files/figure-html/massive-creature-1.png b/docs/02-correlation-regression_files/figure-html/massive-creature-1.png index 7d7335e..01cff5f 100644 Binary files a/docs/02-correlation-regression_files/figure-html/massive-creature-1.png and b/docs/02-correlation-regression_files/figure-html/massive-creature-1.png differ diff --git a/docs/02-correlation-regression_files/figure-html/pairs-1.png b/docs/02-correlation-regression_files/figure-html/pairs-1.png index 96d6bb7..f7bf6a7 100644 Binary files a/docs/02-correlation-regression_files/figure-html/pairs-1.png and b/docs/02-correlation-regression_files/figure-html/pairs-1.png differ diff --git a/docs/02-correlation-regression_files/figure-html/plot-together-1.png b/docs/02-correlation-regression_files/figure-html/plot-together-1.png index 9a4897e..7472e1b 100644 Binary files a/docs/02-correlation-regression_files/figure-html/plot-together-1.png and b/docs/02-correlation-regression_files/figure-html/plot-together-1.png differ diff --git a/docs/02-correlation-regression_files/figure-html/scatter-with-line-1.png b/docs/02-correlation-regression_files/figure-html/scatter-with-line-1.png index 81872d3..6640d0a 100644 Binary files a/docs/02-correlation-regression_files/figure-html/scatter-with-line-1.png and b/docs/02-correlation-regression_files/figure-html/scatter-with-line-1.png differ diff --git a/docs/03-multiple-regression.md b/docs/03-multiple-regression.md index cee8ae1..4dff9f8 100644 --- a/docs/03-multiple-regression.md +++ b/docs/03-multiple-regression.md @@ -62,9 +62,9 @@ grades %>% ``` ``` -## -## Correlation method: 'pearson' -## Missing treated using: 'pairwise.complete.obs' +## Correlation computed with +## • Method: 'pearson' +## • Missing treated using: 'pairwise.complete.obs' ``` ``` @@ -502,16 +502,16 @@ fake_data ## # A tibble: 10 × 2 ## Y group ## -## 1 2.41 A -## 2 -0.232 A -## 3 0.695 A -## 4 0.869 A -## 5 0.112 A -## 6 -1.28 B -## 7 -1.40 B -## 8 2.04 B -## 9 -1.67 B -## 10 -1.35 B +## 1 0.776 A +## 2 0.175 A +## 3 -0.466 A +## 4 -1.40 A +## 5 -0.498 A +## 6 0.536 B +## 7 0.527 B +## 8 -2.06 B +## 9 -0.894 B +## 10 -1.22 B ``` Now let's add a new variable, `group_d`, which is the dummy coded group variable. We will use the `dplyr::if_else()` function to define the new column. @@ -528,16 +528,16 @@ fake_data2 ## # A tibble: 10 × 3 ## Y group group_d ## -## 1 2.41 A 0 -## 2 -0.232 A 0 -## 3 0.695 A 0 -## 4 0.869 A 0 -## 5 0.112 A 0 -## 6 -1.28 B 1 -## 7 -1.40 B 1 -## 8 2.04 B 1 -## 9 -1.67 B 1 -## 10 -1.35 B 1 +## 1 0.776 A 0 +## 2 0.175 A 0 +## 3 -0.466 A 0 +## 4 -1.40 A 0 +## 5 -0.498 A 0 +## 6 0.536 B 1 +## 7 0.527 B 1 +## 8 -2.06 B 1 +## 9 -0.894 B 1 +## 10 -1.22 B 1 ``` Now we just run it as a regular regression model. @@ -553,17 +553,17 @@ summary(lm(Y ~ group_d, fake_data2)) ## lm(formula = Y ~ group_d, data = fake_data2) ## ## Residuals: -## Min 1Q Median 3Q Max -## -1.00245 -0.66524 -0.58396 0.05511 2.77151 +## Min 1Q Median 3Q Max +## -1.4380 -0.5167 -0.2001 0.9078 1.1582 ## ## Coefficients: ## Estimate Std. Error t value Pr(>|t|) -## (Intercept) 0.7700 0.5878 1.310 0.227 -## group_d -1.5023 0.8312 -1.807 0.108 +## (Intercept) -0.2816 0.4420 -0.637 0.542 +## group_d -0.3408 0.6251 -0.545 0.601 ## -## Residual standard error: 1.314 on 8 degrees of freedom -## Multiple R-squared: 0.2899, Adjusted R-squared: 0.2012 -## F-statistic: 3.266 on 1 and 8 DF, p-value: 0.1083 +## Residual standard error: 0.9883 on 8 degrees of freedom +## Multiple R-squared: 0.03582, Adjusted R-squared: -0.0847 +## F-statistic: 0.2972 on 1 and 8 DF, p-value: 0.6005 ``` Let's reverse the coding. We get the same result, just the sign is different. @@ -582,17 +582,17 @@ summary(lm(Y ~ group_d, fake_data3)) ## lm(formula = Y ~ group_d, data = fake_data3) ## ## Residuals: -## Min 1Q Median 3Q Max -## -1.00245 -0.66524 -0.58396 0.05511 2.77151 +## Min 1Q Median 3Q Max +## -1.4380 -0.5167 -0.2001 0.9078 1.1582 ## ## Coefficients: ## Estimate Std. Error t value Pr(>|t|) -## (Intercept) -0.7322 0.5878 -1.246 0.248 -## group_d 1.5023 0.8312 1.807 0.108 +## (Intercept) -0.6224 0.4420 -1.408 0.197 +## group_d 0.3408 0.6251 0.545 0.601 ## -## Residual standard error: 1.314 on 8 degrees of freedom -## Multiple R-squared: 0.2899, Adjusted R-squared: 0.2012 -## F-statistic: 3.266 on 1 and 8 DF, p-value: 0.1083 +## Residual standard error: 0.9883 on 8 degrees of freedom +## Multiple R-squared: 0.03582, Adjusted R-squared: -0.0847 +## F-statistic: 0.2972 on 1 and 8 DF, p-value: 0.6005 ``` The interpretation of the intercept is the estimated mean for the group coded as zero. You can see by plugging in zero for X in the prediction formula below. Thus, $\beta_1$ can be interpreted as the difference between the mean for the baseline group and the group coded as 1. @@ -613,17 +613,17 @@ lm(Y ~ group, fake_data) %>% ## lm(formula = Y ~ group, data = fake_data) ## ## Residuals: -## Min 1Q Median 3Q Max -## -1.00245 -0.66524 -0.58396 0.05511 2.77151 +## Min 1Q Median 3Q Max +## -1.4380 -0.5167 -0.2001 0.9078 1.1582 ## ## Coefficients: ## Estimate Std. Error t value Pr(>|t|) -## (Intercept) 0.7700 0.5878 1.310 0.227 -## groupB -1.5023 0.8312 -1.807 0.108 +## (Intercept) -0.2816 0.4420 -0.637 0.542 +## groupB -0.3408 0.6251 -0.545 0.601 ## -## Residual standard error: 1.314 on 8 degrees of freedom -## Multiple R-squared: 0.2899, Adjusted R-squared: 0.2012 -## F-statistic: 3.266 on 1 and 8 DF, p-value: 0.1083 +## Residual standard error: 0.9883 on 8 degrees of freedom +## Multiple R-squared: 0.03582, Adjusted R-squared: -0.0847 +## F-statistic: 0.2972 on 1 and 8 DF, p-value: 0.6005 ``` The `lm()` function examines `group` and figures out the unique levels of the variable, which in this case are `A` and `B`. It then chooses as baseline the level that comes first alphabetically, and encodes the contrast between the other level (`B`) and the baseline level (`A`). (In the case where `group` has been defined as a factor, the baseline level is the first element of `levels(fake_data$group)`). @@ -650,26 +650,26 @@ season_wt ## # A tibble: 20 × 2 ## season bodyweight_kg ## -## 1 winter 108. -## 2 winter 107. -## 3 winter 106. -## 4 winter 101. -## 5 winter 112. -## 6 spring 105. -## 7 spring 101. -## 8 spring 98.0 -## 9 spring 105. -## 10 spring 101. -## 11 summer 99.2 -## 12 summer 102. -## 13 summer 102. -## 14 summer 95.5 -## 15 summer 103. -## 16 fall 103. -## 17 fall 103. -## 18 fall 103. -## 19 fall 105. -## 20 fall 102. +## 1 winter 107. +## 2 winter 105. +## 3 winter 106. +## 4 winter 107. +## 5 winter 105. +## 6 spring 101. +## 7 spring 102. +## 8 spring 103. +## 9 spring 108. +## 10 spring 105. +## 11 summer 106. +## 12 summer 102. +## 13 summer 100. +## 14 summer 103. +## 15 summer 102. +## 16 fall 107. +## 17 fall 105. +## 18 fall 103. +## 19 fall 101. +## 20 fall 101. ``` Now let's add three predictors to code the variable `season`. Try it out and see if you can figure out how it works. @@ -689,26 +689,26 @@ season_wt2 ## # A tibble: 20 × 5 ## season bodyweight_kg spring_v_winter summer_v_winter fall_v_winter ## -## 1 winter 108. 0 0 0 -## 2 winter 107. 0 0 0 -## 3 winter 106. 0 0 0 -## 4 winter 101. 0 0 0 -## 5 winter 112. 0 0 0 -## 6 spring 105. 1 0 0 -## 7 spring 101. 1 0 0 -## 8 spring 98.0 1 0 0 -## 9 spring 105. 1 0 0 -## 10 spring 101. 1 0 0 -## 11 summer 99.2 0 1 0 -## 12 summer 102. 0 1 0 -## 13 summer 102. 0 1 0 -## 14 summer 95.5 0 1 0 -## 15 summer 103. 0 1 0 -## 16 fall 103. 0 0 1 -## 17 fall 103. 0 0 1 -## 18 fall 103. 0 0 1 -## 19 fall 105. 0 0 1 -## 20 fall 102. 0 0 1 +## 1 winter 107. 0 0 0 +## 2 winter 105. 0 0 0 +## 3 winter 106. 0 0 0 +## 4 winter 107. 0 0 0 +## 5 winter 105. 0 0 0 +## 6 spring 101. 1 0 0 +## 7 spring 102. 1 0 0 +## 8 spring 103. 1 0 0 +## 9 spring 108. 1 0 0 +## 10 spring 105. 1 0 0 +## 11 summer 106. 0 1 0 +## 12 summer 102. 0 1 0 +## 13 summer 100. 0 1 0 +## 14 summer 103. 0 1 0 +## 15 summer 102. 0 1 0 +## 16 fall 107. 0 0 1 +## 17 fall 105. 0 0 1 +## 18 fall 103. 0 0 1 +## 19 fall 101. 0 0 1 +## 20 fall 101. 0 0 1 ``` :::{.warning} @@ -744,7 +744,7 @@ lm(bodyweight_kg ~ spring_v_winter + summer_v_winter + fall_v_winter, ## ## Coefficients: ## (Intercept) spring_v_winter summer_v_winter fall_v_winter -## 103.4081 -1.4343 NA -0.2239 +## 104.2673 -0.3439 NA -0.9552 ``` What happened? Let's look at the data to find out. We will use `distinct` to find the distinct combinations of our original variable `season` with the three variables we created (see `?dplyr::distinct` for details). @@ -787,20 +787,20 @@ lm(bodyweight_kg ~ season, season_wt) %>% ## ## Residuals: ## Min 1Q Median 3Q Max -## -6.0273 -0.8942 -0.1037 1.6187 5.2044 +## -2.7820 -1.1927 -0.6222 0.9015 3.8698 ## ## Coefficients: ## Estimate Std. Error t value Pr(>|t|) -## (Intercept) 103.184 1.304 79.121 <2e-16 *** -## seasonspring -1.210 1.844 -0.656 0.521 -## seasonsummer -3.025 1.844 -1.640 0.120 -## seasonwinter 3.473 1.844 1.883 0.078 . +## (Intercept) 103.3121 0.9597 107.648 <2e-16 *** +## seasonspring 0.6114 1.3572 0.450 0.6584 +## seasonsummer -0.7879 1.3572 -0.581 0.5696 +## seasonwinter 2.6984 1.3572 1.988 0.0642 . ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## -## Residual standard error: 2.916 on 16 degrees of freedom -## Multiple R-squared: 0.453, Adjusted R-squared: 0.3504 -## F-statistic: 4.416 on 3 and 16 DF, p-value: 0.01916 +## Residual standard error: 2.146 on 16 degrees of freedom +## Multiple R-squared: 0.3121, Adjusted R-squared: 0.1831 +## F-statistic: 2.42 on 3 and 16 DF, p-value: 0.104 ``` Here, R implicitly creates three dummy variables to code the four levels of `season`, called `seasonspring`, `seasonsummer` and `seasonwinter`. The unmentioned season, `fall`, has been chosen as baseline because it comes earliest in the alphabet. These three predictors have the following values: @@ -828,11 +828,9 @@ summary(my_anova) ``` ``` -## Df Sum Sq Mean Sq F value Pr(>F) -## season 3 112.7 37.55 4.416 0.0192 * -## Residuals 16 136.1 8.50 -## --- -## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 +## Df Sum Sq Mean Sq F value Pr(>F) +## season 3 33.43 11.143 2.42 0.104 +## Residuals 16 73.68 4.605 ``` OK, now can we replicate that result using the regression model below? @@ -854,20 +852,20 @@ summary(lm(bodyweight_kg ~ spring_v_winter + ## ## Residuals: ## Min 1Q Median 3Q Max -## -6.0273 -0.8942 -0.1037 1.6187 5.2044 +## -2.7820 -1.1927 -0.6222 0.9015 3.8698 ## ## Coefficients: ## Estimate Std. Error t value Pr(>|t|) -## (Intercept) 106.657 1.304 81.784 < 2e-16 *** -## spring_v_winter -4.683 1.844 -2.539 0.02187 * -## summer_v_winter -6.498 1.844 -3.523 0.00282 ** -## fall_v_winter -3.473 1.844 -1.883 0.07800 . +## (Intercept) 106.0105 0.9597 110.460 <2e-16 *** +## spring_v_winter -2.0870 1.3572 -1.538 0.1437 +## summer_v_winter -3.4863 1.3572 -2.569 0.0206 * +## fall_v_winter -2.6984 1.3572 -1.988 0.0642 . ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## -## Residual standard error: 2.916 on 16 degrees of freedom -## Multiple R-squared: 0.453, Adjusted R-squared: 0.3504 -## F-statistic: 4.416 on 3 and 16 DF, p-value: 0.01916 +## Residual standard error: 2.146 on 16 degrees of freedom +## Multiple R-squared: 0.3121, Adjusted R-squared: 0.1831 +## F-statistic: 2.42 on 3 and 16 DF, p-value: 0.104 ``` Note that the $F$ values and $p$ values are identical for the two methods! diff --git a/docs/03-multiple-regression_files/figure-html/pairs-1.png b/docs/03-multiple-regression_files/figure-html/pairs-1.png index 4e96178..2581cf0 100644 Binary files a/docs/03-multiple-regression_files/figure-html/pairs-1.png and b/docs/03-multiple-regression_files/figure-html/pairs-1.png differ diff --git a/docs/03-multiple-regression_files/figure-html/partial-lecture-plot-1.png b/docs/03-multiple-regression_files/figure-html/partial-lecture-plot-1.png index 5a3fa72..efd88a5 100644 Binary files a/docs/03-multiple-regression_files/figure-html/partial-lecture-plot-1.png and b/docs/03-multiple-regression_files/figure-html/partial-lecture-plot-1.png differ diff --git a/docs/03-multiple-regression_files/figure-html/partial-nclicks-1.png b/docs/03-multiple-regression_files/figure-html/partial-nclicks-1.png index 4d6582d..f69387d 100644 Binary files a/docs/03-multiple-regression_files/figure-html/partial-nclicks-1.png and b/docs/03-multiple-regression_files/figure-html/partial-nclicks-1.png differ diff --git a/docs/04-interactions.md b/docs/04-interactions.md index 5d90a2a..027d04f 100644 --- a/docs/04-interactions.md +++ b/docs/04-interactions.md @@ -269,7 +269,7 @@ $$Y_{i} = \beta_0 + \beta_1 X_{1i} + \beta_2 X_{2i} + \beta_3 X_{1i} X_{2i} + e_ - $\hat{\beta}_0$: - $\hat{\beta}_1$: -- $\hat{\beta}_2$: +- $\hat{\beta}_2$: - $\hat{\beta}_3$: Based on these parameter estimates, the regression line for the (baseline) urban group is: diff --git a/docs/04-interactions_files/figure-html/combined-plot-1.png b/docs/04-interactions_files/figure-html/combined-plot-1.png index 74f6815..bed0402 100644 Binary files a/docs/04-interactions_files/figure-html/combined-plot-1.png and b/docs/04-interactions_files/figure-html/combined-plot-1.png differ diff --git a/docs/04-interactions_files/figure-html/plot-urban-1.png b/docs/04-interactions_files/figure-html/plot-urban-1.png index dd78847..856e375 100644 Binary files a/docs/04-interactions_files/figure-html/plot-urban-1.png and b/docs/04-interactions_files/figure-html/plot-urban-1.png differ diff --git a/docs/04-interactions_files/figure-html/scenario-a-plot-1.png b/docs/04-interactions_files/figure-html/scenario-a-plot-1.png index 50b26fc..83b17c2 100644 Binary files a/docs/04-interactions_files/figure-html/scenario-a-plot-1.png and b/docs/04-interactions_files/figure-html/scenario-a-plot-1.png differ diff --git a/docs/04-interactions_files/figure-html/scenario-b-plot-1.png b/docs/04-interactions_files/figure-html/scenario-b-plot-1.png index f79ae3d..69f1918 100644 Binary files a/docs/04-interactions_files/figure-html/scenario-b-plot-1.png and b/docs/04-interactions_files/figure-html/scenario-b-plot-1.png differ diff --git a/docs/04-interactions_files/figure-html/scenario-c-plot-1.png b/docs/04-interactions_files/figure-html/scenario-c-plot-1.png index 7d01398..1038c1f 100644 Binary files a/docs/04-interactions_files/figure-html/scenario-c-plot-1.png and b/docs/04-interactions_files/figure-html/scenario-c-plot-1.png differ diff --git a/docs/05-linear-mixed-effects-intro.md b/docs/05-linear-mixed-effects-intro.md index 121a9ea..a59d212 100644 --- a/docs/05-linear-mixed-effects-intro.md +++ b/docs/05-linear-mixed-effects-intro.md @@ -1111,5 +1111,5 @@ ggplot(sleep2, aes(x = days_deprived, y = Reaction)) + ## Multi-level app -[Try out the multi-level web app](https://shiny.psy.gla.ac.uk/Dale/multilevel){target="_blank"} to sharpen your understanding of the three different approaches to multi-level modeling. +[Try out the multi-level web app](https://rstudio-connect.psy.gla.ac.uk/multilevel){target="_blank"} to sharpen your understanding of the three different approaches to multi-level modeling. diff --git a/docs/05-linear-mixed-effects-intro_files/figure-html/cp-model-plot-1.png b/docs/05-linear-mixed-effects-intro_files/figure-html/cp-model-plot-1.png index 7802a97..db81f46 100644 Binary files a/docs/05-linear-mixed-effects-intro_files/figure-html/cp-model-plot-1.png and b/docs/05-linear-mixed-effects-intro_files/figure-html/cp-model-plot-1.png differ diff --git a/docs/05-linear-mixed-effects-intro_files/figure-html/extrap-plot-1.png b/docs/05-linear-mixed-effects-intro_files/figure-html/extrap-plot-1.png index e15a6d9..efc8d9a 100644 Binary files a/docs/05-linear-mixed-effects-intro_files/figure-html/extrap-plot-1.png and b/docs/05-linear-mixed-effects-intro_files/figure-html/extrap-plot-1.png differ diff --git a/docs/05-linear-mixed-effects-intro_files/figure-html/np-model-fits-1.png b/docs/05-linear-mixed-effects-intro_files/figure-html/np-model-fits-1.png index 3c2044d..4c254f5 100644 Binary files a/docs/05-linear-mixed-effects-intro_files/figure-html/np-model-fits-1.png and b/docs/05-linear-mixed-effects-intro_files/figure-html/np-model-fits-1.png differ diff --git a/docs/05-linear-mixed-effects-intro_files/figure-html/one-subject-1.png b/docs/05-linear-mixed-effects-intro_files/figure-html/one-subject-1.png index f47bf9d..8bb2472 100644 Binary files a/docs/05-linear-mixed-effects-intro_files/figure-html/one-subject-1.png and b/docs/05-linear-mixed-effects-intro_files/figure-html/one-subject-1.png differ diff --git a/docs/05-linear-mixed-effects-intro_files/figure-html/plot-solution0-1.png b/docs/05-linear-mixed-effects-intro_files/figure-html/plot-solution0-1.png index b298392..b9f204d 100644 Binary files a/docs/05-linear-mixed-effects-intro_files/figure-html/plot-solution0-1.png and b/docs/05-linear-mixed-effects-intro_files/figure-html/plot-solution0-1.png differ diff --git a/docs/05-linear-mixed-effects-intro_files/figure-html/plot-solution2-1.png b/docs/05-linear-mixed-effects-intro_files/figure-html/plot-solution2-1.png index f93d782..61925ba 100644 Binary files a/docs/05-linear-mixed-effects-intro_files/figure-html/plot-solution2-1.png and b/docs/05-linear-mixed-effects-intro_files/figure-html/plot-solution2-1.png differ diff --git a/docs/05-linear-mixed-effects-intro_files/figure-html/pp-plot-1.png b/docs/05-linear-mixed-effects-intro_files/figure-html/pp-plot-1.png index ee82fca..2d658a4 100644 Binary files a/docs/05-linear-mixed-effects-intro_files/figure-html/pp-plot-1.png and b/docs/05-linear-mixed-effects-intro_files/figure-html/pp-plot-1.png differ diff --git a/docs/06-linear-mixed-effects-one.md b/docs/06-linear-mixed-effects-one.md index 90dbd12..aee3a8a 100644 --- a/docs/06-linear-mixed-effects-one.md +++ b/docs/06-linear-mixed-effects-one.md @@ -157,7 +157,7 @@ One of the main selling points of the general linear models / regression framewo Let's consider a situation where you are testing the effect of alcohol consumption on simple reaction time (e.g., press a button as fast as you can after a light appears). To keep it simple, let's assume that you have collected data from 14 participants randomly assigned to perform a set of 10 simple RT trials after one of two interventions: drinking a pint of alcohol (treatment condition) or a placebo drink (placebo condition). You have 7 participants in each of the two groups. Note that you would need more than this for a real study. -This [web app](https://shiny.psy.gla.ac.uk/Dale/icc){target="_blank"} presents simulated data from such a study. Subjects P01-P07 are from the placebo condition, while subjects T01-T07 are from the treatment condition. Please stop and have a look! +This [web app](https://rstudio-connect.psy.gla.ac.uk/icc){target="_blank"} presents simulated data from such a study. Subjects P01-P07 are from the placebo condition, while subjects T01-T07 are from the treatment condition. Please stop and have a look! If we were going to run a t-test on these data, we would first need to calculate subject means, because otherwise the observations are not independent. You could do this as follows. (If you want to run the code below, you can download sample data from the web app above and save it as `independent_samples.csv`). diff --git a/docs/07-crossed-random-factors.md b/docs/07-crossed-random-factors.md index a89b509..bffe1ec 100644 --- a/docs/07-crossed-random-factors.md +++ b/docs/07-crossed-random-factors.md @@ -100,23 +100,23 @@ Then you sample a set of four participants to perform the soothing ratings. Agai 1 - 19 - 2020-04-30 + 70 + 2020-05-25 2 - 47 - 2020-05-06 + 21 + 2020-05-26 3 - 34 - 2020-05-09 + 31 + 2020-05-27 4 - 20 - 2020-05-23 + 37 + 2020-05-29 @@ -698,7 +698,7 @@ For more technical details about convergence problems and what to do, see `?lme4 ## Simulating data with crossed random factors -For these exercises, we will generate simulated data corresponding to an experiment with a single, two-level factor (independent variable) that is within-subjects and between-items. Let's imagine that the experiment involves lexical decisions to a set of words (e.g., is "PINT" a word or nonword?), and the dependent variable is response time (in milliseconds), and the independent variable is word type (noun vs verb). We want to treat both subjects and words as random factors (so that we can generalize to the population of events where subjects encounter words). You can play around with the web app (or [click here to open it in a new window](https://shiny.psy.gla.ac.uk/Dale/crossed){target="_blank"}), which allows you to manipulate the data-generating parameters and see their effect on the data. +For these exercises, we will generate simulated data corresponding to an experiment with a single, two-level factor (independent variable) that is within-subjects and between-items. Let's imagine that the experiment involves lexical decisions to a set of words (e.g., is "PINT" a word or nonword?), and the dependent variable is response time (in milliseconds), and the independent variable is word type (noun vs verb). We want to treat both subjects and words as random factors (so that we can generalize to the population of events where subjects encounter words). You can play around with the web app (or [click here to open it in a new window](https://rstudio-connect.psy.gla.ac.uk/crossed){target="_blank"}), which allows you to manipulate the data-generating parameters and see their effect on the data. By now, you should have all the pieces of the puzzle that you need to simulate data from a study with crossed random effects. @Debruine_Barr_2020 provides a more detailed, step-by-step walkthrough of the exercise below. diff --git a/docs/08-generalized-linear-models.md b/docs/08-generalized-linear-models.md index 9dfbdc1..73622bb 100644 --- a/docs/08-generalized-linear-models.md +++ b/docs/08-generalized-linear-models.md @@ -58,8 +58,8 @@ rainy_days %>% ## # A tibble: 2 × 2 ## city variance ## -## 1 Barcelona 45.1 -## 2 Glasgow 92.4 +## 1 Barcelona 46.4 +## 2 Glasgow 93.9 ``` With binomially distributed data, the variance is given by $np(1-p)$ where $n$ is the number of observations and $p$ is the probability of 'success' (in the above example, the probability of rain on a given day). The plot below shows this for $n=1000$; note how the variance peaks at 0.5 and gets small as the probability approaches 0 and 1. @@ -143,8 +143,8 @@ $$np(1 - p).$$ The app below allows you to manipulate the intercept and slope of a line in log odds space and to see the projection of the line back into response space. Note the S-shaped ("sigmoidal") shape of the function in the response shape.
- -

(\#fig:logit-app)**Logistic regression web app**

+ +

(\#fig:logit-app)**Logistic regression web app**

### Estimating logistic regression models in R diff --git a/docs/08-generalized-linear-models_files/figure-html/binomial-var-plot-1.png b/docs/08-generalized-linear-models_files/figure-html/binomial-var-plot-1.png index 25cf2de..1f43fdb 100644 Binary files a/docs/08-generalized-linear-models_files/figure-html/binomial-var-plot-1.png and b/docs/08-generalized-linear-models_files/figure-html/binomial-var-plot-1.png differ diff --git a/docs/404.html b/docs/404.html index 8dda057..c59da91 100644 --- a/docs/404.html +++ b/docs/404.html @@ -7,7 +7,7 @@ Page not found | Learning Statistical Models Through Simulation in R - + @@ -19,15 +19,15 @@ - - + + @@ -210,7 +210,7 @@

Page not found<