[R-sig-ME] Contrast interaction effects in lmer object for reciprocal transplant experiment
Reinhold Kliegl
reinhold.kliegl at gmail.com
Tue Jun 22 23:56:36 CEST 2010
#You could specify a main effect of environment and two nested
contrasts of origin
# within levels of environment for a single factor with four levels,
constructed with paste()
exp=data.frame(pond=pond, env=env, origin=origin, iv = paste(env,
origin, sep="_"), survival=survival)
# nested contrasts
cmat <- matrix(c( -1/2, -1/2, +1/2, +1/2, # Main effect of env
-1/2, +1/2, 0, 0,
# Nested effect of origin | env==r
0, 0, -1/2, +1/2), 4, 3, #
Nested effect of origin | env==w
dimnames=list(c("r_r", "r_w", "w_r", "w_w"),
c(".Ew-Er", ".w-r|Er", ".w-r|Ew")))
(contrasts(exp$iv) <- cmat)
(g<-lmer(survival ~ iv + (1|pond), data = exp))
Reinhold Kliegl
On Tue, Jun 22, 2010 at 11:11 PM, Steven Brady <steven.brady at yale.edu> wrote:
> Dear All:
>
> I am using lmer() to analyze results from a reciprocal transplant
> experiment where the response variable is modeled as a function of two
> fixed effects and their interaction.
>
> Example data follow:
>
> #library(lme4)
> #library(gmodels)
>
> env=c("r","r","w","w","r","r","w","w","r","r",
> "w","w","r","r","w","w")
> #type of environment to where populations
> #were transplanted (fixed effect)
>
> origin=c("r","r","r","r","r","r","r",
> "r","w","w","w","w","w","w","w","w")
> #type of environment from where populations
> #originated (fixed effect)
>
> survival=c(rnorm(16,0.75, sd = 0.1))
> #percent survival (response variable)
>
> population=c("a","a","a","a","b","b","b","b",
> "c","c","c","c","d","d","d","d")
> #local population (random effect)
>
> exp=data.frame(pond=pond, env=env,
> origin=origin,survival=survival)
> #make data frame
>
> g<-lmer(survival~origin*env + (1|population),
> data = exp)
> # mixed model
>
> pvals.fnc(g)
> #evaluate fixed effects
>
>
> My question is this:
>
> How do I perform contrasts on the interaction of the fixed effects
> using, say estimable() in the library {gmodels}? I have seen how to
> do this for levels within a factor, however, I am unsure how to apply
> these to levels among factors (i.e. the interaction terms).
>
> Biologically speaking, I am interested in evaluating the difference in
> survival between the two origin types in each of two types of
> environments. In other words:
>
> 1. does origin r differ from origin w within env w? and,
> 2. does origin r differ from origin w within env r?
>
> Part of my misunderstanding concerns the reporting of the fixed
> effects of the model, which are named as the fixed term concatenated
> with a level (e.g. originw). Does the way lmer names the fixed
> effects influence the contrast matrix I should specify?
>
> Many thanks in advance,
>
> Steve Brady
>
> __________________________________________
> Steven P. Brady, Ph.D. Candidate
> School of Forestry & Environmental Studies
> Yale University
> 370 Prospect Street
> New Haven, CT 06511
>
> Email: steven.brady at yale.edu
> Phone: 203-432-5321 Fax: 203-432-3929
> Web: http://www.cbc.yale.edu/people/skelly/steveb.html
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>
More information about the R-sig-mixed-models
mailing list