2016-04-15 49 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