Skip to contents

Adds estimated values and associated confidence and/or prediction intervals to data based on trending_model fit.

Usage

# S3 method for list
predict(
  object,
  data,
  name = "estimate",
  alpha = 0.05,
  add_ci = TRUE,
  ci_names = c("lower_ci", "upper_ci"),
  add_pi = TRUE,
  pi_names = c("lower_pi", "upper_pi"),
  simulate_pi = FALSE,
  sims = 2000,
  uncertain = TRUE,
  ...
)

Arguments

object

A list of trending_model objects.

data

A data.frame containing data to which the model is to be fit and estimates derived.

name

Character vector of length one giving the name to use for the calculated estimate.

alpha

The alpha threshold to be used for prediction intervals, defaulting to 0.05, i.e. 95% prediction intervals are derived.

add_ci

Should a confidence interval be added to the output. Default TRUE.

ci_names

Names to use for the resulting confidence intervals.

add_pi

Should a prediction interval be added to the output. Default TRUE.

pi_names

Names to use for the resulting prediction intervals.

simulate_pi

Should the prediction intervals for glm models be simulated. If TRUE, default, predict() uses the ciTools::add_pi() function to generate the intervals.

sims

The number of simulations to run when simulating prediction intervals for a glm model.

uncertain

Only used for glm models and when simulate_pi = FALSE. Default TRUE. If FALSE uncertainty in the fitted parameters is ignored when generating the parametric prediction intervals.

...

Not currently used.

Value

A trending_predict_tbl object which is a tibble subclass with one row per model and columns:

  • result: the input data frame with additional estimates and, optionally, confidence and or prediction intervals. NULL if the associated predict method fails.

  • warnings: any warnings generated during prediction.

  • errors: any errors generated during prediction.

Author

Tim Taylor

Examples

x = rnorm(100, mean = 0)
y = rpois(n = 100, lambda = exp(1.5 + 0.5*x))
dat <- data.frame(x = x, y = y)
poisson_model <- glm_model(y ~ x , family = "poisson")
negbin_model <- glm_nb_model(y ~ x)
predict(list(poisson_model, negbin_model), dat)
#> <trending_predict_tbl> 2 x 3
#>   result               warnings errors
#>   <list>               <list>   <list>
#> 1 <trndng_p [100 × 7]> <NULL>   <NULL>
#> 2 <trndng_p [100 × 7]> <NULL>   <NULL>
predict(list(pm = poisson_model, nm = negbin_model), dat)
#> <trending_predict_tbl> 2 x 4
#>   model_name result               warnings     errors      
#>   <chr>      <named list>         <named list> <named list>
#> 1 pm         <trndng_p [100 × 7]> <NULL>       <NULL>      
#> 2 nm         <trndng_p [100 × 7]> <NULL>       <NULL>