问题描述
我希望能够从我使用包插入符号创建的模型生成置信区间.当使用 lm()
创建模型时,可以使用 predict(model, data, interval = "confidence")
来完成.但是,当我对使用 caret 的 train()
函数创建的模型尝试相同的命令时,出现以下错误:
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")
即使我在 train
函数中设置了 method = "lm"
也是如此.有谁知道如何从这样的对象中获得置信区间?最好使用 predict
这样格式是一样的.
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.
谢谢!
推荐答案
了解如何执行此操作!caret
对象实际上将原始模型存储在一大堆元数据之下.您可以使用 my_model_name$finalModel
访问此模型.因此,要找到置信区间,您可以调用 predict(my_model_name$finalModel, my_data, interval = "confidence")
.
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")
.
这篇关于有没有办法从插入符号 lm 对象生成置信区间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!