6
$\begingroup$

I have data on 70,000 students, nested in 120 schools. I'm starting with fixed effects for the schools, but at some point I might start letting intercepts and slopes vary.

Some key predictors (e.g. gpa, test scores) have non-linear relationships with some outcomes. I definitely want to interact these predictors with categorical variables, and maybe with continuous ones as well. Natural cubic splines might be the right approach, but I haven't seen any examples with interactions or nested data, so I could use some pointers. These non-linear relationships aren't the sole focus of my research, so I don't want to focus on them to the neglect of other aspects of the model.

I'd appreciate suggestions of R packages, examples of related work, and general advice on how to approach this. Thanks!

$\endgroup$

1 Answer 1

7
$\begingroup$

You could try generalized additive mixed models, handily implemented in the gamm4 package. The way I've used them, you can do something like:

fit1 = gamm4(
    formula = V1 ~ V2 + s(V3)
    , random = ~ (1|V4)
)
fit2 = gamm4(
    formula = V1 ~ V2 + s(V3,by=V2)
    , random = ~ (1|V4)
)

fit1 seeks to predict V1 using V4 as a random effect and V2 and V3 as fixed effects, but where V3 is spline-smoothed. fit2 seeks the same, except with the addition of permitting the smooth of V3 to vary within levels of V2, thus implementing an interaction. Comparison of fit1 to fit2 evaluates the necessity of permitting the interaction.

$\endgroup$
1
  • 1
    $\begingroup$ Package recommendations: amer — Additive mixed models with lme4, gamm4 — Generalized additive mixed models using mgcv and lme4, mgcv (gamm function, via glmmPQL in MASS package), from [here](glmm.wikidot.com/faq) $\endgroup$ Commented Mar 22, 2011 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.