首页 > 解决方案 > 如何更改原子向量以运行 ANOVA?

问题描述

我想使用 r 进行双向方差分析。我有四列:案例(1-356)、ab_all(我的 IV)、上诉(3 个级别)和产品(2 个级别)。不幸的是,我总是收到错误警告:

“$ 运算符对原子向量无效”。

我知道我需要将我的数据转换为递归对象。但我尝试的一切都失败了。
你知道如何解决这个问题吗?

我已经尝试过 <- data.frame() as.data.frame(mydata)

str(mainstudy_category)
'data.frame':   356 obs. of  4 variables:
 $ CASE   : int  1 2 3 4 5 6 7 8 9 10 ...
 $ ab_all : num  5 5 5 5 4.4 3.2 4.2 2.8 3.8 5 ...
 $ appeal : Factor w/ 3 levels "emotional negative",..: 2 2 1 2 3 3 3 3 3 1 ...
 $ product: Factor w/ 2 levels "hedonic","utilitarian": 1 1 1 2 1 1 1 1 2 2 ...
model_category<-lm(ab_all~product*appeal, data=mainstudy_category)
anova(model_category, type="III")

错误:$ 运算符对原子向量无效

我的数据:

structure(list(CASE = 1:6, ab_all = c(5, 5, 5, 5, 4.4, 3.2), appeal = structure(c(2L, 2L, 1L, 2L, 3L, 3L), .Label = c("emotional negative", "emotional positive", "rational"), class = "factor"), product = structure(c(1L, 1L, 1L, 2L, 1L, 1L), .Label = c("hedonic", "utilitarian"), class = "factor")), row.names = c(NA, 6L), class = "data.frame")

标签: rvectoratomicanova

解决方案


我遇到了同样的问题(即使使用 as.data.frame 也会出现 $ 运算符错误)。确保安装并加载“car”包:

install.packages("car", dependencies=TRUE)
library(car)

"car" 的 anova 函数用大写的 "A" 编写:

Anova(model_category, type="III")

推荐阅读