Devon  Oliver
Devon Oliver

Reputation: 345

R equivalent to random residual by subject in SAS

I can code this problem in SAS with residual as a random effect ( I believe this is a r-side random intercept by fish)

    proc glimmix data=one method=mmpl ;
    class fish;
    model increment =age growth_year age*growth_year;
    random residual / subject=fish ;
    run;

Here is the same analysis with AR(1) covariance structure.

   proc glimmix data=one method=mmpl ;
    class fish;
    model increment =age growth_year age*growth_year;
    random residual/ subject=fish type = ar(1) ;
    run;

Here is my attempt in R to reproduce the first model that doesn't work.

    model = lmer(increment ~ age + growth_year+ age*growth_year 
    + (resid()|fish), data = SR_data)

Please Help, Use of lmer or glmer(gamma instead of normal distribution) or lme or any other package that I am unaware of.

Upvotes: 0

Views: 933

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226732

The lme4 package doesn't allow R-side models, but nlme does. If you want correlation within fish without random effects of fish (i.e. R-side effects only, without any G-side effects), then I think you want to use gls: here's an example using the Orthodont data from the nlme package:

library("nlme")
gls(distance~age*Sex, correlation=corAR1(form=~1|Subject), data=Orthodont)

If you want to allow variation in the baseline value/intercept by group (both G- and R-side), then you'd use:

lme(distance~age*Sex, random = ~1|Subject,
     correlation=corAR1(form=~1|Subject), data=Orthodont)

If you want variation in the baseline but not correlated residuals within subject (G-side only):

lme(distance~age*Sex, random=~1|Subject, data=Orthodont)

or

library(lme4)
lmer(distance~age*Sex + (1|Subject), data=Orthodont)

Upvotes: 2

Related Questions