首页 > 解决方案 > 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

                                                                                   

任何帮助,尤其是我需要修复它的代码,都会很棒。我认为数据可能有问题,但我不知道是什么。

标签: r

解决方案


我会这样做。注意因子和连续预测变量之间的差异。

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)


推荐阅读