【问题标题】:qqplot (and other plots for diagnostics) after AIC using train() functionAIC 后使用 train() 函数的 qqplot(和其他诊断图)
【发布时间】:2021-07-20 14:47:44
【问题描述】:

我正在使用 train() 函数为 OLS 拟合逐步变量选择。

在我运行模型并尝试使用 plot() 绘制 qqplot 后,它会根据最大预测变量数绘制 RMSE。

有没有办法在上面的模型之后绘制qqplot和其他诊断图?

我写的代码如下:

OLS_AIC_CV = train(Variable ~ . , data = df_train_all, 
                       method = "leapSeq", 
                       trControl = trainControl(method = "cv", number = 3), 
                       tuneGrid = data.frame(nvmax = 1:10) 
                   )   

plot(OLS_AIC_CV)

谢谢,

【问题讨论】:

  • 你试过plot(OLS_AIC_CV$finalModel)吗?

标签: r plot regression r-caret


【解决方案1】:

您可以尝试这样的事情:从逐步选择中,选择变量的最佳子集,用最佳子集重新拟合 lm 模型,然后从新的 lm obkect 中提取 qqplot。

data("mtcars")
library(caret)
set.seed(5)
OLS_AIC_CV = train(mpg ~ . , data = mtcars, 
                   method = "leapSeq", 
                   trControl = trainControl(method = "cv", number = 3), 
                   tuneGrid = data.frame(nvmax = 1:10) 
)   

fit <- OLS_AIC_CV$finalModel
#extract the best subset of variable 
x <- summary(fit)$which[2,-1]
new.df <- mtcars[,x]
#refit the lm model 
OLS <-  train(
  mpg ~ .,
  data = new.df,
  method = "lm",
  trControl = trainControl(method = "cv", number = 3)
)   
#plot the qqplot 
plot(OLS$finalModel,2)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-10
    • 2016-10-20
    • 2014-05-23
    • 1970-01-01
    • 2016-08-06
    • 1970-01-01
    • 2015-12-28
    • 2020-03-29
    相关资源
    最近更新 更多