r - 如何更改原子向量以运行 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")
解决方案
我遇到了同样的问题(即使使用 as.data.frame 也会出现 $ 运算符错误)。确保安装并加载“car”包:
install.packages("car", dependencies=TRUE)
library(car)
"car" 的 anova 函数用大写的 "A" 编写:
Anova(model_category, type="III")
推荐阅读
- python - Django 模型和模板连接
- php - Laravel Homestead 中的引导程序
- css - 为什么@font-face 不能正常工作?
- scala - 将迭代器转换为重复块的迭代器
- git - 在 git bash 中:“错误:refs/tags/prod--release--371 未指向有效对象!” - 如何解决?
- python - 将一行(文件)中的多个字符串与其他文件中的单个字符串相同的行号进行比较
- javascript - 在 JS 中如何最好地向对象文字添加属性?
- reactjs - 在 HoC 中调用 React Hook
- c++ - 如何用 2 个对象覆盖运算符
- reactjs - 为什么手动输入 React Routes 不起作用,它会重定向到另一个页面