Get the fitted values from a DFA as a data frame

dfa_fitted(modelfit, conf_level = 0.95, names = NULL)

Arguments

modelfit

Output from fit_dfa.

conf_level

Probability level for CI.

names

Optional vector of names for time series labels. Should be same length as the number of time series.

Value

A data frame with the following columns: ID is an identifier for each time series, time is the time step, y is the observed values standardized to mean 0 and unit variance, estimate is the mean fitted value, lower is the lower CI, and upper is the upper CI.

See also

predicted plot_fitted fit_dfa

Examples

# \donttest{
y <- sim_dfa(num_trends = 2, num_years = 20, num_ts = 4)
m <- fit_dfa(y = y$y_sim, num_trends = 2, iter = 50, chains = 1)
#> 
#> SAMPLING FOR MODEL 'dfa' NOW (CHAIN 1).
#> Chain 1: 
#> Chain 1: Gradient evaluation took 0.000126 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 1.26 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.011398 seconds (Warm-up)
#> Chain 1:                0.042844 seconds (Sampling)
#> Chain 1:                0.054242 seconds (Total)
#> Chain 1: 
#> Warning: There were 1 chains where the estimated Bayesian Fraction of Missing Information was low. See
#> https://mc-stan.org/misc/warnings.html#bfmi-low
#> Warning: Examine the pairs() plot to diagnose sampling problems
#> 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
#> 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.8     -0.8     -0.7     -0.8    0.0  2.06        4       13
#> x[2,1]          -0.6     -0.6     -0.6     -0.6    0.0  2.06        4       13
#> x[1,2]          -1.4     -1.4     -1.4     -1.4    0.0  2.06        3       13
#> x[2,2]          -0.7     -0.6     -0.5     -0.6    0.0  2.06        4       13
#> x[1,3]          -0.2     -0.2     -0.1     -0.2    0.0  2.06        3       13
#> x[2,3]           0.0      0.1      0.1      0.1    0.1  2.06        4       13
#> x[1,4]          -0.3     -0.2     -0.2     -0.2    0.0  2.06        4       13
#> x[2,4]          -0.8     -0.7     -0.6     -0.7    0.1  2.06        4       13
#> x[1,5]           1.6      1.6      1.6      1.6    0.0  2.06        4       13
#> x[2,5]          -1.1     -0.9     -0.8     -1.0    0.1  2.06        4       13
#> x[1,6]           1.5      1.5      1.5      1.5    0.0  2.06        4       13
#> x[2,6]           0.2      0.4      0.4      0.3    0.1  2.06        4       13
#> x[1,7]          -0.3     -0.2     -0.2     -0.2    0.0  2.06        4       13
#> x[2,7]          -1.7     -1.4     -1.3     -1.5    0.1  2.06        3       13
#> x[1,8]          -1.2     -1.1     -1.1     -1.1    0.1  2.06        3       13
#> x[2,8]          -0.3      0.0      0.0     -0.1    0.1  2.06        4       13
#> x[1,9]          -1.1     -1.0     -1.0     -1.0    0.1  2.06        3       13
#> x[2,9]          -1.7     -1.4     -1.4     -1.5    0.1  2.06        4       13
#> x[1,10]         -0.4     -0.3     -0.3     -0.3    0.0  2.06        4       13
#> x[2,10]         -1.9     -1.7     -1.6     -1.7    0.1  2.06        4       13
#> x[1,11]         -0.4     -0.4     -0.3     -0.4    0.0  2.06        4       13
#> x[2,11]         -0.8     -0.7     -0.6     -0.7    0.1  2.06        4       13
#> x[1,12]         -0.5     -0.4     -0.4     -0.4    0.0  2.06        4       13
#> x[2,12]          0.5      0.5      0.6      0.5    0.0  2.06        4       13
#> x[1,13]          0.8      0.8      0.8      0.8    0.0  2.06        4       13
#> x[2,13]          0.4      0.5      0.5      0.5    0.0  1.48        4       13
#> x[1,14]         -0.9     -0.9     -0.9     -0.9    0.0  2.06        4       13
#> x[2,14]          0.3      0.4      0.4      0.4    0.0  1.24        5       13
#> x[1,15]         -0.6     -0.6     -0.6     -0.6    0.0  1.87        7       13
#> x[2,15]          0.7      0.8      0.9      0.8    0.1  2.06        3       13
#> x[1,16]          0.4      0.4      0.5      0.4    0.0  1.18        7       13
#> x[2,16]          0.4      0.5      0.6      0.5    0.1  2.06        3       13
#> x[1,17]          1.7      1.7      1.8      1.7    0.0  1.07        6       13
#> x[2,17]          1.3      1.5      1.6      1.4    0.1  2.06        3       13
#> x[1,18]          1.1      1.1      1.2      1.1    0.0  1.39        4       13
#> x[2,18]         -0.4     -0.3     -0.2     -0.3    0.1  2.06        3       13
#> x[1,19]         -0.4     -0.4     -0.4     -0.4    0.0  1.71        4       13
#> x[2,19]          0.6      0.7      0.8      0.7    0.1  2.06        3       13
#> x[1,20]         -1.0     -1.0     -1.0     -1.0    0.0  1.58        8       13
#> x[2,20]          0.0      0.2      0.3      0.2    0.1  2.06        3       13
#> Z[1,1]         -99.8    -99.8    -99.8    -99.8    0.0  1.71        4       13
#> Z[2,1]         -26.6    -20.0    -15.7    -21.4    4.1  2.06        3       13
#> Z[3,1]          27.5     34.0     41.9     35.3    5.4  2.06        3       13
#> Z[4,1]         -31.5    -24.5    -19.8    -25.7    4.5  2.06        3       13
#> Z[1,2]           0.0      0.0      0.0      0.0    0.0  1.00       13       13
#> Z[2,2]         -98.9    -98.9    -98.9    -98.9    0.0  2.06        4       13
#> Z[3,2]         -41.9    -33.9    -27.8    -35.3    5.1  2.06        3       13
#> Z[4,2]         -11.6     -7.9     -5.7     -8.6    2.4  2.06        3       13
#> log_lik[1]     -47.2    -22.0    -16.5    -28.4   11.5  2.06        3       13
#> log_lik[2]     -49.3    -18.5    -13.8    -26.8   13.5  2.06        3       13
#> log_lik[3]      -3.7     -3.6     -3.4     -3.6    0.1  2.06        4       13
#> log_lik[4]     -10.6     -5.3     -4.4     -6.7    2.4  2.06        3       13
#> log_lik[5]    -145.9    -63.1    -45.9    -84.1   37.1  2.06        3       13
#> log_lik[6]     -72.8    -23.3    -15.6    -36.5   21.5  2.06        3       13
#> log_lik[7]     -10.6     -6.0     -4.8     -7.2    2.2  2.06        3       13
#> log_lik[8]     -22.7     -8.1     -5.8    -11.9    6.4  2.06        3       13
#> log_lik[9]      -6.5     -4.6     -4.2     -5.0    0.9  2.06        3       13
#> log_lik[10]     -4.0     -3.6     -3.3     -3.6    0.3  2.06        4       13
#> log_lik[11]     -3.8     -3.7     -3.5     -3.7    0.1  2.06        4       13
#> log_lik[12]     -3.6     -3.5     -3.5     -3.5    0.1  2.06        3       13
#> log_lik[13]     -7.5     -4.8     -4.5     -5.6    1.2  2.06        3       13
#> log_lik[14]    -57.3    -18.1    -12.8    -28.8   16.8  2.06        3       13
#> log_lik[15]     -7.2     -4.2     -3.9     -5.0    1.2  2.06        3       13
#> log_lik[16]     -5.4     -3.8     -3.8     -4.3    0.6  2.06        4       13
#> log_lik[17]   -166.1    -76.8    -59.6   -100.2   39.6  2.06        3       13
#> log_lik[18]    -34.0    -12.9    -11.0    -18.8    8.8  2.06        4       13
#> log_lik[19]    -87.5    -24.3    -13.5    -40.8   27.7  2.06        3       13
#> log_lik[20]    -11.9     -6.4     -5.2     -7.8    2.5  2.06        3       13
#> log_lik[21]   -151.0    -70.0    -54.1    -91.0   35.7  2.06        3       13
#> log_lik[22]    -24.2    -16.7    -13.5    -18.2    3.8  2.06        3       13
#> log_lik[23]    -23.6     -7.9     -5.5    -12.0    6.8  2.06        3       13
#> log_lik[24]    -19.3     -8.2     -6.0    -11.0    5.0  2.06        3       13
#> log_lik[25]     -7.5     -4.9     -4.4     -5.6    1.2  2.06        3       13
#> log_lik[26]   -201.0    -65.1    -45.2   -103.0   59.6  2.06        3       13
#> log_lik[27]    -26.3     -8.3     -5.9    -13.1    7.7  2.06        3       13
#> log_lik[28]     -7.9     -4.2     -3.9     -5.3    1.6  2.06        3       13
#> log_lik[29]   -100.3    -40.5    -29.7    -56.7   26.9  2.06        3       13
#> log_lik[30]    -28.2     -5.6     -4.1    -12.3    9.5  2.06        3       13
#> log_lik[31]    -13.0     -7.5     -5.7     -8.8    2.7  2.06        3       13
#> log_lik[32]    -14.4     -5.7     -4.6     -8.1    3.8  2.06        3       13
#> log_lik[33]    -82.4    -32.2    -23.9    -46.3   22.4  2.06        3       13
#> log_lik[34]   -264.1    -82.8    -55.4   -134.0   80.2  2.06        3       13
#> log_lik[35]     -7.3     -4.2     -3.9     -5.0    1.3  2.06        3       13
#> log_lik[36]    -22.3     -7.2     -5.2    -11.4    6.6  2.06        3       13
#> log_lik[37]    -11.7     -5.9     -5.2     -7.9    2.6  2.06        3       13
#> log_lik[38]   -262.0    -90.7    -66.2   -139.9   75.3  2.06        3       13
#> log_lik[39]    -29.6     -9.8     -6.7    -15.0    8.6  2.06        3       13
#> log_lik[40]     -9.9     -4.6     -4.0     -6.1    2.3  2.06        3       13
#> log_lik[41]    -14.5     -7.1     -5.8     -9.4    3.4  2.06        3       13
#> log_lik[42]    -59.9    -18.9    -14.1    -31.3   17.9  2.06        3       13
#> log_lik[43]     -4.7     -3.8     -3.7     -4.0    0.4  2.06        3       13
#> log_lik[44]     -6.0     -3.9     -3.8     -4.5    0.9  2.06        3       13
#> log_lik[45]    -17.7     -8.5     -6.8    -11.3    4.2  2.06        3       13
#> log_lik[46]    -11.0     -9.3     -8.8     -9.7    0.8  0.94        8       13
#> log_lik[47]    -14.6     -7.0     -5.3     -9.0    3.4  2.06        3       13
#> log_lik[48]     -3.6     -3.5     -3.4     -3.5    0.1  2.06        3       13
#> log_lik[49]    -46.7    -24.6    -19.6    -29.3   10.0  2.06        3       13
#> log_lik[50]    -32.5    -15.6    -11.5    -19.1    7.4  2.06        3       13
#> log_lik[51]     -4.4     -3.9     -3.8     -4.1    0.3  2.06        3       13
#> log_lik[52]     -9.8     -5.4     -4.5     -6.4    1.9  2.06        3       13
#> log_lik[53]    -59.1    -25.9    -20.6    -36.0   14.8  2.06        3       13
#> log_lik[54]     -5.4     -4.6     -4.3     -4.7    0.4  1.00        8       13
#> log_lik[55]    -24.9     -9.1     -6.2    -13.2    6.9  2.06        3       13
#> log_lik[56]     -6.7     -4.4     -4.1     -5.1    1.0  2.06        3       13
#> log_lik[57]    -24.0    -12.4    -10.8    -16.3    5.3  2.06        3       13
#> log_lik[58]    -36.8    -16.4    -11.7    -20.7    8.9  2.06        3       13
#> log_lik[59]    -27.7     -9.6     -6.4    -14.4    7.9  2.06        3       13
#> log_lik[60]     -3.7     -3.6     -3.4     -3.6    0.1  2.06        3       13
#> log_lik[61]    -18.7    -10.2     -8.2    -11.8    3.7  2.06        3       13
#> log_lik[62]    -36.8    -13.3     -8.3    -18.2   10.0  2.06        3       13
#> log_lik[63]     -3.6     -3.5     -3.2     -3.4    0.2  2.06        3       13
#> log_lik[64]     -6.2     -4.2     -3.9     -4.6    0.9  2.06        3       13
#> log_lik[65]   -219.8    -96.5    -70.4   -126.3   54.6  2.06        3       13
#> log_lik[66]   -276.2    -97.6    -60.2   -140.8   78.6  2.06        3       13
#> log_lik[67]     -4.1     -4.0     -3.9     -4.0    0.1  1.71        4       13
#> log_lik[68]    -38.8    -11.9     -7.2    -18.6   11.8  2.06        3       13
#> log_lik[69]   -100.2    -43.9    -32.9    -57.7   24.7  2.06        3       13
#> log_lik[70]     -4.8     -3.6     -3.3     -3.9    0.6  1.03        6       13
#> log_lik[71]    -26.1    -11.1     -8.0    -15.1    6.9  2.06        3       13
#> log_lik[72]    -10.9     -5.3     -4.4     -6.6    2.4  2.06        3       13
#> log_lik[73]    -11.2     -7.6     -7.0     -8.8    1.7  2.06        3       13
#> log_lik[74]    -34.4    -13.8     -9.3    -18.1    8.9  2.06        3       13
#> log_lik[75]    -17.9     -7.1     -5.1     -9.7    4.7  2.06        3       13
#> log_lik[76]     -3.7     -3.6     -3.1     -3.5    0.2  2.06        3       13
#> log_lik[77]    -68.3    -33.2    -26.6    -43.4   16.0  2.06        3       13
#> log_lik[78]     -4.0     -3.6     -3.1     -3.6    0.3  2.06        3       13
#> log_lik[79]    -21.2     -7.8     -5.4    -11.3    5.9  2.06        3       13
#> log_lik[80]     -8.7     -5.2     -4.6     -6.2    1.6  2.06        3       13
#> xstar[1,1]      -2.6     -1.4      0.5     -1.2    1.1  0.92       13       13
#> xstar[2,1]      -0.6     -0.1      1.5      0.2    0.8  1.38        9       13
#> sigma[1]         8.6     12.9     14.9     11.9    2.4  2.06        3       13
#> lp__        -15937.4 -12945.7 -12007.7 -13680.6 1464.3  2.06        3       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).
fitted <- dfa_fitted(m)
# }