Examine the dataset, and perform any necessary and appropriate data management steps.
Provide a table of descriptive statistics and visualise your data.
Remember to interpret your plot in the context of the study.
- For your table of descriptive statistics, both the
group_by()
and summarise()
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.
Let’s first produce a descriptive statistics table:
Table 1: Descriptive Statistics
group |
n |
Avg_recall |
rollercoaster |
53 |
50.11 |
meditation |
47 |
59.46 |
We can explore the association between our variables as follows:
recall_plt1 <- ggplot(data = recdata, aes(x = group, y = perc_recall, fill = group)) +
geom_boxplot() +
labs(x = "Intervention Group", y = "Recall (%)", title = "Association between Age, Intervention, and Recall")
recall_plt1
From Table 1 and Figure 1, we can see:
- there were more participants in the rollercoaster condition than meditation
- participants in the meditation condition had higher recall scores than those in the rollercoaster condition
- there was less variability in scores in the meditation condition in comparison to the rollercoaster condition
Using a significance level (\(\alpha\)) of .05, what sample size (\(n\)) would you require to check whether any of the predictors (and 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:
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
k <- 3
f2 <- .02
pwr.f2.test(u = k, f2 = f2, sig.level = 0.05, power = 0.9)
Multiple regression power calculation
u = 3
v = 708.495
f2 = 0.02
sig.level = 0.05
power = 0.9
The required sample size is \(n = \text v + k + 1 = 709 + 3 + 1 = 713\).
Using the same \(\alpha\) (.05) 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:
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
k <- 3
f2 <- .15
pwr.f2.test(u = k, f2 = f2, sig.level = 0.05, power = 0.9)
Multiple regression power calculation
u = 3
v = 94.48157
f2 = 0.15
sig.level = 0.05
power = 0.9
The required sample size is \(n = \text v + k + 1 = 95 + 3 + 1 = 99\).
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:
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
k <- 3
f2 <- .35
pwr.f2.test(u = k, f2 = f2, sig.level = 0.05, power = 0.9)
Multiple regression power calculation
u = 3
v = 40.61744
f2 = 0.35
sig.level = 0.05
power = 0.9
The required sample size is \(n = \text v + k + 1 = 41 + 3 + 1 = 45\).
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?
recall_mdl1 <- lm(perc_recall ~ age, data = recdata)
summary(recall_mdl1)
Call:
lm(formula = perc_recall ~ age, data = recdata)
Residuals:
Min 1Q Median 3Q Max
-10.0850 -4.7474 0.7331 4.6758 10.1733
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 62.16336 1.81984 34.159 < 2e-16 ***
age -0.16206 0.03672 -4.414 2.61e-05 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 5.494 on 98 degrees of freedom
Multiple R-squared: 0.1658, Adjusted R-squared: 0.1573
F-statistic: 19.48 on 1 and 98 DF, p-value: 2.614e-05
We can see both the R-squared or Adjusted R-squared from the model summary()
output. We can use either since we only have a single predictor. To be conservative, we might want to use the adjusted R-squared (0.16).
The model, with Age as a single predictor, explained approximately 16% of the variance in recall scores.
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.
recall_plt2 <- ggplot(data = recdata, aes(x = age, y = perc_recall, color = group)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(x = "Age (in years)", y = "Recall (%)", title = "Scatterplot displaying the association between age, intervention group, and recall")
recall_plt2
The slope appears to be stepper in the roller coaster intervention group than the meditation group - this suggests that there could be an interaction.
Imagine you found the R-squared that you computed above (Q6) 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.9?
# restricted model m - number of predictors & R-squared
k <- 1
R2m <- 0.16
# full model M - number of predictors & R-squared
K <- 3
R2M <- 0.16 + 0.5
# effect size - calculate f2
f2 <- (R2M - R2m) / (1 - R2M)
#run test
pwr.f2.test(u = K - k, f2 = f2, sig.level = 0.05, power = 0.9)
Multiple regression power calculation
u = 2
v = 9.211914
f2 = 1.470588
sig.level = 0.05
power = 0.9
The sample size should be \(n = \text v + K + 1 = 10 + 3 + 1 = 14\).
With such a big effect size, don’t be surprised it’s so small. When the effect size is much smaller, that will be harder to detect and you will require a bigger sample size.
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.9?
# restricted model m - number of predictors & R-squared
k <- 1
R2m <- 0.16
# full model M - number of predictors & R-squared
K <- 3
R2M <- 0.16 + 0.05
# effect size - calculate f2
f2 <- (R2M - R2m) / (1 - R2M)
# run test
pwr.f2.test(u = K - k, f2 = f2, sig.level = 0.05, power = 0.9)
Multiple regression power calculation
u = 2
v = 199.9608
f2 = 0.06329114
sig.level = 0.05
power = 0.9
The sample size should be \(n = \text v + K + 1 = 200 + 3 + 1 = 204\).
With such a small effect size, we need a bigger sample size for us to detect it with high confidence.
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?
From Figure 3, to detect a large effect size (red line), they should aim to recruit ~50 participants, for a medium effect size ~100 (blue line). It is impossible to judge how many participants would be required to detect a small effect size (green line) - we would suggest that they conduct their own power calculation as it is too difficult to judge based on the figure alone.
Generally, if they want to be able to detect a medium-large effect with 90% power using \(\alpha = .05\), it appears that there is little gain in recruiting a sample size > ~110. However, if they want to be able to detect a small effect with 90% power using \(\alpha = .05\), they are likely going to require a very large sample size.
To summarise the association between effect size and sample size, it appears that the smaller the effect you are trying to detect, the larger the sample size you will require.