Summarize and plot time varying coefficients from the fitted model

dlm_trends(fitted_model)

Arguments

fitted_model

A fitted model object

Value

A list containing the plot and data used to fit the model. These include plot and b_varying

Examples

# \donttest{
set.seed(123)
N = 20
data = data.frame("y" = runif(N),
                  "cov1" = rnorm(N),
                  "cov2" = rnorm(N),
                  "year" = 1:N,
                  "season" = sample(c("A","B"), size=N, replace=TRUE))
b_1 = cumsum(rnorm(N))
b_2 = cumsum(rnorm(N))
data$y = data$cov1*b_1 + data$cov2*b_2
time_varying = y ~ cov1 + cov2
formula = NULL
fit <- fit_dlm(formula = formula,
               time_varying = time_varying,
               time = "year",
               est_df = FALSE,
               family = c("normal"),
               data=data, chains = 1, iter = 20)
#> 
#> SAMPLING FOR MODEL 'dlm' NOW (CHAIN 1).
#> Chain 1: 
#> Chain 1: Gradient evaluation took 0.002149 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 21.49 seconds.
#> Chain 1: Adjust your expectations accordingly!
#> Chain 1: 
#> Chain 1: 
#> Chain 1: WARNING: No variance estimation is
#> Chain 1:          performed for num_warmup < 20
#> Chain 1: 
#> Chain 1: Iteration:  1 / 20 [  5%]  (Warmup)
#> Chain 1: Iteration:  2 / 20 [ 10%]  (Warmup)
#> Chain 1: Iteration:  4 / 20 [ 20%]  (Warmup)
#> Chain 1: Iteration:  6 / 20 [ 30%]  (Warmup)
#> Chain 1: Iteration:  8 / 20 [ 40%]  (Warmup)
#> Chain 1: Iteration: 10 / 20 [ 50%]  (Warmup)
#> Chain 1: Iteration: 11 / 20 [ 55%]  (Sampling)
#> Chain 1: Iteration: 12 / 20 [ 60%]  (Sampling)
#> Chain 1: Iteration: 14 / 20 [ 70%]  (Sampling)
#> Chain 1: Iteration: 16 / 20 [ 80%]  (Sampling)
#> Chain 1: Iteration: 18 / 20 [ 90%]  (Sampling)
#> Chain 1: Iteration: 20 / 20 [100%]  (Sampling)
#> Chain 1: 
#> Chain 1:  Elapsed Time: 1.491 seconds (Warm-up)
#> Chain 1:                1.372 seconds (Sampling)
#> Chain 1:                2.863 seconds (Total)
#> Chain 1: 
#> Warning: The largest R-hat is NA, indicating chains have not mixed.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#r-hat
#> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#bulk-ess
#> Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#tail-ess
dlm_trends(fit)
#> Error in dlm_trends(fit): object 'fit' not found
# }