variable | description |
---|---|
perc_recall | Percentage Recall - the percentage of correctly recalled items |
group | Group - whether the individual was assigned to the roller-coaster (group = 0) or the meditation (group = 1) intervention condition |
age | Age - individual's age (in years) |
Sample Size and Power Analysis
Learning Objectives
At the end of this lab, you will:
- Understand how varying factors can influence power
- Be able to conduct power analyses using the
pwr
package
What You Need
- Be up to date with lectures
Required R Packages
Remember to load all packages within a code chunk at the start of your RMarkdown file using library()
. If you do not have a package and need to install, do so within the console using install.packages(" ")
. For further guidance on installing/updating packages, see Section C here.
For this lab, you will need to load the following package(s):
- tidyverse
- kableExtra
- pwr
Presenting Results
All results should be presented following APA guidelines. If you need a reminder on how to hide code, format tables/plots, etc., make sure to review the rmd bootcamp.
The example write-up sections included as part of the solutions are not perfect - they instead should give you a good example of what information you should include and how to structure this. Note that you must not copy any of the write-ups included below for future reports - if you do, you will be committing plagiarism, and this type of academic misconduct is taken very seriously by the University. You can find out more here.
Lab Data
You can download the data required for this lab here or read it in via this link https://uoepsy.github.io/data/recall_med_coast.csv
Study Overview
Research Question
Do age and intervention type influence recall?
Setup
- Create a new RMarkdown file
- Load the required package(s)
- Read in the recall_med_coast dataset into R, assigning it to an object named
recdata
Exercises
Study Overview & Data Management
First, provide a brief overview of the study design and data.
Next examine the dataset, and perform any necessary and appropriate data management steps.
Descriptive Statistics & Visualisations
Provide a table of descriptive statistics and visualise your data.
Remember to interpret these in the context of the study.
- For your table of descriptive statistics, both the
group_by()
andsummarise()
functions will come in handy here. - Recall that when visualising a continuous outcome across groups,
geom_boxplot()
may be most appropriate to use. - Make sure to comment on any observed differences among the sample means of the four treatment conditions.
Use a scatterplot to visualise the association between recall and age by group.
Is there any evidence of an interaction between age and group?
- It might be useful to specify the
color =
argument for your grouping variable - Consider using
geom_smooth()
to superimpose the best-fitting line describing the association of interest for each intervention group.
Sample Size & Power
Using a significance level (\(\alpha\)) of .05, what sample size (\(n\)) would you require to check whether any of the predictors (including their interaction) influenced recall scores with a 90% chance?
Because you do not know the effect size, assume Cohen’s guideline for linear regression and, to be on the safe side, consider the ‘small’ value.
In linear regression, the relevant function in R is:
pwr.f2.test(u = , v = , f2 = , sig.level = , power = )
Where:
-
u
= numerator degrees of freedom = number predictors in the model (\(k\)) -
v
= denominator degrees of freedom = \(v = n-k-1\) -
f2
= effect size. Cohen suggests effect size cut-off values of \(.02\) (small), \(.15\) (moderate), and \(.35\) (large) -
sig.level
= significance level -
power
= level of power
where one of the above the parameters - u
, v
, f2
,power
, or sig.level
- must be passed as NULL (or in other words not specified), as that parameter will be determined from the others.
Using the same \(\alpha\) and power, what would be the sample size if you assumed effect size to be ‘medium’?
In linear regression, the relevant function in R is:
pwr.f2.test(u = , v = , f2 = , sig.level = , power = )
Where:
-
u
= numerator degrees of freedom = number predictors in the model (\(k\)) -
v
= denominator degrees of freedom = \(v = n-k-1\) -
f2
= effect size. Cohen suggests effect size cut-off values of \(.02\) (small), \(.15\) (moderate), and \(.35\) (large) -
sig.level
= significance level -
power
= level of power
where one of the above the parameters - u
, v
, f2
,power
, or sig.level
- must be passed as NULL (or in other words not specified), as that parameter will be determined from the others.
Using the same \(\alpha\) and power, what would be the sample size if you assumed effect size to be ‘large’?
In linear regression, the relevant function in R is:
pwr.f2.test(u = , v = , f2 = , sig.level = , power = )
Where:
-
u
= numerator degrees of freedom = number predictors in the model (\(k\)) -
v
= denominator degrees of freedom = \(v = n-k-1\) -
f2
= effect size. Cohen suggests effect size cut-off values of \(.02\) (small), \(.15\) (moderate), and \(.35\) (large) -
sig.level
= significance level -
power
= level of power
where one of the above the parameters - u
, v
, f2
,power
, or sig.level
- must be passed as NULL (or in other words not specified), as that parameter will be determined from the others.
Fit the following model using lm()
, and assign it as an object with the name “recall_mdl1”.
\[ \text{Recall} = \beta_0 + \beta_1 \cdot Age + \epsilon \\ \]
How much variance in recall scores does the model explain?
Imagine you found the R-squared that you computed above (Q7) in a paper, and you are using that to base your next study.
A researcher believes that the inclusion of intervention group and its interaction with age should explain an extra 50% of the variation in recall scores.
Using a significance level of 5%, what sample size should you use for your next data collection in order to discover that effect with a power of 0.90?
Suppose that the aforementioned researcher made a mistake, and issues a corrected statement in which they state that the inclusion of intervention group and its interaction with age should explain an extra 5% of the variation in recall scores.
Using a significance level of 5%, what sample size should you use for your next data collection in order to discover that effect with a power of 0.90?
A colleague produces a visualisation of the joint relationship between sample size and effect size via a power curve (with coloured lines representing large, medium, and small effect sizes).
Based on this, what feedback/comments might you share with them regarding sample size for their prospective study, and its relation to effect size?
Compile Report
Knit your report to PDF, and check over your work. To do so, you should make sure:
- Only the output you want your reader to see is visible (e.g., do you want to hide your code?)
- Check that the tinytex package is installed
- Ensure that the ‘yaml’ (bit at the very top of your document) looks something like this:
---
title: "this is my report title"
author: "B1234506"
date: "07/09/2024"
output: bookdown::pdf_document2
---
If you are having issues knitting directly to PDF, try the following:
- Knit to HTML file
- Open your HTML in a web-browser (e.g. Chrome, Firefox)
- Print to PDF (Ctrl+P, then choose to save to PDF)
- Open file to check formatting
To not show the code of an R code chunk, and only show the output, write:
```{r, echo=FALSE}
# code goes here
```
To show the code of an R code chunk, but hide the output, write:
```{r, results='hide'}
# code goes here
```
To hide both code and output of an R code chunk, write:
```{r, include=FALSE}
# code goes here
```
You must make sure you have tinytex installed in R so that you can “Knit” your Rmd document to a PDF file:
install.packages("tinytex")
tinytex::install_tinytex()