Predict method for trending_model objects
Source:R/predict-trending_model.R
predict.trending_model.Rd
Adds estimated values and associated confidence and/or prediction intervals to data based on trending_model fit.
Arguments
- object
A
trending_model
object.- 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 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.
NULL
if the associatedpredict
method 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")
predict(poisson_model, dat)
#> <trending_predict_tbl> 1 x 3
#> result warnings errors
#> <list> <list> <list>
#> 1 <trndng_p [100 × 7]> <NULL> <NULL>
predict(poisson_model, dat, as_tibble = FALSE)
#> $result
#> <trending_prediction> 100 x 7
#> x y estimate lower_ci upper_ci lower_pi upper_pi
#> <dbl> <int> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 0.238 1 4.94 4.51 5.41 1 10
#> 2 -0.296 5 3.76 3.36 4.22 0 9
#> 3 0.369 4 5.28 4.84 5.77 1 11
#> 4 1.35 10 8.71 7.85 9.66 3 16
#> 5 -0.489 6 3.41 3.01 3.86 0 8
#> 6 1.09 6 7.64 6.95 8.39 2 14
#> 7 -0.561 4 3.29 2.89 3.74 0 8
#> 8 -0.984 3 2.65 2.26 3.09 0 7
#> 9 0.134 8 4.69 4.26 5.15 1 10
#> 10 0.749 4 6.41 5.88 6.99 2 13
#> # ℹ 90 more rows
#>
#> $warnings
#> NULL
#>
#> $errors
#> NULL
#>
#> attr(,"class")
#> [1] "trending_predict" "list"