[R-sig-ME] Specifying Crossed vs. Nested Factors with Lmer and bootstrapping downstream statistics

ledonret at email.unc.edu ledonret at email.unc.edu
Wed Sep 9 17:08:39 CEST 2009


I just wanted to correct something in my earlier post,

The function that I used was actually,
#The function
> fun<-function(data,i){
+ d<-data[i,]
+ M<-lmer(SVL~Treatment+(1|Family/Treatment/Box1),d)
+ Mv<-VarCorr(M)
+ varcomps<-c(unlist(lapply(Mv,diag))) #Variance of random factors
+ resid<-(attr(Mv,"sc")^2) #Residual Variance
+ VarTot<-sum(varcomps,resid) #Total variance
+ VarFamTrt<-Mv$`Treatment:Family`[1,1] #Variance for Family by Treatment
+ return((2*VarFamTrt)/VarTot)} #Heritability
#bootstrapping
> Fam.boot<-boot(data,statistic=fun,R=10)

Which still gives me the error message
In mer_finalize(ans) : singular convergence (7)

Sorry about the typo!

Dear List,

I have been using R for a couple of years now, but I am very new to the 
lme4 package. I am currently trying to use lmer to analyze a mixed 
model, and also trying to bootstrap some downstream statistics that 
utilize the variance components I am obtaining from this model. 
However, I'm not sure that I am specifying the model correctly, and 
while I have written a function that works with the boot package for 
iterations of up to about 30, it will not work for greater iterations. 
I was hoping you or others could shed some light on these issues!

*I am using lme4 version 0.99375-28 with Mac OS X version 10.5.7

My design is this: I created 9 Families, and I treated these families 
with two diets. Each family by diet combination was replicated 9 times 
(randomized and interspersed). In my model, I am treating Family as a 
random effect, and Diet as a fixed effect. I am mostly concerned with 
determining the variance of the Family by Diet interaction. From 
previous queries, I gathered that the correct specification would be 
this (disregarding replicate)

lmer(SVL ~ Treatment + (1|Family) + (1|Family:Treatment), dataset)

or equivalently

lmer(SVL ~ Treatment + (1|Family/Treatment), dataset)

where "SVL" is my trait. It's a little confusing to me, because in the 
second formula it appears that Treatment is nested in Family, instead 
of being completely crossed with family, but I tried both ways and they 
gave me the same answer, so I was satisfied. However, I'd also like to 
add replicate (Box1) as a nested factor. The way I'd intuitively write 
that,

lmer(SVL ~ Treatment + (1|Family/Treatment/Box1), dataset)

should mean that replicate is completely cross with Family, instead of 
being nested within. The way I tried to deal with this was to make sure 
each replicate had a unique identity... is that sufficient?

My second issue concerned bootstrapping and some errors that I receive 
when trying to use this with an R>30. The function that I am attempting 
to use is a function that I wrote to calculate heritability (I am 
trying to bootstrap my estimate of the heritability of the Diet by 
Treatment interaction).

#The function
> fun<-function(data,i){
+ d<-data[i,]
+ M<-lmer(SVL~Treatment+(1|Family/Box1/Family),d)
+ Mv<-VarCorr(M)
+ varcomps<-c(unlist(lapply(Mv,diag))) #Variance of random factors
+ resid<-(attr(Mv,"sc")^2) #Residual Variance
+ VarTot<-sum(varcomps,resid) #Total variance
+ VarFamTrt<-Mv$`Treatment:Family`[1,1] #Variance for Family by Treatment
+ return((2*VarFamTrt)/VarTot)} #Heritability
#bootstrapping
> Fam.boot<-boot(data,statistic=fun,R=10)
This will work up to about R=30, but beyond that, I get this error message,

Warning message:
In mer_finalize(ans) : singular convergence (7)

I realize this is probably a problem that isn't specific to lmer, but 
it is the first time that I have run into it, so I'm at a loss for what 
to do.

Thank you so much in advance, for any insight you can provide!

Best, Cristina Ledon-Rettig
UNC-Chapel Hill




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