Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to generate a confidence interval from a caret lm object?

Tags:

r

r-caret

I would like to be able to generate a confidence interval from a model that I create with the package caret. This can be done using predict(model, data, interval = "confidence") when the model is created with lm(). However, when I try the same command with a model created with caret's train() function, I get the following error:

Error in extractPrediction(list(object), unkX = newdata, unkOnly = TRUE,  : 
  unused argument (interval = "confidence")

This is true even when I set method = "lm" in the train function. Does anyone know how to get a confidence interval from such an object? Preferably using predict so the format is the same.

Thanks!

like image 235
ila Avatar asked Jul 06 '15 20:07

ila


1 Answers

Found out how to do this! caret objects do in fact store the original model, beneath a huge pile of metadata. You can access this model with my_model_name$finalModel. Thus, to find the confidence interval, you would call predict(my_model_name$finalModel, my_data, interval = "confidence").

like image 161
ila Avatar answered Dec 15 '22 11:12

ila