library(tidyverse)
library(pwr)
library(psych)
library(car)

1

# a
f2model <- .33 / (1 - .33)
pwr.f2.test(u = 3, v = NULL, f2 = f2model, power = .8)
# v = 22.4, so 23 + 4 = 27 observations needed
# +4 because 3 df go with the tested parameters, and 1 is needed for the intercept

# b
f2X1 <- .12 / (1 - .33)
pwr.f2.test(u = 1, v = NULL, f2 = f2X1, power = .8)
# v = 43.8, so 44 + 1 + 1 = 46 observations needed
  1. 27 observations are needed.

  2. 46 observations are needed.

  3. 46 observations are needed. If 27 were available, the power for the partial slope of X1 would be less than .8.

2

# 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)]
  1. 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.

  2. \(\hat{endurance} = 25.9 - 0.26 \times age_c + 0.97 \times exercise_c + 0.05 \times age:exercise\)

  3. 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).

  4. The regression equations at 40, 50, and 60 (you might have used different values!) are below. (The mean of age is about 49, and the standard deviation is about 10. If you examined ages 30 and 70, these are unusual observations in this data set. If you went even further from the mean, these are even-more unusual observations in this data set. The simple slopes estimates at unusual values have wide confidence intervals, and thus are not especially useful estimates.)

\(\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\)

  1. The exercise-endurance relationship is positive, but more strongly so among older than among younger folks. The predicted level of endurance goes down across ages.
# e

m.not.centered <- lm(yendu ~ xage*zexer, d)
interactions::johnson_neyman(model = m.not.centered,
                                                         pred = zexer,
                                                         modx = xage)

  1. The exercise-endurance relationship is significant (and positive) for those over age 37 or so.