0

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.

Devon Oliver
  • 295
  • 1
  • 7
  • 20
  • your first two code blocks/examples look identical ... ?? I'm going to guess `increment ~ age*growth_year + (1|fish)` ... does that give you comparable answers? – Ben Bolker Mar 24 '18 at 01:40
  • can you explain what `_residual_ / subject=fish` actually does, statistically or mathematically? – Ben Bolker Mar 24 '18 at 01:40
  • I fixed the second code block and I believe it sets random r side intercepts by individual – Devon Oliver Mar 24 '18 at 02:10
  • The following link is the SAS help file explaination. I think R may only allow specification of g side random effects. https://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_glimmix_a0000001405.htm – Devon Oliver Mar 24 '18 at 04:50
  • I still don't understand what your first example does. – Ben Bolker Mar 24 '18 at 13:36
  • The first block is an r-side random intercept by fish with no ar(1) covariance structure and second model adds the ar(1) covariance structure. I'll edit the question for clarity and check out your suggestion in comment and answer. – Devon Oliver Mar 24 '18 at 13:49
  • I don't understand what an "R-side random intercept by fish" model means. Are the residuals assumed IID within fish (in which case this would be mathematically equivalent to a G-side intercept model on fish ...) ? – Ben Bolker Mar 24 '18 at 13:58
  • Yes and your right. I just noticed that. The SAS code is from some work a former colleague was doing on yellow bass. I will try to run both your examples this afternoon. – Devon Oliver Mar 24 '18 at 14:06

1 Answers1

2

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)
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453