我正在从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 [版本0.99.489和Mozilla/5.0(Macintosh; Intel Mac OS X 10_11_4)AppleWebKit/601.5.17(KHTML,如Gecko)]中运行boxM测试时
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
最佳答案
数据设置需要做两件事:将wine2更改为wine1(但这不能解决您的错误),并从boxM的第一个参数中删除列1:
> 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