我想对我的数据进行 Tukey 测试并找到一些代码。我花了一些时间将它应用于我的数据,当我到达 glht 时,我得到了上面的错误。我想也许我的数据输入错误,所以我用演示数据对其进行了测试,但我得到了同样的错误:
mcp2matrix(模型,linfct = linfct)中的错误:类“字符”的变量“X”不包含在“模型”中。
这是演示数据:
Y X
1 0.2855104 A
2 0.3385240 A
3 0.0883132 A
4 0.2059308 A
5 0.3632401 A
6 0.5217391 B
7 0.7633588 B
8 0.3254679 B
9 0.4253057 B
10 0.3780718 B
11 0.9891197 C
12 1.1927181 C
13 0.7882883 C
14 0.5491762 C
15 0.5445882 C
16 1.2670565 D
17 1.6253208 D
18 1.2661090 D
19 1.1541876 D
20 1.2684989 D
21 1.0695187 D
这是完整的代码:
install.packages("multcomp")
expt1 <- read.table("demo.txt",header=T)
amod <- aov(Y~X,data=expt1)
summary(amod)
library("multcomp")
tmod <- glht(amod,linfct=mcp(X="Tukey"))
这就是它在 R 中的显示方式(安装软件包后):
> expt1 <- read.table("demo.txt",header=T)
> amod <- aov(Y~X,data=expt1)
> summary(amod)
Df Sum Sq Mean Sq F value Pr(>F)
X 3 3.244 1.0815 27.59 9.26e-07 ***
Residuals 17 0.666 0.0392
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> library("multcomp")
Loading required package: mvtnorm
Loading required package: survival
Loading required package: TH.data
Loading required package: MASS
Attaching package: ‘TH.data’
The following object is masked from ‘package:MASS’:
geyser
> tmod <- glht(amod,linfct=mcp(X="Tukey"))
Error in mcp2matrix(model, linfct = linfct) :
Variable(s) ‘X’ of class ‘character’ is/are not contained as a factor in ‘model’.
我完全是新手,我完全被难住了。我究竟做错了什么?