首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >变量‘group’已在‘linfct’中指定,但在‘model’中找不到!

变量‘group’已在‘linfct’中指定,但在‘model’中找不到!
EN

Stack Overflow用户
提问于 2017-12-09 07:25:34
回答 1查看 1.7K关注 0票数 3

我的问题已经在以前的论坛上被问到了,但由于某种原因,答案对我来说并不起作用。我正在使用R对对数转换后的数据进行有计划的比较,并且继续得到错误:mcp2matrix(mcp2matrix,linfct = linfct)中的错误:变量‘group’已在‘linfct’中指定,但在‘model’中找不到!任何帮助都将不胜感激。谢谢!

以下是我的数据:

代码语言:javascript
复制
stress.data = read.table(textConnection(" group    rate   lnrate
1      P  69.169 4.236553
2      P  68.862 4.232105
3      C  84.738 4.439564
4      F  99.692 4.602085
5      C  87.231 4.468560
6      C  84.877 4.441203
7      P  70.169 4.250907
8      P  64.169 4.161520
9      P  58.692 4.072303
10     C  80.369 4.386629
11     C  91.754 4.519111
12     P  79.662 4.377793
13     C  87.446 4.471021
14     C  87.785 4.474891
15     P  69.231 4.237449
16     P  75.985 4.330536
17     F  91.354 4.514742
18     C  73.277 4.294247
19     F  83.400 4.423648
20     F 100.877 4.613902
21     C  84.523 4.437024
22     F 102.154 4.626481
23     C  77.800 4.354141
24     C  70.877 4.260946
25     P  86.446 4.459520
26     P  97.538 4.580242
27     F  89.815 4.497752
28     F  80.277 4.385483
29     P  85.000 4.442651
30     F  98.200 4.587006
31     C  90.015 4.499976
32     F 101.062 4.615734
33     F  76.908 4.342610
34     C  99.046 4.595584
35     F  97.046 4.575185
36     P  69.538 4.241873
37     C  75.477 4.323828
38     C  62.646 4.137500
39     P  70.077 4.249595
40     F  88.015 4.477507
41     F  81.600 4.401829
42     F  86.985 4.465736
43     F  92.492 4.527122
44     P  72.262 4.280298
45     P  65.446 4.181225"), header = TRUE)

library("multcomp")
stress.lm= lm(stress.data$lnrate ~ stress.data$group, data = stress.data)
stressPlanned= glht(stress.lm, linfct=mcp(group=c("C-P=0", "F-P=0")))

组中出错(mcp2matrix,linfct = linfct):变量‘group’已在‘linfct’中指定,但在‘model’中找不到!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-09 08:23:36

问题来自于在公式中使用$访问数据,而不是像预期的那样从data参数中获取数据。这通常是不鼓励的,因为它会混淆后续的函数,如您的示例中的predict()glht()。只需使用:

代码语言:javascript
复制
stress.lm <- lm(lnrate ~ group, data = stress.data)
glht(stress.lm, linfct = mcp(group=c("C-P=0", "F-P=0")))
##   General Linear Hypotheses
## 
## Multiple Comparisons of Means: User-defined Contrasts
## 
## Linear Hypotheses:
##            Estimate
## C - P == 0   0.1180
## F - P == 0   0.2215
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47723572

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档