楼主: dominee
1434 1

[问答] 为什么方差分析aov中用data用cbind之后就不对了? [推广有奖]

  • 2关注
  • 2粉丝

硕士生

65%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
4.0016
学术水平
5 点
热心指数
5 点
信用等级
2 点
经验
1184 点
帖子
66
精华
0
在线时间
234 小时
注册时间
2006-5-18
最后登录
2022-4-2

楼主
dominee 发表于 2018-12-30 20:23:35 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
temp=rep(c(300,500,750,800),c(5,5,5,5))
rst=c(90,92,88,89,92,95,92,88,89,92,96,96,97,94,92,91,90,93,89,88)
temp_factor=factor(temp)
df=data.frame(rst,temp_factor)
aov(rst~temp_factor,df)
Call:
   aov(formula = rst ~ temp_factor, data = df)
Terms:
                temp_factor Residuals
Sum of Squares        78.15     74.40
Deg. of Freedom           3        16

这是正确的。而以下是错误的,这是为什么
temp=rep(c(300,500,750,800),c(5,5,5,5))
rst=c(90,92,88,89,92,95,92,88,89,92,96,96,97,94,92,91,90,93,89,88)
temp_factor=factor(temp)
df=data.frame(cbind(rst,temp_factor))
aov(rst~temp_factor,df)
为什么加上了一句,cbind之后就变成了。。
Call:
   aov(formula = rst ~ temp_factor, data = df)
Terms:
                temp_factor Residuals
Sum of Squares         3.61    148.94
Deg. of Freedom           1        18
Residual standard error: 2.876533




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:正确的

回帖推荐

fyc7346165 发表于2楼  查看完整内容

在cbind的帮助说明中有这么一句“The type of a matrix result determined from the highest type of any of the inputs in the hierarchy raw < logical < integer < double < complex < character < list .” 在本例中 所以在使用cbind后,temp_factor已经不是因子了,它被转换成了double

沙发
fyc7346165 发表于 2018-12-30 21:39:13
在cbind的帮助说明中有这么一句“The type of a matrix result determined from the highest type of any of the inputs in the hierarchy raw < logical < integer < double < complex < character < list .”

在本例中
  1. > typeof(temp_factor)
  2. [1] "integer"
  3. > typeof(rst)
  4. [1] "double"
复制代码


所以在使用cbind后,temp_factor已经不是因子了,它被转换成了double
已有 1 人评分论坛币 学术水平 热心指数 收起 理由
dominee + 1 + 1 + 1 精彩帖子

总评分: 论坛币 + 1  学术水平 + 1  热心指数 + 1   查看全部评分

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-3 14:19