Reputation: 395
I want to use the function prediction_summary()
of the prediction package and adjust the confidence interval length. However, it seems as if the level specification does not make any difference. Am I doing something wrong here?
Reproducible example:
# Make data
DF <- data.frame(
x = rnorm(n= 100, 20,3),
y = rbinom(n = 100, size = 1, prob=0.4)
)
# Specify model
model <- glm(x ~ y, data = DF)
# Prediction
prediction::prediction_summary(
model = model,
level = 0.2
)
# Same result
prediction::prediction_summary(
model = model,
level = 0.9
)
Upvotes: 1
Views: 53
Reputation: 887118
The issue is related to the source code
library(prediction)
prediction_summary
function (model, ..., level = 0.95)
{
predictions <- prediction(model, ...)
summary(predictions, level = 0.95)
}
Note that the level
is hard-coded as 0.95
in summary
. We can make a correction with by modifying the summary
line to take the input as level = level
i.e. user specified level
body(prediction_summary)[[3]] <- quote(summary(predictions, level = level))
Now, do the test
> prediction_summary(
+ model = model,
+ level = 0.9
+ )
Prediction SE z p lower upper
19.96 0.3178 62.81 0 19.44 20.49
> prediction_summary(
+ model = model,
+ level = 0.2
+ )
Prediction SE z p lower upper
19.96 0.3178 62.81 0 19.88 20.04
Upvotes: 4