首页 > 解决方案 > ANOVA 因子警告和无 p 值

问题描述

我正在为数据集做单向方差分析,我在这里显示了一些行:-

Number  Call    Weight
1   X   33.29
2   Y   88.22
3   Y   70.19
4   Y   69.25
5   X   73.26
6   X   56.18
7   Y   16.19
8   Y   20.21
9   Y   50.26
10  X   95.29

我做了方差分析: -

aov <- aov(data$Weight ~ data$Call)

但它没有给出任何 p 值。我也得到: -

Warning messages:
1: In model.response(mf, "numeric") :
  using type = "numeric" with a factor response will be ignored
2: In Ops.factor(y, z$residuals) : ‘-’ not meaningful for factors

标签: r

解决方案


我已经在这些数据上尝试了您的代码,并且它可以正常工作。尝试检查str您的数据。最可能的问题是这Weight是您的情况的因素,您需要将其更改为数字与as.numeric().

   dta <- read.table(text=
   "Number,  Call,    Weight
    1,   X,   33.29
    2,   Y,   88.22
    3,   Y,   70.19
    4,   Y,   69.25
    5,   X,   73.26
    6,   X,   56.18
    7,   Y,   16.19
    8,   Y,   20.21
    9,   Y,   50.26
    1,0  X,   95.29", header=T, sep=",")

    summary(aov(dta$Weight ~ dta$Call))

结果

Call:
   aov(formula = dta$Weight ~ dta$Call)

Terms:
                dta$Call Residuals
Sum of Squares   352.450  6303.466
Deg. of Freedom        1         8

Residual standard error: 28.07015
Estimated effects may be unbalanced

结果为str(dta)

'data.frame':   10 obs. of  3 variables:
 $ Number: int  1 2 3 4 5 6 7 8 9 1
 $ Call  : Factor w/ 3 levels "   X","   Y",..: 1 2 2 2 1 1 2 2 2 3
 $ Weight: num  33.3 88.2 70.2 69.2 73.3 ...

推荐阅读