Skip to content

Commit

Permalink
Merge branch 'main' of github.com:lbelzile/experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
lbelzile committed Oct 28, 2024
2 parents 3d51651 + bffe67d commit 68b0f6a
Show file tree
Hide file tree
Showing 93 changed files with 1,100 additions and 491 deletions.
5 changes: 3 additions & 2 deletions _freeze/content/06-content/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"hash": "3b86839d0acb503ff2e1608cae65dae5",
"hash": "3b3ae3a89ab4df194d13ded0e4be226d",
"result": {
"markdown": "---\ntitle: \"Repeated measures\"\n---\n\n\n## Content\n\n- Unbalanced designs\n- Analysis of within-subject designs\n- Repeated measures and sphericity\n\n## Learning objectives\n\nAt the end of the session, students should be capable of\n\n- listing the benefits of balanced designs\n- adequately modelling repeated measures\n- correctly interpreting tests of sphericity using software\n- explaining the benefits and disadvantages of repeated-measure designs\n\n## Readings\n\n- {{< fa book >}} [Chapter 6](https://lbelzile.github.io/math80667a/repeated.html) of the course notes\n- {{< fa book-open-reader >}} [Repeated measure example](/example/repeated.html)\n\n\n## Complementary readings\n\n- <i class=\"fas fa-book\"></i> [Chapter 5.2 ](https://opentext.wsu.edu/carriecuttler/chapter/experimental-design/) of @Price:2017\n- {{< fa book >}} Chapters 11--12 of @Maxwell.Delaney.Kelley:2017.\n- {{< fa book >}} Chapters 16--18 of @Keppel/Wickens:2004.\n\n## Videos\n\n\n<div class=\"ratio ratio-16x9\">\n<iframe src=\"https://www.youtube.com/embed/Rss0bSmONz0\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n</div>\n\n\n## Slides\n\n\n\n\n<p><a class=\"btn btn-primary\" target=\"_blank\" href=\"/slides/06-slides.html\"><i class=\"fa-solid fa-arrow-up-right-from-square\"></i> View all slides in new window</a> <a class=\"btn btn-primary\" target=\"_blank\" href=\"/slides/06-slides.pdf\" role=\"button\"><i class=\"fa-solid fa-file-pdf\"></i> Download PDF of all slides</a></p>\n\n::: {.cell}\n::: {.cell-output-display}\n```{=html}\n<div class=\"shareagain\" style=\"min-width:300px;margin:1em auto;\" data-exeternal=\"1\">\n<iframe src=\"/slides/06-slides.html\" width=\"1600\" height=\"900\" style=\"border:2px solid currentColor;\" loading=\"lazy\" allowfullscreen></iframe>\n<script>fitvids('.shareagain', {players: 'iframe'});</script>\n</div>\n```\n:::\n:::\n\n\n:::{.callout-tip}\n**Fun fact**: If you type <kbd>?</kbd> (or <kbd>shift</kbd> + <kbd>/</kbd>) while going through the slides, you can see a list of slide-specific commands.\n:::\n\n\n## Code\n\n\n- [R script](/content/MATH80667A-06-content.R)\n\n\n",
"engine": "knitr",
"markdown": "---\ntitle: \"Repeated measures\"\n---\n\n\n\n\n## Content\n\n- Unbalanced designs\n- Analysis of within-subject designs\n- Repeated measures and sphericity\n\n## Learning objectives\n\nAt the end of the session, students should be capable of\n\n- listing the benefits of balanced designs\n- adequately modelling repeated measures\n- correctly interpreting tests of sphericity using software\n- explaining the benefits and disadvantages of repeated-measure designs\n\n## Readings\n\n- {{< fa book >}} [Chapter 6](https://lbelzile.github.io/math80667a/repeated.html) of the course notes\n- {{< fa book-open-reader >}} [Repeated measure example](/example/repeated.html)\n\n\n## Complementary readings\n\n- <i class=\"fas fa-book\"></i> [Chapter 5.2 ](https://opentext.wsu.edu/carriecuttler/chapter/experimental-design/) of @Price:2017\n- {{< fa book >}} Chapters 11--12 of @Maxwell.Delaney.Kelley:2017.\n- {{< fa book >}} Chapters 16--18 of @Keppel/Wickens:2004.\n\n## Videos\n\nPlease watch this video before class.\n\n<div class=\"ratio ratio-16x9\">\n<iframe src=\"https://www.youtube.com/embed/Rss0bSmONz0\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n</div>\n\n\n## Slides\n\n\n\n\n\n\n<p><a class=\"btn btn-primary\" target=\"_blank\" href=\"/slides/06-slides.html\"><i class=\"fa-solid fa-arrow-up-right-from-square\"></i> View all slides in new window</a> <a class=\"btn btn-primary\" target=\"_blank\" href=\"/slides/06-slides.pdf\" role=\"button\"><i class=\"fa-solid fa-file-pdf\"></i> Download PDF of all slides</a></p>\n\n::: {.cell}\n::: {.cell-output-display}\n\n```{=html}\n<div class=\"shareagain\" style=\"min-width:300px;margin:1em auto;\" data-exeternal=\"1\">\n<iframe src=\"/slides/06-slides.html\" width=\"1600\" height=\"900\" style=\"border:2px solid currentColor;\" loading=\"lazy\" allowfullscreen></iframe>\n<script>fitvids('.shareagain', {players: 'iframe'});</script>\n</div>\n```\n\n:::\n:::\n\n\n\n\n:::{.callout-tip}\n**Fun fact**: If you type <kbd>?</kbd> (or <kbd>shift</kbd> + <kbd>/</kbd>) while going through the slides, you can see a list of slide-specific commands.\n:::\n\n\n## Code\n\n\n- [R script](/content/MATH80667A-06-content.R)\n- [SPSS script](/content/MATH80667A-06-content.sps)\n\n\n",
"supporting": [
"06-content_files"
],
Expand Down
8 changes: 5 additions & 3 deletions _freeze/content/08-content/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"hash": "3f2abc599f5d7c8f95d25bb2959e3314",
"hash": "e61efb5276662eb88d0c65e010cdbab7",
"result": {
"engine": "knitr",
"markdown": "---\ntitle: \"Analysis of covariance and moderation\"\n---\n\n\n\n\n## Content\n\n- Analysis of covariance and linear regression models\n- Moderation analysis\n\n## Learning objectives\n\nAt the end of the session, students should be capable of\n\n- explain the benefits ANCOVA over completely randomized designs\n- using control covariates\n- testing equality of slopes\n- testing for moderating variables (interactions)\n\n## Readings\n\n- {{< fa book >}} [Chapter 9](https://lbelzile.github.io/math80667a/ancova.html) of the course notes\n\n\n## Complementary readings\n\n\n\n- {{< fa book >}} Chapter 6 of @Maxwell.Delaney.Kelley:2017.\n- <i class=\"fas fa-book\"></i> Chapter 14--15 of @Keppel/Wickens:2004\n\n\n## Slides\n\n\n\n\n\n\n<p><a class=\"btn btn-primary\" target=\"_blank\" href=\"/slides/08-slides.html\"><i class=\"fa-solid fa-arrow-up-right-from-square\"></i> View all slides in new window</a> <a class=\"btn btn-primary\" target=\"_blank\" href=\"/slides/08-slides.pdf\" role=\"button\"><i class=\"fa-solid fa-file-pdf\"></i> Download PDF of all slides</a></p>\n\n::: {.cell}\n::: {.cell-output-display}\n\n```{=html}\n<div class=\"shareagain\" style=\"min-width:300px;margin:1em auto;\" data-exeternal=\"1\">\n<iframe src=\"/slides/08-slides.html\" width=\"1600\" height=\"900\" style=\"border:2px solid currentColor;\" loading=\"lazy\" allowfullscreen></iframe>\n<script>fitvids('.shareagain', {players: 'iframe'});</script>\n</div>\n```\n\n:::\n:::\n\n\n\n\n## Videos\n\n\n<div class=\"ratio ratio-16x9\">\n<iframe src=\"https://www.youtube.com/embed/gTLp0pplRXk\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n</div>\n\n## Code\n\n- [R script](/content/MATH80667A-08-content.R)\n\n\n:::{.callout-tip}\n**Fun fact**: If you type <kbd>?</kbd> (or <kbd>shift</kbd> + <kbd>/</kbd>) while going through the slides, you can see a list of slide-specific commands.\n:::\n",
"supporting": [],
"markdown": "---\ntitle: \"Analysis of covariance and moderation\"\n---\n\n\n\n\n## Content\n\n- Analysis of covariance and linear regression models\n- Moderation analysis\n\n## Learning objectives\n\nAt the end of the session, students should be capable of\n\n- explain the benefits ANCOVA over completely randomized designs\n- using control covariates\n- testing equality of slopes\n- testing for moderating variables (interactions)\n\n## Readings\n\n- {{< fa book >}} [Chapter 9](https://lbelzile.github.io/math80667a/ancova.html) of the course notes\n\n\n## Complementary readings\n\n\n\n- {{< fa book >}} Chapter 6 of @Maxwell.Delaney.Kelley:2017.\n- <i class=\"fas fa-book\"></i> Chapter 14--15 of @Keppel/Wickens:2004\n\n\n## Slides\n\n\n\n\n\n\n<p><a class=\"btn btn-primary\" target=\"_blank\" href=\"/slides/08-slides.html\"><i class=\"fa-solid fa-arrow-up-right-from-square\"></i> View all slides in new window</a> <a class=\"btn btn-primary\" target=\"_blank\" href=\"/slides/08-slides.pdf\" role=\"button\"><i class=\"fa-solid fa-file-pdf\"></i> Download PDF of all slides</a></p>\n\n::: {.cell}\n::: {.cell-output-display}\n\n```{=html}\n<div class=\"shareagain\" style=\"min-width:300px;margin:1em auto;\" data-exeternal=\"1\">\n<iframe src=\"/slides/08-slides.html\" width=\"1600\" height=\"900\" style=\"border:2px solid currentColor;\" loading=\"lazy\" allowfullscreen></iframe>\n<script>fitvids('.shareagain', {players: 'iframe'});</script>\n</div>\n```\n\n:::\n:::\n\n\n\n\n## Videos\n\n\n<div class=\"ratio ratio-16x9\">\n<iframe src=\"https://www.youtube.com/embed/gTLp0pplRXk\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n</div>\n\n## Code\n\n- [R script](/content/MATH80667A-08-content.R)\n- [SPSS script](/content/MATH80667A-08-content.sps)\n\n\n:::{.callout-tip}\n**Fun fact**: If you type <kbd>?</kbd> (or <kbd>shift</kbd> + <kbd>/</kbd>) while going through the slides, you can see a list of slide-specific commands.\n:::\n",
"supporting": [
"08-content_files"
],
"filters": [
"rmarkdown/pagebreak.lua"
],
Expand Down
4 changes: 2 additions & 2 deletions _freeze/evaluations/05-problem-set/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"hash": "e562a2138627579045f9095247af6590",
"hash": "40e9db2e90e4cf33039f3f35ca8f77ad",
"result": {
"engine": "knitr",
"markdown": "---\ntitle: \"Problem set 5\"\n---\n\n\n\nComplete this task individually\n\n**Submission information**: please submit on ZoneCours\n\n- a PDF report\n- your code\n\n## Task 1\n\nWe consider data from Experiment 2 of @Jordan:2022, who measured the confidence of participants on their ability to land successfully a plane if the pilot was incapacitated, after they were exposed to a trivially uninformative 3 minute video of a pilot landing a plane, but filmed in such a way that it was utterly useless. The authors pre-registered a comparison between experimental conditions `video` vs `no video`, and found that people watching the video answered higher for the question \"How confident are you that you would be able to land the plane without dying\", but there was no discernible effect for \"How confident are you that you would be able to successfully land the plane as well as a pilot could\", contrary to expectations. They found that the order in which the questions were asked (`order`, either pilot first, or dying first) changed the response.\n\nThe database in package `hecedsm` in **R** is labelled `JZBJG22_E2`. You can also download the [SPSS database via this link](/files/data/SPSS/JZBJG22_E2.sav).\n\n\n1. A dataset is said to be *balanced* if there are the same number of people in each experimental condition. Are the data balanced over `condition` and `order`? Justify your answer.\n2. Plot the response variables using a suitable graph (e.g., half-violin or density plot, see below), for each of the four conditions. Comment on the distribution of the scores along the scale. See @sec-plots for help.\n3. Using Levene's test, check whether the variance in each subgroup is the same.\n4. Perform the two-way analysis of variance for both `conf_dying` and `conf_pilot` and report the null and alternative hypotheses, the test statistic, the $P$-value and the conclusion of the test. Use Welch's ANOVA, i.e., an analysis of variance model with different variance for each subgroup if you rejected the null of homogeneity of variance in Question 3: see @sec-welch.\n5. For each response variable `conf_dying` and `conf_pilot`, perform follow-up tests. Compute simple or marginal effects (depending on whether the interaction is significant or not), along with 95% confidence intervals for the difference in score for `video` conditions. \n\n## Indications and helper code\n\nThere is no **R** script this week, but below are some instructions for fitting the different models.\n\n### Graphics {#sec-plots}\n\nTo create a pretty plot in **R**, try the following:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# install.packages(c(\"ggplot2\",\"ggdist\"))\n# remotes::install_github(\"lbelzile/hecedsm\")\ndata(JZBJG22_E2, package = \"hecedsm\")\nlibrary(ggplot2)\nlibrary(ggdist)\n\nggplot(data = JZBJG22_E2, \n mapping = aes(x = condition, group = order, y = conf_dying)) + \n ggdist::stat_halfeye(adjust = .5, width = 1, \n .width = c(0.5, 0.95)) + # 50% (box) and 95% confidence intervals\n ggdist::stat_dots(side = \"left\", dotsize = .4, justification = 1.05, binwidth = .1) +\n facet_grid(~order) + \n labs(y = \"\", subtitle = \"confidence in landing without dying\") +\n theme_classic()\n```\n\n::: {.cell-output-display}\n![](05-problem-set_files/figure-html/unnamed-chunk-1-1.png){width=672}\n:::\n:::\n\n\n\nYou must repeat this for the other response variable.\n\nIn SPSS, you need to specify manually with `GGRAPH` the format. This [post](https://andrewpwheeler.com/2012/05/20/bean-plots-in-spss/) shows an example of such plots.\n\n\n\n### Welch ANOVA {#sec-welch}\n\n\nIf the variance are unequal, we want to fit a model to observations in subgroup $(a_j, b_k)$ for $j=1, \\ldots, n_a$ and $k=1, \\ldots, n_b$, specifying that in the subgroup the average is $\\mu_{jk}$ and the variance $\\sigma^2_{jk}$. The resulting $F$ test from comparing overall means is typically named Welch after @Welch:1947.\n\n\nIn **R**, the Welch ANOVA can be obtained via `oneway.test`, but there is no possibility of follow-up for marginal means and contrasts. Rather, use the function `gls` in package `nlme` as follows.\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmodel <- nlme::gls(\n model = conf_dying ~ condition*order,\n data = JZBJG22_E2,\n weights = nlme::varIdent(form = ~ 1 | condition*order))\n# Use condition*order to get a different variance for each subgroup\n\n# ANOVA table for testing the interaction - use type 2\ncar::Anova(model, type = 2)\n```\n:::\n\n\n\nTo obtain the analysis of variance table in **R** to an object `model` representing an ANOVA with unbalanced data, use the `car::Anova` function. Use `type=2` as argument (the default). You can pass `model` to `emmeans` as before to compute main/simple effects.\n\nIn SPSS, you must first transform the $2 \\times 2$ into a one-way ANOVA with a categorical variable having $4$ levels. Then, use `oneway` and code directly the contrasts for the interaction, and either the simple effects of `condition` for each level of `order`, and the main effect of `condition`, depending on which is most suitable.\n",
"markdown": "---\ntitle: \"Problem set 5\"\n---\n\n\n\n\nComplete this task individually\n\n**Submission information**: please submit on ZoneCours\n\n- a PDF report\n- your code\n\n## Task 1\n\nWe consider data from Experiment 2 of @Jordan:2022, who measured the confidence of participants on their ability to land successfully a plane if the pilot was incapacitated, after they were exposed to a trivially uninformative 3 minute video of a pilot landing a plane, but filmed in such a way that it was utterly useless. The authors pre-registered a comparison between experimental conditions `video` vs `no video`, and found that people watching the video answered higher for the question \"How confident are you that you would be able to land the plane without dying\", but there was no discernible effect for \"How confident are you that you would be able to successfully land the plane as well as a pilot could\", contrary to expectations. They found that the order in which the questions were asked (`order`, either pilot first, or dying first) changed the response.\n\nThe database in package `hecedsm` in **R** is labelled `JZBJG22_E2`. You can also download the [SPSS database via this link](/files/data/SPSS/JZBJG22_E2.sav).\n\n\n1. A dataset is said to be *balanced* if there are the same number of people in each experimental condition. Are the data balanced over `condition` and `order`? Justify your answer.\n2. Look at Figure @fig-repartition and comment on the distribution of the scores along the scale.\n<!-- 3. Using Levene's test, check whether the variance in each subgroup is the same. -->\n3. Perform the two-way analysis of variance for both `conf_dying` and `conf_pilot` and report the null and alternative hypotheses, the test statistic, the $P$-value and the conclusion of the test. \n4. For each response variable `conf_dying` and `conf_pilot`, perform follow-up tests. Compute simple or main effects (depending on whether the interaction is significant or not), along with 95% confidence intervals for the difference in score for `video` conditions. \n\n## Indications and helper code\n\nThere is no **R** script this week, but below are some instructions for fitting the different models.\n\n### Graphics {#sec-plots}\n\nTo create a pretty plot in **R**, try the following:\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# install.packages(c(\"ggplot2\",\"ggdist\"))\n# remotes::install_github(\"lbelzile/hecedsm\")\ndata(JZBJG22_E2, package = \"hecedsm\")\nlibrary(ggplot2)\nlibrary(ggdist)\n\nggplot(data = JZBJG22_E2, \n mapping = aes(x = condition, group = order, y = conf_dying)) + \n ggdist::stat_halfeye(adjust = .5, width = 1, \n .width = c(0.5, 0.95)) + # 50% (box) and 95% confidence intervals\n ggdist::stat_dots(side = \"left\", dotsize = .4, justification = 1.05, binwidth = .1) +\n facet_grid(~order) + \n labs(y = \"\", subtitle = \"confidence in landing without dying\") +\n theme_classic()\n```\n\n::: {.cell-output-display}\n![Half-violin (density) plots, with box plots and 95% intervals, and jittered scatterplot for confidence in landing without dying, as a function of order and condition.](05-problem-set_files/figure-html/fig-repartition-1.png){#fig-repartition width=672}\n:::\n:::\n\n\n\n\nYou must repeat this for the other response variable.\n\nIn SPSS, you need to specify manually with `GGRAPH` the format. This [post](https://andrewpwheeler.com/2012/05/20/bean-plots-in-spss/) shows an example of such plots.\n\n\n\n### Welch ANOVA {#sec-welch}\n\nUsing Levene's test, we can check whether the variance in each subgroup is the same. In this example, we find that there are significant differences in variance per subgroup, but the effect on $p$-values is negligeable, so we can safely ignore it here.\n\nIf the variance are unequal, we want to fit a model to observations in subgroup $(a_j, b_k)$ for $j=1, \\ldots, n_a$ and $k=1, \\ldots, n_b$, specifying that in the subgroup the average is $\\mu_{jk}$ and the variance $\\sigma^2_{jk}$. The resulting $F$ test from comparing overall means is typically named Welch after @Welch:1947.\n\n\nIn **R**, the Welch ANOVA can be obtained via `oneway.test`, but there is no possibility of follow-up for marginal means and contrasts. Rather, use the function `gls` in package `nlme` as follows.\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmodel <- nlme::gls(\n model = conf_dying ~ condition*order,\n data = JZBJG22_E2,\n weights = nlme::varIdent(form = ~ 1 | condition*order))\n# Use condition*order to get a different variance for each subgroup\n\n# ANOVA table for testing the interaction - use type 2\ncar::Anova(model, type = 2)\n```\n:::\n\n\n\n\nTo obtain the analysis of variance table in **R** to an object `model` representing an ANOVA with unbalanced data, use the `car::Anova` function. Use `type=2` as argument (the default). You can pass `model` to `emmeans` as before to compute main/simple effects.\n\nIn SPSS, you must first transform the $2 \\times 2$ into a one-way ANOVA with a categorical variable having $4$ levels. Then, use `oneway` and code directly the contrasts for the interaction, and either the simple effects of `condition` for each level of `order`, and the main effect of `condition`, depending on which is most suitable.\n",
"supporting": [
"05-problem-set_files"
],
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 68b0f6a

Please sign in to comment.