Adds estimated values and associated confidence and/or prediction intervals to trending_fit objects.
Arguments
- object
A
trending_fitobject.- new_data
A
data.framecontaining data for which estimates are to be derived. If missing, the model frame from the fit data will be used.- 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 theciTools::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.- as_tibble
Should the output be converted to a tibble subclass.
- ...
Not currently used.
Value
If as_tibble = FALSE, a trending_predict object, which is a list
subclass, with entries:
result: the input data frame with additional estimates and, optionally, confidence and or prediction intervals.
NULLif the associatedpredictmethod fails.warnings: any warnings generated during prediction.
errors: any errors generated during prediction.
If as_tibble = TRUE, a trending_predict_tbl object which is a
tibble subclass with one row per model and columns
'result', 'warnings' and 'errors' with contents as above.
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")
fitted_poisson <- fit(poisson_model, dat)
predict(fitted_poisson)
#> <trending_predict_tbl> 1 x 3
#> result warnings errors
#> <list> <list> <list>
#> 1 <trndng_p [100 × 7]> <NULL> <NULL>
predict(fitted_poisson, as_tibble = FALSE)
#> <trending_predict_tbl> 1 x 3
#> result warnings errors
#> <list> <list> <list>
#> 1 <trndng_p [100 × 7]> <NULL> <NULL>