简体   繁体   English

在R中构造重复测量方差分析并提取ls均值。

[英]Constructing repeated measures ANOVA in R and extracting ls means.

I am trying to properly construct a repeated measures ANOVA in R and extract the associated lsmeans. 我试图在R中正确构建重复测量方差分析,并提取相关的lsmeans。 My data consists of a dependent variable (rSWC) and a predictor (Geno). 我的数据由一个因变量(rSWC)和一个预测变量(Geno)组成。 The full dataset is as below: 完整的数据集如下:

> str(mydata)
'data.frame':   153 obs. of  5 variables:
 $ Geno          : Factor w/ 5 levels "8306","8307",.. 
 $ BioRepeat     : int  1 1 1 1 1 1 1 1 1 2 ...
 $ Geno_BioRepeat: Factor w/ 17 levels "8306_1","8306_2",..
 $ Day           : Factor w/ 9 levels "1","2","3","4",.. 
 $ rSWC          : num  104.5 92.5 81.8 65.6 61 ...

I am constructing my repeated measures anova as: 我正在将我的重复措施方差分析构建为:

rmaModel <- aov(rSWC ~ Geno + Error(Day/Geno), data=mydata)

I wish to extract the lsmeans (and associated variance terms) for Geno for every repeated measure (Day). 我希望为每个重复的度量(天)提取Geno的lsmeans(和相关的方差项)。 At the moment if I try to extract the lsmean, I just get one lsmean for each Geno and a warning message that I cannot interpret: 目前,如果我尝试提取lsmean,则对于每个Geno我只会得到一个lsmean和一条我无法解释的警告消息:

> library(lsmeans)
> lsmeans(rmaModel, specs = "Geno")
 Geno      lsmean        SE    df lower.CL  upper.CL
 8306    59.43538  8.905658  8.00 38.89890  79.97187
 8307    58.06825  9.988820 12.45 35.03399  81.10251
 8417    71.16686 10.158125 13.24 47.74219  94.59154
 Control 86.97797 10.488538 14.84 62.79136 111.16459
 WT      45.76538  9.988820 12.45 22.73112  68.79964

Confidence level used: 0.95 
Warning message:
In lsm.basis.aovlist(object, trms, xlev, grid, ...) :
  Some predictors are correlated with the intercept - results are biased.
 May help to re-fit with different contrasts, e.g. 'contr.sum' 

Any help to understand whether my model is constructed appropriately, how to extract the lsmean for each repeated measure, and how to interpret the warning message would be very much appreciated. 对于理解我的模型是否构建适当,如何为每次重复测量提取lsmean以及如何解释警告消息的任何帮助,将不胜感激。 Thanks! 谢谢!

The default contrasts for statistical tests in R regression functions are treatment contrasts, so the "Intercept" level is generally the first of each of the factor variables. R回归函数中统计检验的默认对比是处理对比,因此“拦截”级别通常是每个因子变量中的第一个。 The warning message is suggesting you might redefine the contrasts for your Geno variable. 警告消息表明您可能需要重新定义Geno变量的对比度。 So that might be done with: 因此可以通过以下方式完成:

 ?contrasts  # to get the background theory and example code
 contrasts(mydata$Geno) <- contr.sum(5) 
 rmaModel <- aov(rSWC ~ Geno + Error(Day/Geno), data=mydata) # refit
 lsmeans(rmaModel, specs = "Geno") 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM