r - R 上的双向 ANOVA 中没有 P 或 F 值
问题描述
我正在为大学做作业,并复制并粘贴了 R 代码,所以我知道这是对的,但我仍然没有从我的数据中获得任何 P 或 F 值:
Food Temperature Area
50 11 820.2175
100 11 936.5437
50 14 1506.568
100 14 1288.053
50 17 1692.882
100 17 1792.54
这是我到目前为止使用的代码:
aovdata<-read.table("Condition by area.csv",sep=",",header=T)
attach(aovdata)
Food <- as.factor(Food) ; Temperature <- as.factor(Temperature)
summary(aov(Area ~ Temperature*Food))
但这是输出:
Df Sum Sq Mean Sq
Temperature 2 757105 378552
Food 1 1 1
Temperature:Food 2 35605 17803
任何帮助,尤其是我需要修复它的代码,都会很棒。我认为数据可能有问题,但我不知道是什么。
解决方案
我会这样做。注意因子和连续预测变量之间的差异。
library(tidyverse)
df <- sapply(strsplit(c("Food Temperature Area", "50 11 820.2175", "100 11 936.5437",
"50 14 1506.568", "100 14 1288.053", "50 17 1692.882",
"100 17 1792.54")," +"), paste0, collapse=",") %>%
read_csv()
model <- lm(Area ~ Temperature * as.factor(Food),df)
summary(model)
#>
#> Call:
#> lm(formula = Area ~ Temperature * as.factor(Food), data = df)
#>
#> Residuals:
#> 1 2 3 4 5 6
#> -83.34 25.50 166.68 -50.99 -83.34 25.50
#>
#> Coefficients:
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) -696.328 505.683 -1.377 0.302
#> Temperature 145.444 35.580 4.088 0.055 .
#> as.factor(Food)100 38.049 715.144 0.053 0.962
#> Temperature:as.factor(Food)100 -2.778 50.317 -0.055 0.961
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Residual standard error: 151 on 2 degrees of freedom
#> Multiple R-squared: 0.9425, Adjusted R-squared: 0.8563
#> F-statistic: 10.93 on 3 and 2 DF, p-value: 0.08498
ggeffects::ggpredict(model,terms = c('Temperature','Food')) %>% plot()
由reprex 包于 2020-12-08 创建(v0.3.0)
推荐阅读
- php - 为每个用户将信息提取到 xml 文件中
- reactjs - React - 在组件之间共享数据的最有效方式
- c# - MediaElement.NaturalDuration.TimeSpan 返回错误值
- javascript - 导入/导出声明只能出现在模块的顶层
- javascript - 在 morris.bar 图表中,所有标签都没有显示但是当我放大所有标签时,所有标签都正确显示
- java - 使用数据库时可以使用类型检查代码吗?
- html - 如何禁用 Datalist 上的选项
- reactjs - 如何将孙子数据传递给 GrandParent 组件而不将数据传递给 Reactjs 中的中间组件?
- linux - 在 Linux 上使用 connect 函数时 UDP 套接字无法接收回复
- python - 在使用 python 库 rply 时,解析多行时出现意外的令牌错误。我怎样才能解决这个问题?