AIC 使用 train() 函数后的 qqplot(和其他诊断图)

qqplot (and other plots for diagnostics) after AIC using train() function

我正在使用 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)

谢谢,

你可以这样尝试:从逐步selection,select最好的变量子集,用最好的子集重新拟合一个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)