r - biotools R封装中的boxM测试

标签 r error-handling packages

我正在从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

关于r - biotools R封装中的boxM测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36642226/

相关文章:

R:将重复的 'row.names' 设置为数字数据帧

r - 如何使用 ggvis 和映射包(即 ggmap)在 map 上交互地绘制空间数据

java - 捕获错误(而不是异常)有什么意义,因为程序不会由 JVM 启动

c# - 如何在.Net中以中间层结构化方式处理错误或异常

android - 演示和付费应用 - 如何实现?

r - 仅在R中将ggplot上的x轴显示为月

r - 根据计算在数据框中插入行

java - 什么可能导致 Android 上的 DatagramChannel connect() 调用中出现间歇性 'Permissions Denied' 错误?

r - R包:当我的导出函数未从其他包中显式调用函数,而子例程执行时,“import”的工作方式

R - knitr - ShareLatex - install.packages(xyz)