我正在从biotools
R包中进行boxM测试,以测试方差 - 协方差矩阵的同质性。我正在研究一个名为rattle
的r包中的“wine”数据集。
首先,我安装了library(car)
。然后我对所有变量进行了跟踪转换,以便在Box M测试后为LDA或QDA准备数据集。
wine1 <- data.frame(wine)
wine1$Type <- as.factor(wine1$Type)
wine1$Alcohol <- as.numeric(wine1$Alcohol) # I converted all other variables to "numeric" class.
当我在RStudio中运行boxM测试[版本0.99.489和Mozilla / 5.0(Macintosh; Intel Mac OS X 10_11_4)AppleWebKit / 601.5.17(KHTML,如Gecko)]
boxM(wine2[,-c(4, 11, 12, 13)], wine2[,1]) # No physical factors
boxM(wine2[,-c(2, 3, 5, 6, 7, 8, 9, 10, 14)], wine2[,1]) # No chemical factor
它返回以下错误
Error: is.numeric(x) || is.logical(x) is not TRUE
答案 0 :(得分:0)
该数据设置需要两件事:将wine2更改为wine1(但是没有修复错误)并从第一个参数中删除第1列到boxM:
> boxM(wine1[,-c(1,4, 11, 12, 13)], wine1[,1])
Box's M-test for Homogeneity of Covariance Matrices
data: wine1[, -c(1, 4, 11, 12, 13)]
Chi-Sq (approx.) = 378.32, df = 90, p-value < 2.2e-16
> boxM(wine2[,-c(1,2, 3, 5, 6, 7, 8, 9, 10, 14)], wine2[,1])
Error in inherits(data, c("data.frame", "matrix")) :
object 'wine2' not found
> boxM(wine1[,-c(1,2, 3, 5, 6, 7, 8, 9, 10, 14)], wine1[,1])
Box's M-test for Homogeneity of Covariance Matrices
data: wine1[, -c(1, 2, 3, 5, 6, 7, 8, 9, 10, 14)]
Chi-Sq (approx.) = 147.69, df = 20, p-value < 2.2e-16