[R] problems with contrast matrix

Greg Snow Greg.Snow at imail.org
Tue Jul 14 22:15:08 CEST 2009


Your contrasts are not linearly independent and therefore there are an infinite number of possible correct answers, this tends to confuse computers (take 1/3 times the 3rd col, plus 2/3 times the 4th col, plus 3/3 times the 5th col and compare that to the 1st col).  You need to replace one of the contrasts with something else that makes them all linearly independent/full rank.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of doris gomez
> Sent: Friday, July 10, 2009 7:23 AM
> To: r-help at r-project.org
> Subject: [R] problems with contrast matrix
> 
> Dear lme and lmer -ers,
> I have some problems using "home-made" contrast matrix in lme and lmer.
> 
> I
> did an experiment to investigate the relationship between the response
> of an animal and some factors, namely the light wavelength (WA), the
> light intensity to which this animal was exposed and the sex of the
> animal
> tested.
> 
> - The response can be a variable LA (normal
> distribution) or another variable PE (normal distribution). Each
> analysed separately.
> - WA has 6 different levels: 400, 430, 470, 540, 570, 620 nm.
> - the light intensity has 4 different levels: 1, 2, 7, 50.
> - the same animal was used in several tests.
> I
> suspect the response varies quadratically with WA (intermediate
> wavelengths more efficient to evoke a response than extreme
> wavelengths) but I would like to know if 470 is different from 540 nm,
> if 430 is different from 570 nm...
> 
> I analyse the response with WA as an ordered factor, either with lmer
> (for PE) or with lme (for LA).
> All models tested converge but the by-default contrast matrix is really
> hard
> to interpret because all the contrasts always involve all the
> wavelengths.
> 
> Here is an example of the syntax for lmer and lme, for the complete
> model:
> model1<-
> lmer(PE~Sex+LightIntensity+ordered(WA)+(1|Animal),data=datamic,na.actio
> n=na.omit,family="poisson",REML=FALSE)
> model2<-
> lme(LA~Sex+LightIntensity+ordered(WA),random=~1|Animal,data=datamic,na.
> action=na.omit,method="ML")
> 
> 
> So I built a specific contrast matrix:
> 
> cmat.r<-matrix(c(-3/6,-2/6,-1/6,+1/6,+2/6,+3/6, # linear effect
>                         -3/6,+1/6,+2/6,+2/6,+1/6,-3/6, # main quadratic
> effect
>                         0,0,-1/2,+1/2,0,0, # mid wavelengths
>                         0,-1/2,0,0,+1/2,0, #intermediate wavelengths
>                         -1/2,0,0,0,0,+1/2),6,5) # extreme wavelengths
> colnames(cmat.r) <- c(".L",".Q",".mid",".inter",".extr")
> contrasts(ordered(datamic$WA)<- cmat.r
> 
> When I run the lme models, for all models involving WA, I get an error
> message (approximate English translation):
> Error in MEEM(object, conLin, control$niterEM) :
> Singularity encountered in inverse resolution in level 0, block 1
> 
> When I run the lmer models, for all models involving WA, I get an error
> message (approximate English translation):
> Warning message:
> In mer_finalize(ans) : gr cannot be computed at initial par (65)
> 
> 
> What is/are the problems and the solutions?
> - Is the contrast matrix of a rank inferior to what it should be?
> - Are there some other code lines I should have put to facilitate
> convergence?
> 
> Thank you for your help.
> Doris Gomez
> 
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list