[R-sig-ME] problem with using R nlme function

Ben Bolker bbolker at gmail.com
Wed Jun 29 20:59:19 CEST 2011


On 06/29/2011 11:57 AM, Zhiwei Tang wrote:
> Dear R users,
> 
> I am trying to converting a piece of my SAS code into R code, and I have met
> some difficulties which I couldn't figure out. The SAS code looks like this:
> 
> proc mixed CL method=ml data = wholedata  covtest;
> class site year tissue species fish_id;
> model fishSe = waterSe  / outp=predict solution;
> random intercept / sub=site;
> repeated tissue/ sub=fish_id type=cs;
> run;
> 
> Basically,  I am trying to fit a random intercept linear mixed model to
> allow each *site *to have a different intercept and I also want to specify a
> variance-covariance structure (CS for example) within each *fish (fish_id) .
> *I do not know how can I fit this model with correct R code. I tried
> *lme* function
> included in the *nlme *package, with R code:
> 
> lme(fixed=y~x,random=~1|site,correlation = corCompSymm(form = ~1|fishid),
> na.action=na.omit, method="REML")
> 
> but R gave me error message like this:    Incompatible formulas for groups
> in "random" and "correlation"
> 
> I heard I can use the *nlme* function to have both the random and
> correlation statements together. I wonder how can I write the correct syntax
> to fit my model under *nlme *? I really have no clue about that.... I will
> be highly appreciated if anyone can give me any advice on this issue. Thank
> you in advance!

  I believe you're required to have the correlation structured within
the same units as the overall random effect, so

lme(fixed=y~x,random=~1|site/fishid,
  correlation = corCompSymm(form =~1|site/fishid),
   na.action=na.omit, method="REML")

  But: doesn't compound symmetry at the fishid level mean the
correlation statement would then be redundant?

  I don't quite understand the distinction between "random" and
"repeated" in the SAS code (sorry ...)

  Ben Bolker




More information about the R-sig-mixed-models mailing list