用于不平衡嵌套设计的线性混合模型

发布于 2025-01-12 01:44:49 字数 1080 浏览 1 评论 0原文

我从我的实验设计中收集了以下数据集。我有两个物种(sp1和sp2),在sp1中我有两个种质(a1和a2),它们是不同类型的材料(L和CV),然后在每个种质中,我随机取出两颗种子(1和2)并生长后,我从每个种子中生成了两个克隆(1 和 2),并且我对 a2 做了同样的事情。在数据集中,我有另一个物种 sp2,它只有一个种质 (a3),但也对该物种进行了相同的克隆。

据我所知,这种类型的实验设计被称为不平衡嵌套设计,其中因子的水平与阶乘或其他平衡设计不同。 现在我想进行方差分析以获得以下结果:

1:方差分析,以便种质嵌套在物种中,并根据测量的性状 Y1 和 Y2 查看物种之间的差异,然后与邓肯分组字母相关的情节。

图 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)) 

I have the following data set collected from my experimental design. I have two species (sp1 and sp2), in sp1 I have two accessions (a1 and a2) which are different types of material (L and CV), and then in each accession, I randomly took two seeds (1 and 2) and after growing I generated two clones from each seed (1 and 2) and I did the same for a2. In the dataset, I have another species sp2 which only has one accession (a3) but the same cloning was done for this species also.

As far as I know, this type of experimental design is named as unbalanced nested design, in which factors don't have the same levels as factorial or other balanced designs.
Now I want to perform an analysis of variance to get the following results:

1: analysis of variance so that accession is nested in species and to see the differences between species based on measured traits Y1 and Y2 and then relevant plot with Duncan grouping letters.

2: a plot of comparing two species while different types (L, CV, and W) are also represented (are grouped). I really appreciated it if you could help me. Thanks a lot.

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)) 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

饭团 2025-01-19 01:44:49

作为开始:

首先使用 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 是否与零显着不同)。

As a start:

first with lme4/lmerTest (the latter is needed for p-values on the fixed effects)

library(lmerTest)
summary(lmer(Y1 ~ species + (1|species:accession), data = df),
   ddf = "Kenward-Roger")

Results:

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

Now with 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

Most results match between the two packages (estimate of among-accession and residual variance; estimates and standard errors for fixed effects; denominator df and p-value for speciesp2). The only difference is in the estimated df/p-value for the intercept, which is probably not scientifically important (i.e., testing whether Y1 is significant different from zero for species 1).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文