Nested mixed model

bugman

Super Moderator
#1
Hi folks,

I would like some feed back on an analyis I have been running in R. Its the first time I have run such a model in R and just wonder if its the correct choice.

My study involves bugs collected at three sites (6 replicates at each site) up and downstream of an impact.

I believe that the sites are considered a random effect and location (up or downstream) is a fixed effect, thus a mixed effect model. The sites, because not located in each location are therefore nested in location.

My R code is below.

The summary provides a responable output, but I dont think its nesting site with location.


Can any one offer some advice regarding the model? and still I struggle with the interpretation of the intercept in the output - shed some light some one?

ResLmeriff<-lme(OE50~Location,random=~1|Site/Location,data=riff)
summary(ResLmeriff)

#################################################
OUTPUT
#################################################


inear mixed-effects model fit by REML
Data: riff
AIC BIC logLik
-33.46531 -25.83350 21.73265

Random effects:
Formula: ~1 | Site
(Intercept)
StdDev: 0.08016658

Formula: ~1 | Location %in% Site
(Intercept) Residual
StdDev: 0.08016658 0.03006247

Fixed effects: OE50 ~ Location
Value Std.Error DF t-value p-value
(Intercept) 0.8205263 0.02690834 34 30.493388 0.000
Locationu 0.0177090 0.03915738 34 0.452251 0.654
Correlation:
(Intr)
Locationu -0.687

Standardized Within-Group Residuals:
Min Q1 Med Q3 Max
-0.60800837 -0.12725757 -0.08855936 0.15181604 0.39219145

Number of Observations: 36
Number of Groups:
Site Location %in% Site
36 36


Thansk for any help

Phil
 
#3
I know this is old but I thought I would correct it for users that come in here through Google search on R and nested anova with mixed effects.

Hi folks,

My R code is below.

The summary provides a responable output, but I dont think its nesting site with location.

Can any one offer some advice regarding the model? and still I struggle with the interpretation of the intercept in the output - shed some light some one?

ResLmeriff<-lme(OE50~Location,random=~1|Site/Location,data=riff)
summary(ResLmeriff)
You should write:
ResLmeriff<-lme(OE50~Location,random=~1|Location/Site,data=riff)
summary(ResLmeriff)

See it tells you below
Formula: ~1 | Location %in% Site
 

bugman

Super Moderator
#4
Can someone help me through this?

In this model I have a continuous response, y two fixed effects (l and ses (location and season)) both with two levels (u,d (up and down) and sp, au (spring, autumn) respectively) and one random factor site, which is nested in location.

So I fit the following model and got an error (NaNs produced).

Is this a problem with my data? Or is it an error in the model?

Can it be fixed?

Code:
> m1<-lme(y~l*ses,random=~1|l/s,data=lmm)
> summary(m1)
Linear mixed-effects model fit by REML
 Data: lmm 
       AIC      BIC    logLik
  649.2088 659.4689 -317.6044

Random effects:
 Formula: ~1 | l
        (Intercept)
StdDev:     2709.49

 Formula: ~1 | s %in% l
        (Intercept) Residual
StdDev:   0.4211858 4310.772

Fixed effects: y ~ l * ses 
                 Value Std.Error DF    t-value p-value
(Intercept)   981.0000  3066.934 28  0.3198634  0.7514
lu           2963.6667  4337.300  0  0.6832976     NaN
sessp        -666.3333  2032.117 28 -0.3279010  0.7454
lu:sessp    -1915.1111  2873.848 28 -0.6663927  0.5106
 Correlation: 
         (Intr) lu     sessp 
lu       -0.707              
sessp    -0.331  0.234       
lu:sessp  0.234 -0.331 -0.707

Standardized Within-Group Residuals:
        Min          Q1         Med          Q3         Max 
-0.91344818 -0.25969183 -0.15150676  0.09855158  4.77834001 

Number of Observations: 36
Number of Groups: 
       l s %in% l 
       2        6 
Warning message:
In pt(q, df, lower.tail, log.p) : NaNs produced
[/CODE]
 

bugman

Super Moderator
#5
Post script,

when I look at the output again, it is telling me that l (location) is a random effect in the model, but when I rearrange the order (i.e. s/l instead of l/s) it nests location in site, which isn't correct either. Any thoughts on how to rewrite this model so that I have the interation term for season and location with site nested in location - (I'm having a bit of trouble with this guys!)
 

bugman

Super Moderator
#6
Ok, so this has really been annoying me. This is more me thinking out loud, but I hope it may help others.

I have been able to fit this model using the lmer function in lme4. The problem with this function for the masses is that you don't get p-values with anova(model) as explained here. Anyway, recently a new package was released called "LMERConvienceFuntions" which provides back fitting p-values on fixed effects and produces a table with the pamer.fnc(model1) function.

Its a step in the right direction, but since I don't really get the math behind this I am unsure whether the sites are intrinsically being nested in the model or not. For this I emailed Douglas Bates directly and am still waiting for a response...