作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 BACI 实验,在三个地点之前(2007 年)和之后(2011 年)进行了测量。在设置对比时遇到问题,所以我看看年份对三个地点中每个地点的处理(对照对照)的影响是否不同。
我试图扩展 vignette 中的示例没有成功。也试过 lsmeans 包。
下面的示例 df 和代码,以及我想测试的显式对比。
library(nlme)
library(multcomp)
require(lsmeans)
# I have these versions:
# R version 3.2.4 Revised (2016-03-16 r70336)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 7 x64 (build 7601) Service Pack 1
# nlme_3.1-126
# multcomp_1.4-4
exdf <- expand.grid(Site = c("Z", "Y", "X"),
Plot = 1:30,
Year = c("2007", "2011"),
Treatment = c("Control", "A", "B", "A+B"))
exdf$Site <- factor(exdf$Site)
exdf$Plot <- factor(exdf$Plot)
exdf$Year <- factor(exdf$Year)
exdf$Treatment <- factor(exdf$Treatment)
exdf$Treatment <- relevel(exdf$Treatment, ref = "Control")
exdf$Response <- rnorm(mean = 1150, sd = 130, n = nrow(exdf))
mod1 <- lme(data = exdf,
fixed = Response ~ Year * Treatment * Site,
random = ~1|Plot)
## would like to test (obviously that's not actual code)
## How do the treatments A, B, A+B differ in their interaction with
## year, compared to the control treatment (ie do the slopes differ)
SiteX:Year:TreatmentControl - SiteX:Year:TreatmentA == 0
SiteX:Year:TreatmentControl - SiteX:Year:TreatmentB == 0
SiteX:Year:TreatmentControl - SiteX:Year:TreatmentA+B == 0
SiteY:Year:TreatmentControl - SiteY:Year:TreatmentA == 0
SiteY:Year:TreatmentControl - SiteY:Year:TreatmentB == 0
SiteY:Year:TreatmentControl - SiteY:Year:TreatmentA+B == 0
SiteZ:Year:TreatmentControl - SiteZ:Year:TreatmentA == 0
SiteZ:Year:TreatmentControl - SiteZ:Year:TreatmentB == 0
SiteZ:Year:TreatmentControl - SiteZ:Year:TreatmentA+B == 0
## Also potentially - does the interaction between site and year
## differ across sites?
SiteX:Year:TreatmentA - SiteY:Year:TreatmentA == 0
SiteZ:Year:TreatmentA - SiteY:Year:TreatmentA == 0
SiteZ:Year:TreatmentA - SiteX:Year:TreatmentA == 0
SiteX:Year:TreatmentB - SiteY:Year:TreatmentB == 0
SiteZ:Year:TreatmentB - SiteY:Year:TreatmentB == 0
SiteZ:Year:TreatmentB - SiteX:Year:TreatmentB == 0
SiteX:Year:TreatmentA+B - SiteY:Year:TreatmentA+B == 0
SiteZ:Year:TreatmentA+B - SiteY:Year:TreatmentA+B == 0
SiteZ:Year:TreatmentA+B - SiteX:Year:TreatmentA+B == 0
## Started doing the example from
#https://cran.r-project.org/web/packages/multcomp/vignettes/multcomp-examples.pdf
# Got a bit stuck
tmp <- expand.grid(Year = levels(exdf$Year),
Treatment = levels(exdf$Treatment),
Site = levels(exdf$Site))
X <- model.matrix(~ Year * Treatment * Site, data = tmp)
glht(mod1, linfct = X)
## Gives all the interactions not in the form I want..
tt <- lsmeans(mod1, specs = ~Year:Treatment|Site)
comps <- pairs(tt, interaction = TRUE)
summary(comps, adjust = "holm")
最佳答案
让我们逐步构建它。首先,您想为其他因素的每个组合获得两年的差异。这很容易在 中完成lsmeans 使用
tt = lsmeans(mod1, specs = ~ Year | Treatment:Site)
dd = pairs(tt, reverse = TRUE) # (2011) - (2008) for each T*S comb
summary(dd, by = NULL)
pairs(dd, by = "Site")
pairs(dd, by = "Treatment")
pairs(lsmeans(dd, "Treatment"))
pairs(lsmeans(dd, "Site"))
关于r - 使用multcomp设置三向交互的对比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37126460/
假设我正在使用 R ( Bretz et al. (2011) Multiple Comparisons with R. Chapman & Hall/CRC) 的 multcomp 包进行剂量 re
我是一名优秀的程序员,十分优秀!