library(tidyverse)
library(lmSupport)
library(pwr)
library(psych)
library(car)
# a
d <- read.csv("http://whlevine.hosted.uark.edu/psyc5143/exercise.csv")
d <- d %>%
mutate(age.c = xage - mean(xage, na.rm = T),
exer.c = zexer - mean(zexer, na.mr = T))
model.da <- lm(yendu ~ age.c*exer.c, d)
coef(model.da)
summary(model.da)
# d
d <- d %>%
mutate(age40 = xage - 40,
age50 = xage - 50,
age60 = xage - 60)
coef(lm(yendu ~ age40*exer.c, d))[c(1, 3)]
coef(lm(yendu ~ age50*exer.c, d))[c(1, 3)]
coef(lm(yendu ~ age60*exer.c, d))[c(1, 3)]
There is a significant Age \(\times\) Exercise interaction, t(241) = 3.5, p = 0.0006. For age, the simple slope is -0.26. For exercise, the simple slope is 0.97. The intercept is about 25.9. The interaction slope is approximately 0.05.
\(\hat{endurance} = 25.9 - 0.26 \times age_c + 0.97 \times exercise_c + 0.05 \times age:exercise\)
This question should have called these simple and not partial slopes!! There is (unsurprisingly) a negative relationship between age and endurance, \(b_{age}\) = -0.26, which in this case means that for every year aged, we would predict a decrease of 0.26 minutes of endurance at the mean level of exercise (i.e., ~10.7 years of exercise, or 0 years of centered exercise). There is (again, unsurprisingly), a positive relationship between exercise and endurance, \(b_{exercise}\) = 0.97, which in this case means that for every additional year of exercise, we would predict an increase of 0.97 minutes of endurance at the mean age (i.e., ~49.2 years old, or 0 years old for centered age).
The regression equations at 40, 50, and 60 (you might have used different values!) are below.
\(\hat{Y_{40}} = 28.29 + 0.54 \times exercise\)
\(\hat{Y_{50}} = 25.68 + 1.01 \times exercise\)
\(\hat{Y_{60}} = 23.06 + 1.48 \times exercise\)
# e
m.not.centered <- lm(yendu ~ xage*zexer, d)
interactions::johnson_neyman(model = m.not.centered,
pred = zexer,
modx = xage)
# g
age40 <- lm(yendu ~ age40*exer.c, d)
age50 <- lm(yendu ~ age50*exer.c, d)
age60 <- lm(yendu ~ age60*exer.c, d)
library(lmSupport)
library(pwr)
# the bracket notation and $Effects allow me to extract delta-R-squared and
# store it in a variable
dR2_exercise40 <- modelEffectSizes(age40)$Effects[3,4]
dR2_exercise50 <- modelEffectSizes(age50)$Effects[3,4]
dR2_exercise60 <- modelEffectSizes(age60)$Effects[3,4]
R2 <- summary(age40)$r.squared
f2_exercise40 <- dR2_exercise40 / (1 - R2)
f2_exercise50 <- dR2_exercise50 / (1 - R2)
f2_exercise60 <- dR2_exercise60 / (1 - R2)
v_40 <- pwr.f2.test(u = 1, v = NULL, f2 = f2_exercise40, power = .8)$v
v_50 <- pwr.f2.test(u = 1, v = NULL, f2 = f2_exercise50, power = .8)$v
v_60 <- pwr.f2.test(u = 1, v = NULL, f2 = f2_exercise60, power = .8)$v
n40 <- ceiling(v_40) + 4
n50 <- ceiling(v_50) + 4
n60 <- ceiling(v_60) + 4
For the simple slope of exercise among 40-year-olds, \(f^2\) = 0.04; based on this, the required sample size to achieve power = .8 is 201. For the simple slope of exercise among 50-year-olds, \(f^2\) = 0.222; based on this, the required sample size to achieve power = .8 is 40. For the simple slope of exercise among 60-year-olds, \(f^2\) = 0.203; based on this, the required sample size to achieve power = .8 is 43.
This is a “trick” question because these power analyses are for simple slopes, and it’s unlikely (though not impossible) that you’ll be interested in powering a particular simple slope to be significant. Instead, you’re more likely to be interested in powering the overall interaction, which has a constant \(f^2\) value rather than one that varies depending on the meaning of 0.
One other thing here that might have caught your eye: The (simple) slope of exercise gets larger as age increases, but the effect size for the simple slope of exercise at 60 years old is smaller than that at 50 years old; this is becuase of the larger SE at the older age, which makes for a wider confidence interval and a need to have more rather than fewer observations to achieve a desired level of power.