[R-sig-eco] Can I weight LS means estimates by elevation in lme4/lmerTest packages?

Chris Howden chris at trickysolutions.com.au
Mon Dec 1 07:44:09 CET 2014


Hi Mathew,

Are you sure you want to 'weight' by elevation? That would imply higher elevations have a greater weight on the analysis?

I think you actually want to know if elevation changes the effect of your other predictors? In which case you need to include it as an interaction with those other predictors. That said you may need to convert elevation into a categorical predictor first. This would basically give you different predictor parameters for different elevations, you could then look to see if they differ. 

Chris Howden
Founding Partner
Tricky Solutions
Tricky Solutions 4 Tricky Problems
Evidence Based Strategic Development, IP Commercialisation and Innovation, Data Analysis, Modelling and Training

(mobile) 0410 689 945
(fax / office)
chris at trickysolutions.com.au

Disclaimer: The information in this email and any attachments to it are
confidential and may contain legally privileged information. If you are not
the named or intended recipient, please delete this communication and
contact us immediately. Please note you are not authorised to copy, use or disclose this communication or any attachments without our consent. Although this email has been checked by anti-virus software, there is a risk that email messages may be corrupted or infected by viruses or other
interferences. No responsibility is accepted for such interference. Unless
expressly stated, the views of the writer are not those of the company. Tricky Solutions always does our best to provide accurate forecasts and analyses based on the data supplied, however it is possible that some important predictors were not included in the data sent to us. Information provided by us should not be solely relied upon when making decisions and clients should use their own judgement.

> On 29 Nov 2014, at 12:35, Matthew Van Scoyoc <scoyoc at gmail.com> wrote:
> 
> Good afternoon r-sig-ecology,
> 
> I'm running linear mixed models using the lme4 and lmerTest packages to
> examine ecosystem structure in grasslands and shrublands. The grasslands
> are located at lower elevations than the shrublands, and I would like to
> weight the estimates from LS means to reflect the differences in
> elevations. My colleague says there is an easy way to do it in SAS, but I
> haven't found a way to do it in R.
> 
> There is an example dataset and workflow. Here I would be examining grass
> cover differences between the two ecosystems, the quality of the
> ecosystems, and examining the interaction between ecosystem and quality. I
> am also interested in systematic changes throughout the study area (not
> represented in this example) so I don't want to run separate analyses on
> for each ecosystem. I just want to adjust the LS means estimates to reflect
> the differences in elevation and not a mean elevation of the sampled plots.
> 
>> library("lme4")
>> library("lmerTest")
>> 
>> df = data.frame(PlotID = rep(c(paste0("G", 1:30), paste0("S", 1:30)), 2),
> +                 SamplePeriod = as.factor(c(rep(2012, 30), rep(2014,
> 30))),
> +                 Ecosystem = rep(c(rep("Grassland", 30), rep("Shrubland",
> 30)), 2),
> +                 Quality = rep(rep(c(rep("Good", 10), rep("Moderate", 10),
> rep("Poor", 10)), 2), 2),
> +                 GrassCover = c(runif(10, min = 0.50, max = 0.85), # 2012
> Grassland Good
> +                                runif(10, min = 0.50, max = 0.60), # 2012
> Grassland Moderate
> +                                runif(10, min = 0.30, max = 0.40), # 2012
> Grassland Poor
> +                                runif(10, min = 0.25, max = 0.60), # 2012
> Shrubland Good
> +                                runif(10, min = 0.20, max = 0.45), # 2012
> Shrubland Moderate
> +                                runif(10, min = 0.05, max = 0.25), # 2012
> Shrubland Poor
> +                                runif(10, min = 0.50, max = 0.90), # 2014
> Grassland Good
> +                                runif(10, min = 0.50, max = 0.55), # 2014
> Grassland Moderate
> +                                runif(10, min = 0.30, max = 0.30), # 2014
> Grassland Poor
> +                                runif(10, min = 0.25, max = 0.60), # 2014
> Shrubland Good
> +                                runif(10, min = 0.20, max = 0.30), # 2014
> Shrubland Moderate
> +                                runif(10, min = 0.05, max = 0.15))) # 2014
> Shrubland Poor
>> Elevation = c(sample(1200:1700, size = 30, replace = T),
> sample(1800:3000, size = 30,
>>                   replace = T))
>> df$Elevation = c(Elevation, Elevation); rm(Elevation)
>> 
>> lmm = lmer(GrassCover ~ Ecosystem*Quality + Elevation + (1|PlotID), data
> = df, REML = T)
>> anova(lmm,  ddf = "Satterthwaite", type = 3, method.grad = "Richardson")
> Analysis of Variance Table of type 3  with  Satterthwaite
> approximation for degrees of freedom
>                         Sum Sq      Mean Sq      NumDF      DenDF
> F.value    Pr(>F)
> Ecosystem           1.68172     1.68172     1              113
> 51.239    8.79e-11 ***
> Quality               1.97119     0.98560     2               113
> 152.611   < 2.2e-16 ***
> Elevation             0.00311     0.00311     1              113
> 0.016      0.89978
> Ecosystem:Quality 0.04201    0.02101     2              113          3.604
>     0.03039 *
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>> lsms = lsmeans(lmm, method.grad = "Richardson")
>> estimates = lsms[[1]]$Estimate
> 
> At this point I would be plotting the estimates of the significant response
> variables and interactions to look at the differences. As I understand, the
> ecosystem effect and the interaction between ecosystem and quality are with
> an average elevation for all plots, and this could exaggerate LS means
> estimate.  Correcting for elevation would provide more accurate
> estimations. Right?
> 
> Okay, thanks for you help.
> Cheers,
> MVS
> =====
> Matthew Van Scoyoc
> 
> <https://mail.google.com/mail/?view=cm&fs=1&tf=1&to=mvanscoyoc@aggiemail.usu.edu>
> https://sites.google.com/site/scoyoc/
> =====
> Think SNOW!
> 
>    [[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology



More information about the R-sig-ecology mailing list