Confidence and Prediction Interval for Model Predictions
Returns the Confidence (or Prediction) Interval (CI) associated with predictions made by a model.
get_predicted_ci( x, predictions = NULL, data = NULL, ci = 0.95, ci_type = "confidence", vcov_estimation = NULL, vcov_type = NULL, vcov_args = NULL, dispersion_function = "sd", interval_function = "quantile", ... )
x |
A statistical model (can also be a data.frame, in which case the second argument has to be a model). |
predictions |
A vector of predicted values (as obtained by
|
data |
An optional data frame in which to look for variables with which to predict. If omitted, the data used to fit the model is used. |
ci |
The interval level (default |
ci_type |
Can be |
vcov_estimation |
String, indicating the suffix of the
|
vcov_type |
Character vector, specifying the estimation type for the
robust covariance matrix estimation (see
|
vcov_args |
List of named vectors, used as additional arguments that are
passed down to the sandwich-function specified in
|
dispersion_function, interval_function |
These arguments are only used in
the context of bootstrapped and Bayesian models. Possible values are
|
... |
Not used for now. |
The Confidence (or Prediction) Interval (CI).
data(mtcars) # Linear model x <- lm(mpg ~ cyl + hp, data = mtcars) predictions <- predict(x) ci_vals <- get_predicted_ci(x, predictions, ci_type = "prediction") head(ci_vals) ci_vals <- get_predicted_ci(x, predictions, ci_type = "confidence") head(ci_vals) predictions <- get_predicted(x, iterations = 500) get_predicted_ci(x, predictions) if (require("bayestestR")) { ci_vals <- get_predicted_ci(x, predictions, ci = c(0.80, 0.95)) head(ci_vals) bayestestR::reshape_ci(ci_vals) ci_vals <- get_predicted_ci(x, predictions, dispersion_function = "MAD", interval_function = "HDI" ) head(ci_vals) } # Logistic model x <- glm(vs ~ wt, data = mtcars, family = "binomial") predictions <- predict(x, type = "link") ci_vals <- get_predicted_ci(x, predictions, ci_type = "prediction") head(ci_vals) ci_vals <- get_predicted_ci(x, predictions, ci_type = "confidence") head(ci_vals)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.