2016-04-15 445 views
0

我正在从biotools R包中进行boxM测试来测试方差 - 协方差矩阵的同质性。我正在研究一个名为rattle的r包中的“wine”数据集。 首先,我安装了library(car)。然后,我对所有变量进行了以下转换,以便在Box's M测试后为LDA或QDA准备数据集。biofools R包中的boxM测试

wine1 <- data.frame(wine) 
wine1$Type <- as.factor(wine1$Type) 
wine1$Alcohol <- as.numeric(wine1$Alcohol) # I converted all other variables to "numeric" class. 

当我跑boxM测试在RStudio [0.99.489版和Mozilla/5.0(Macintosh上;英特尔的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

您还没有定义'wine2' –

回答

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