如何为R中的随机森林模型运行ANOVA函数?

问题描述 投票:0回答:1

我需要在随机森林模型上执行ANOVA。调用与我在glmgam模型中使用的相同的代码不会在我的rf模型中使用。我应使用什么代码使其正常工作?

我正在使用R中的sdm包来构建我的rf模型。射频模型可以正常运行,但是,我无法在结果上使用ANOVA函数。

MRF <- sdm(presence~.,data=dM,methods='rf',replication='sub',test.percent=20)

anova(MRF)

UseMethod(“ anova”)中的错误:没有适用于'sdmModels

类对象的'anova'适用方法

我也尝试过此选项:

m <-MRF@models$presence$rf$`1`@object

anova(m)

UseMethod(“ anova”)中的错误:没有适用于'anova'的适用方法应用于类“ c('randomForest.formula','randomForest')”的对象]

r random-forest anova
1个回答
0
投票

您可以计算Variable Importance来查看哪些因素最重要,类似于anova类型II对逻辑回归模型所做的工作:

library(caret)

trControl <- trainControl(classProbs = TRUE,
                          method = "cv",
                          number = 5,  # 5-fold cross validation
                          search ="grid",
                          savePredictions = TRUE,
                          summaryFunction = twoClassSummary)

tuneGrid <- expand.grid(.mtry = 18) # Configurable

rf_model <- train(presence~.,            
                          data = dM,
                          method = "rf",
                          tuneGrid = tuneGrid_competitive_jam,
                          trControl = trControl,
                          importance = TRUE,
                          maxnodes = 5,
                          nodesize = 14,
                          ntree = 100)

varImp(rf_model)
© www.soinside.com 2019 - 2024. All rights reserved.