plot_loadings: Plot the loadings from a DFA

Description Usage Arguments See Also Examples

View source: R/plot_loadings.R

Description

Plot the loadings from a DFA

Usage

1
2
3
4
5
6
7
8
plot_loadings(
  rotated_modelfit,
  names = NULL,
  facet = TRUE,
  violin = TRUE,
  conf_level = 0.95,
  threshold = NULL
)

Arguments

rotated_modelfit

Output from rotate_trends().

names

An optional vector of names for plotting the loadings.

facet

Logical. Should there be a separate facet for each trend? Defaults to TRUE.

violin

Logical. Should the full posterior densities be shown as a violin plot? Defaults to TRUE.

conf_level

Confidence level for credible intervals. Defaults to 0.95.

threshold

Numeric (0-1). Optional for plots, if included, only plot loadings who have Pr(<0) or Pr(>0) > threshold. For example threshold = 0.8 would only display estimates where 80% of posterior density was above/below zero. Defaults to NULL (not used).

See Also

plot_trends fit_dfa rotate_trends

Examples

1
2
3
4
5
6
7
8
9
set.seed(42)
s <- sim_dfa(num_trends = 2, num_ts = 4, num_years = 10)
# only 1 chain and 180 iterations used so example runs quickly:
m <- fit_dfa(y = s$y_sim, num_trends = 2, iter = 50, chains = 1)
r <- rotate_trends(m)
plot_loadings(r, violin = FALSE, facet = TRUE)
plot_loadings(r, violin = FALSE, facet = FALSE)
plot_loadings(r, violin = TRUE, facet = FALSE)
plot_loadings(r, violin = TRUE, facet = TRUE)

Example output

Loading required package: Rcpp
Warning message:
In file(con, "r") : cannot open file '/proc/stat': Permission denied

SAMPLING FOR MODEL 'dfa' NOW (CHAIN 1).
Chain 1: 
Chain 1: Gradient evaluation took 0.000141 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 1.41 seconds.
Chain 1: Adjust your expectations accordingly!
Chain 1: 
Chain 1: 
Chain 1: WARNING: There aren't enough warmup iterations to fit the
Chain 1:          three stages of adaptation as currently configured.
Chain 1:          Reducing each adaptation stage to 15%/75%/10% of
Chain 1:          the given number of warmup iterations:
Chain 1:            init_buffer = 3
Chain 1:            adapt_window = 20
Chain 1:            term_buffer = 2
Chain 1: 
Chain 1: Iteration:  1 / 50 [  2%]  (Warmup)
Chain 1: Iteration:  5 / 50 [ 10%]  (Warmup)
Chain 1: Iteration: 10 / 50 [ 20%]  (Warmup)
Chain 1: Iteration: 15 / 50 [ 30%]  (Warmup)
Chain 1: Iteration: 20 / 50 [ 40%]  (Warmup)
Chain 1: Iteration: 25 / 50 [ 50%]  (Warmup)
Chain 1: Iteration: 26 / 50 [ 52%]  (Sampling)
Chain 1: Iteration: 30 / 50 [ 60%]  (Sampling)
Chain 1: Iteration: 35 / 50 [ 70%]  (Sampling)
Chain 1: Iteration: 40 / 50 [ 80%]  (Sampling)
Chain 1: Iteration: 45 / 50 [ 90%]  (Sampling)
Chain 1: Iteration: 50 / 50 [100%]  (Sampling)
Chain 1: 
Chain 1:  Elapsed Time: 0.005887 seconds (Warm-up)
Chain 1:                0.634828 seconds (Sampling)
Chain 1:                0.640715 seconds (Total)
Chain 1: 
Inference for the input samples (1 chains: each with iter = 25; warmup = 12):

               Q5   Q50  Q95  Mean  SD  Rhat Bulk_ESS Tail_ESS
