find_dfa_trends: Find the best number of trends according to LOOIC

Description Usage Arguments Examples

View source: R/find_dfa_trends.R

Description

Fit a DFA with different number of trends and return the leave one out (LOO) value as calculated by the loo package.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
find_dfa_trends(
  y = y,
  kmin = 1,
  kmax = 5,
  iter = 2000,
  thin = 1,
  compare_normal = FALSE,
  convergence_threshold = 1.05,
  variance = c("equal", "unequal"),
  ...
)

Arguments

y

A matrix of data to fit. Columns represent time element.

kmin

Minimum number of trends, defaults to 1.

kmax

Maximum number of trends, defaults to 5.

iter

Iterations when sampling from each Stan model, defaults to 2000.

thin

Thinning rate when sampling from each Stan model, defaults to 1.

compare_normal

If TRUE, does model selection comparison of Normal vs. Student-t errors

convergence_threshold

The maximum allowed value of Rhat to determine convergence of parameters

variance

Vector of variance arguments for searching over large groups of models. Can be either or both of ("equal","unequal")

...

Other arguments to pass to fit_dfa()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
set.seed(42)
s <- sim_dfa(num_trends = 2, num_years = 20, num_ts = 3)
# only 1 chain and 180 iterations used so example runs quickly:
m <- find_dfa_trends(
  y = s$y_sim, iter = 50,
  kmin = 1, kmax = 2, chains = 1, compare_normal = FALSE,
  variance = "equal", convergence_threshold = 1.1,
  control = list(adapt_delta = 0.95, max_treedepth = 20)
)
m$summary
m$best_model

bayesdfa documentation built on May 29, 2021, 1:06 a.m.