我从实验设计中收集了以下数据集。我有两个物种(sp1和sp2(,在sp1中,我有两份材料(a1和a2(,它们是不同类型的材料(L和CV(,然后在每一份材料中,我随机抽取两个种子(1和2(,生长后,我从每个种子中产生两个克隆(1和2中(,我对a2也这样做。在数据集中,我有另一个物种sp2,它只有一个登录(a3(,但对这个物种也进行了相同的克隆。
据我所知,这种类型的实验设计被命名为不平衡嵌套设计,其中的因素与阶乘或其他平衡设计的水平不同。现在我想进行方差分析,得到以下结果:
1:方差分析,以便登录嵌套在物种中,并根据测量的性状Y1和Y2,然后用Duncan分组字母的相关图,查看物种之间的差异。
2:比较两个物种的图,同时也表示(分组(不同的类型(L、CV和W(。如果你能帮我,我真的很感激。非常感谢。
df <- data.frame(species=c(rep("sp1",8),rep("sp2",4)),
accession=c(rep("a1",4),rep("a2",4), rep("a3", 4)),
type=c(rep("L",4),rep("CV",4), rep("W", 4)),
seed=c(rep("1",2),rep("2",2), rep("1", 2), rep("2", 2),
rep("1", 2), rep("2", 2)),
clone=c(rep("1",1),rep("2",1), rep("1", 1), rep("2", 1),
rep("1", 1), rep("2", 1), rep("1",1),rep("2",1), rep("1", 1), rep("2", 1),
rep("1", 1), rep("2", 1)),
Y1 = c(11, 10, 8, 9, 20, 21, 19, 19, 6, 5, 7, 8),
Y2 = c(34, 31, 23, 25, 44, 45, 33, 34, 14, 11, 16, 13))
作为开始:
首先使用lme4
/lmerTest
(后者对于固定效果上的p值是必需的(
library(lmerTest)
summary(lmer(Y1 ~ species + (1|species:accession), data = df),
ddf = "Kenward-Roger")
结果:
Random effects:
Groups Name Variance Std.Dev.
species:accession (Intercept) 52.178 7.223
Residual 1.417 1.190
Number of obs: 12, groups: species:accession, 3
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 14.625 5.125 1.000 2.854 0.215
speciessp2 -8.125 8.877 1.000 -0.915 0.528
现在使用nlme
:
library(nlme)
## we have to do a bit of data transformation to make this work
df <- transform(df, sp_acc = interaction(species, accession))
dfg <- groupedData(Y1 ~ 1|sp_acc, df)
summary(lme(Y1 ~ species, random = ~ 1, data = dfg))
Random effects:
Formula: ~1 | sp_acc
(Intercept) Residual
StdDev: 7.223371 1.190238
Fixed effects: Y1 ~ species
Value Std.Error DF t-value p-value
(Intercept) 14.625 5.12500 9 2.8536585 0.0190
speciessp2 -8.125 8.87676 1 -0.9153114 0.5281
大多数结果在两个包之间匹配(加入和残差方差之间的估计;固定效应的估计和标准误差;speciesp2
的分母df和p值(。唯一的差异是截距的df/p-估计值,这可能在科学上并不重要(即,测试物种1的Y1
是否与零显著不同(。