x[1,1]       -0.4  -0.1  0.1  -0.1 0.2  0.92       13       13
x[2,1]       -0.1   0.3  1.1   0.4 0.4  0.97       13       13
x[1,2]        0.2   0.4  1.0   0.5 0.3  1.04       13       13
x[2,2]        0.6   1.4  2.6   1.4 0.7  1.33        5       13
x[1,3]        1.4   2.0  3.6   2.1 1.0  1.58        4       13
x[2,3]       -1.3   0.0  1.4   0.0 0.9  1.19       10       13
x[1,4]       -0.6  -0.1  0.4  -0.1 0.4  0.96       13       13
x[2,4]        0.3   1.2  1.8   1.2 0.5  1.07       13       13
x[1,5]       -0.6  -0.3  0.1  -0.3 0.2  1.16        8       13
x[2,5]        0.9   1.3  2.7   1.5 0.6  1.14        8       13
x[1,6]       -0.7  -0.3 -0.1  -0.4 0.2  0.95       13       13
x[2,6]       -0.6   0.3  0.8   0.2 0.5  1.04       13       13
x[1,7]       -1.4  -0.4  0.2  -0.5 0.6  1.24        7       13
x[2,7]       -2.5  -0.9 -0.2  -1.2 0.8  1.14        7       13
x[1,8]       -2.3  -0.6 -0.4  -1.0 0.9  1.15       13       13
x[2,8]       -2.6  -1.3 -0.5  -1.5 0.8  1.16        8       13
x[1,9]       -1.4  -0.8 -0.4  -0.8 0.4  1.07       13       13
x[2,9]       -2.9  -1.5 -0.7  -1.7 0.7  1.02       11       13
x[1,10]       0.0   0.3  1.3   0.4 0.5  0.93       13       13
x[2,10]      -1.3  -0.4  0.3  -0.4 0.6  1.12       13       13
Z[1,1]        0.7   1.1  1.5   1.1 0.3  1.47        9       13
Z[2,1]       -1.2  -0.7 -0.3  -0.8 0.3  1.58        8       13
Z[3,1]        0.5   0.9  1.4   1.0 0.3  1.87        8       13
Z[4,1]       -1.5  -0.6  0.0  -0.7 0.5  1.71        9       13
Z[1,2]        0.0   0.0  0.0   0.0 0.0  1.00       13       13
Z[2,2]        0.4   0.8  1.4   0.8 0.4  0.98       13       13
Z[3,2]       -1.1  -0.6 -0.3  -0.6 0.3  1.00       13       13
Z[4,2]        0.5   0.8  1.3   0.9 0.3  0.98       13       13
sigma[1]      0.3   0.3  0.5   0.4 0.1  1.87        4       13
log_lik[1]   -0.3  -0.1  0.4   0.0 0.2  1.58        7       13
log_lik[2]   -2.9  -0.7 -0.2  -1.1 1.0  0.92       13       13
log_lik[3]   -0.4  -0.1  0.3  -0.1 0.2  0.95       13       13
log_lik[4]   -0.8  -0.1  0.3  -0.1 0.4  1.47        5       13
log_lik[5]   -1.8  -0.4  0.3  -0.5 0.7  1.58       13       13
log_lik[6]   -2.9  -1.1  0.2  -1.1 1.1  1.20        8       13
log_lik[7]   -0.6   0.0  0.2  -0.1 0.3  1.30        6       13
log_lik[8]   -1.2  -0.2  0.2  -0.4 0.5  1.19        9       13
log_lik[9]   -1.4  -0.1  0.3  -0.4 0.7  1.01       10       13
log_lik[10]  -1.1   0.0  0.4  -0.2 0.5  1.16       10       13
log_lik[11]  -1.1   0.0  0.3  -0.2 0.5  1.15        8       13
log_lik[12]  -1.3  -0.2  0.3  -0.3 0.6  0.98       13       13
log_lik[13]  -0.6   0.0  0.4  -0.1 0.4  1.27        8       13
log_lik[14]  -0.9  -0.1  0.3  -0.2 0.4  1.11        9       13
log_lik[15]  -0.5  -0.2  0.3  -0.1 0.3  1.16        6       13
log_lik[16]  -0.9   0.0  0.3  -0.1 0.4  1.33        5       13
log_lik[17]  -1.0  -0.2  0.3  -0.3 0.5  1.03        7       13
log_lik[18]  -0.8   0.2  0.3  -0.1 0.4  1.71        4       13
log_lik[19]  -2.1  -0.5 -0.1  -0.7 0.8  1.03       12       13
log_lik[20]  -0.3   0.1  0.3   0.0 0.2  1.71        4       13
log_lik[21]  -1.2  -0.3  0.3  -0.3 0.5  1.18        9       13
log_lik[22]  -0.7  -0.1  0.2  -0.2 0.4  1.00       13       13
log_lik[23]  -0.9  -0.1  0.3  -0.2 0.4  1.71        4       13
log_lik[24]  -0.9   0.0  0.2  -0.1 0.4  1.47        5       13
log_lik[25]  -1.8  -0.1  0.3  -0.5 0.8  0.97       10       13
log_lik[26]  -0.8  -0.3  0.3  -0.3 0.4  1.12       13       13
log_lik[27]  -1.7  -0.7  0.1  -0.6 0.7  1.06       13       13
log_lik[28]  -0.7   0.0  0.4  -0.1 0.4  1.32        5       13
log_lik[29]  -2.0  -0.3  0.3  -0.5 1.0  1.16       10       13
log_lik[30]  -0.9  -0.2  0.2  -0.3 0.4  0.99       13       13
log_lik[31]  -0.4   0.0  0.2   0.0 0.2  0.96       11       13
log_lik[32]  -2.3  -0.5  0.2  -0.8 0.9  1.03       13       13
log_lik[33]  -2.8  -0.4  0.0  -0.9 1.2  0.92       13       13
log_lik[34]  -1.0  -0.1  0.3  -0.2 0.5  1.33        6       13
log_lik[35]  -2.0  -0.1  0.3  -0.3 0.8  1.05       13       13
log_lik[36]  -0.6   0.0  0.3  -0.1 0.3  1.71        4       13
log_lik[37]  -0.6  -0.2  0.2  -0.2 0.3  1.13       10       13
log_lik[38]  -0.6   0.1  0.3   0.0 0.3  1.87        4       13
log_lik[39]  -1.7  -0.5 -0.1  -0.7 0.6  0.92       13       13
log_lik[40]  -1.3  -0.4  0.1  -0.5 0.5  0.97       13       13
psi[1]        0.5   1.0  4.7   1.7 1.7  1.16        8       13
psi[2]        0.5   1.5  2.6   1.5 0.8  1.13        8       13
xstar[1,1]   -1.8   0.5  2.5   0.4 1.7  1.09       10       13
xstar[2,1]   -1.3  -0.2  1.2   0.0 0.9  0.99       13       13
lp__        -19.1 -10.5 -3.0 -10.2 5.5  2.06        4       13

For each parameter, Bulk_ESS and Tail_ESS are crude measures of 
effective sample size for bulk and tail quantities respectively (an ESS > 100 
per chain is considered good), and Rhat is the potential scale reduction 
factor on rank normalized split chains (at convergence, Rhat <= 1.05).
Warning messages:
1: There were 1 chains where the estimated Bayesian Fraction of Missing Information was low. See
http://mc-stan.org/misc/warnings.html#bfmi-low 
2: Examine the pairs() plot to diagnose sampling problems
 
3: The largest R-hat is NA, indicating chains have not mixed.
Running the chains for more iterations may help. See
http://mc-stan.org/misc/warnings.html#r-hat 
4: 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
http://mc-stan.org/misc/warnings.html#bulk-ess 
5: 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
http://mc-stan.org/misc/warnings.html#tail-ess 

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