Some simple extractors returning the corresponding element of an
svdraws
and svpredict
object.
para(x, chain = "concatenated")
latent0(x, chain = "concatenated")
latent(x, chain = "concatenated")
vola(x, chain = "concatenated")
svbeta(x, chain = "concatenated")
svtau(x, chain = "concatenated")
priors(x)
thinning(x)
runtime(x)
sampled_parameters(x)
predy(y, chain = "concatenated")
predlatent(y, chain = "concatenated")
predvola(y, chain = "concatenated")
The return value depends on the actual funtion.
extracts the parameter draws.
extracts the latent contemporaneous log-volatility draws.
extracts the latent initial log-volatility draws.
extracts the linear regression coefficient draws.
extracts the tau draws.
extracts standard deviation draws.
extracts the prior
parameters used and returns them in a prior_spec
object as generated by
specify_priors.
extracts the thinning parameters used and returns them in
a list
.
extracts the runtime and returns it as a
proc_time
object.
returns the names of time independent model
parameters that were actually sampled by svsample
.
extracts the predicted latent contemporaneous log-volatility draws.
extracts predicted standard deviation draws.
extracts the predicted observation draws.
Functions that have input parameter chain
return
an mcmc.list
object if chain=="all"
and
return an mcmc
object otherwise. If chain
is
an integer, then the specified chain is selected from
all chains. If chain
is "concatenated"
,
then all chains are merged into one mcmc
object.
# Simulate data
sim <- svsim(150)
# Draw from vanilla SV
draws <- svsample(sim, draws = 2000)
#> Extracted data vector from 'svsim'-object.
#> Done!
#> Summarizing posterior draws...
## Summarize all estimated parameter draws as a merged mcmc object
summary(para(draws)[, sampled_parameters(draws)])
#>
#> Iterations = 1001:3000
#> Thinning interval = 1
#> Number of chains = 1
#> Sample size per chain = 2000
#>
#> 1. Empirical mean and standard deviation for each variable,
#> plus standard error of the mean:
#>
#> Mean SD Naive SE Time-series SE
#> mu -10.1735 1.26156 0.028209 0.09454
#> phi 0.9715 0.02594 0.000580 0.00270
#> sigma 0.2545 0.09254 0.002069 0.01182
#>
#> 2. Quantiles for each variable:
#>
#> 2.5% 25% 50% 75% 97.5%
#> mu -12.5423 -10.7326 -10.2301 -9.7110 -7.7686
#> phi 0.9008 0.9630 0.9787 0.9893 0.9977
#> sigma 0.1255 0.1884 0.2376 0.3015 0.5012
#>
## Extract the draws as an mcmc.list object
params <- para(draws, chain = "all")[, sampled_parameters(draws)]
# \donttest{
options(max.print = 100)
## Further short examples
summary(latent0(draws))
#>
#> Iterations = 1001:3000
#> Thinning interval = 1
#> Number of chains = 1
#> Sample size per chain = 2000
#>
#> 1. Empirical mean and standard deviation for each variable,
#> plus standard error of the mean:
#>
#> Mean SD Naive SE Time-series SE
#> -11.70583 0.68071 0.01522 0.02964
#>
#> 2. Quantiles for each variable:
#>
#> 2.5% 25% 50% 75% 97.5%
#> -13.07 -12.16 -11.72 -11.26 -10.26
#>
summary(latent(draws))
#>
#> Iterations = 1001:3000
#> Thinning interval = 1
#> Number of chains = 1
#> Sample size per chain = 2000
#>
#> 1. Empirical mean and standard deviation for each variable,
#> plus standard error of the mean:
#>
#> Mean SD Naive SE Time-series SE
#> h_1 -11.755 0.6424 0.014363 0.02819
#> h_2 -11.757 0.5778 0.012920 0.02966
#> h_3 -11.801 0.5672 0.012683 0.02922
#> h_4 -11.821 0.5429 0.012140 0.02856
#> h_5 -11.835 0.5275 0.011795 0.02610
#> h_6 -11.841 0.5261 0.011764 0.02538
#> h_7 -11.815 0.5145 0.011505 0.02508
#> h_8 -11.759 0.4901 0.010959 0.02492
#> h_9 -11.698 0.4764 0.010652 0.02291
#> h_10 -11.628 0.4585 0.010251 0.02374
#> h_11 -11.638 0.4696 0.010501 0.02282
#> h_12 -11.640 0.4912 0.010983 0.02519
#> h_13 -11.624 0.4729 0.010575 0.02221
#> h_14 -11.582 0.4420 0.009883 0.02370
#> h_15 -11.621 0.4465 0.009984 0.02430
#> h_16 -11.645 0.4584 0.010250 0.02381
#> h_17 -11.687 0.4861 0.010870 0.02301
#> h_18 -11.697 0.5052 0.011297 0.02486
#> h_19 -11.670 0.5113 0.011434 0.02523
#> h_20 -11.639 0.4905 0.010967 0.02538
#> h_21 -11.562 0.4599 0.010284 0.02257
#> h_22 -11.493 0.4451 0.009952 0.02149
#> h_23 -11.439 0.4487 0.010032 0.02030
#> h_24 -11.382 0.4448 0.009946 0.02027
#> h_25 -11.315 0.4313 0.009644 0.01847
#> [ reached getOption("max.print") -- omitted 125 rows ]
#>
#> 2. Quantiles for each variable:
#>
#> 2.5% 25% 50% 75% 97.5%
#> h_1 -12.963 -12.174 -11.772 -11.330 -10.452
#> h_2 -12.839 -12.157 -11.777 -11.375 -10.556
#> h_3 -12.912 -12.178 -11.828 -11.424 -10.681
#> h_4 -12.854 -12.185 -11.837 -11.445 -10.693
#> h_5 -12.846 -12.199 -11.851 -11.476 -10.774
#> h_6 -12.881 -12.191 -11.855 -11.486 -10.795
#> h_7 -12.839 -12.155 -11.821 -11.490 -10.737
#> h_8 -12.675 -12.096 -11.785 -11.433 -10.705
#> h_9 -12.563 -12.014 -11.728 -11.396 -10.713
#> h_10 -12.463 -11.952 -11.641 -11.330 -10.694
#> h_11 -12.511 -11.951 -11.657 -11.349 -10.653
#> h_12 -12.558 -11.972 -11.655 -11.332 -10.607
#> h_13 -12.504 -11.949 -11.639 -11.326 -10.630
#> h_14 -12.389 -11.891 -11.600 -11.302 -10.660
#> h_15 -12.436 -11.925 -11.638 -11.331 -10.676
#> h_16 -12.514 -11.947 -11.653 -11.370 -10.685
#> h_17 -12.669 -12.003 -11.673 -11.371 -10.735
#> h_18 -12.746 -12.008 -11.680 -11.365 -10.711
#> h_19 -12.723 -11.989 -11.656 -11.327 -10.683
#> h_20 -12.630 -11.958 -11.631 -11.314 -10.703
#> [ reached getOption("max.print") -- omitted 130 rows ]
#>
summary(vola(draws))
#>
#> Iterations = 1001:3000
#> Thinning interval = 1
#> Number of chains = 1
#> Sample size per chain = 2000
#>
#> 1. Empirical mean and standard deviation for each variable,
#> plus standard error of the mean:
#>
#> Mean SD Naive SE Time-series SE
#> h_1 0.002952 0.0010012 2.239e-05 4.643e-05
#> h_2 0.002920 0.0008920 1.995e-05 4.462e-05
#> h_3 0.002852 0.0008461 1.892e-05 4.229e-05
#> h_4 0.002814 0.0007977 1.784e-05 3.955e-05
#> h_5 0.002788 0.0007572 1.693e-05 3.779e-05
#> h_6 0.002779 0.0007496 1.676e-05 3.523e-05
#> h_7 0.002811 0.0007464 1.669e-05 3.664e-05
#> h_8 0.002883 0.0007434 1.662e-05 3.749e-05
#> h_9 0.002968 0.0007461 1.668e-05 3.491e-05
#> h_10 0.003067 0.0007443 1.664e-05 3.786e-05
#> h_11 0.003056 0.0007635 1.707e-05 3.699e-05
#> h_12 0.003061 0.0008027 1.795e-05 3.895e-05
#> h_13 0.003078 0.0007759 1.735e-05 3.603e-05
#> h_14 0.003133 0.0007380 1.650e-05 3.874e-05
#> h_15 0.003074 0.0007203 1.611e-05 3.908e-05
#> h_16 0.003040 0.0007243 1.619e-05 3.530e-05
#> h_17 0.002986 0.0007422 1.660e-05 3.464e-05
#> h_18 0.002976 0.0007520 1.681e-05 3.688e-05
#> h_19 0.003020 0.0007781 1.740e-05 3.700e-05
#> h_20 0.003060 0.0007570 1.693e-05 3.856e-05
#> h_21 0.003169 0.0007506 1.679e-05 3.611e-05
#> h_22 0.003274 0.0007390 1.653e-05 3.678e-05
#> h_23 0.003364 0.0007604 1.700e-05 3.313e-05
#> h_24 0.003460 0.0007736 1.730e-05 3.413e-05
#> h_25 0.003573 0.0007790 1.742e-05 3.379e-05
#> [ reached getOption("max.print") -- omitted 125 rows ]
#>
#> 2. Quantiles for each variable:
#>
#> 2.5% 25% 50% 75% 97.5%
#> h_1 0.001532 0.002272 0.002778 0.003465 0.005374
#> h_2 0.001630 0.002291 0.002772 0.003388 0.005103
#> h_3 0.001571 0.002267 0.002701 0.003307 0.004794
#> h_4 0.001617 0.002260 0.002689 0.003272 0.004765
#> h_5 0.001623 0.002244 0.002671 0.003221 0.004575
#> h_6 0.001595 0.002253 0.002666 0.003205 0.004528
#> h_7 0.001630 0.002293 0.002711 0.003200 0.004662
#> h_8 0.001769 0.002362 0.002760 0.003291 0.004736
#> h_9 0.001871 0.002461 0.002840 0.003353 0.004716
#> h_10 0.001967 0.002539 0.002966 0.003464 0.004762
#> h_11 0.001920 0.002540 0.002942 0.003432 0.004861
#> h_12 0.001875 0.002514 0.002946 0.003462 0.004975
#> h_13 0.001926 0.002543 0.002970 0.003473 0.004918
#> h_14 0.002041 0.002617 0.003027 0.003513 0.004844
#> h_15 0.001994 0.002574 0.002971 0.003463 0.004805
#> h_16 0.001917 0.002545 0.002949 0.003397 0.004785
#> h_17 0.001774 0.002475 0.002919 0.003394 0.004666
#> h_18 0.001707 0.002468 0.002908 0.003405 0.004721
#> h_19 0.001726 0.002493 0.002943 0.003471 0.004789
#> h_20 0.001809 0.002531 0.002981 0.003494 0.004742
#> [ reached getOption("max.print") -- omitted 130 rows ]
#>
sampled_parameters(draws)
#> [1] "mu" "phi" "sigma"
priors(draws)
#> Prior distributions:
#> mu ~ Normal(mean = 0, sd = 100)
#> (phi+1)/2 ~ Beta(a = 5, b = 1.5)
#> sigma^2 ~ Gamma(shape = 0.5, rate = 0.5)
#> nu ~ Infinity
#> rho ~ Constant(value = 0)
# Draw 3 independent chains from heavy-tailed and asymmetric SV with AR(2) structure
draws <- svsample(sim, draws = 20000, burnin = 3000,
designmatrix = "ar2",
priornu = 0.1, priorrho = c(4, 4),
n_chains = 3)
#> Extracted data vector from 'svsim'-object.
#> Done!
#> Summarizing posterior draws...
## Extract beta draws from the second chain
svbeta(draws, chain = 2)
#> Markov Chain Monte Carlo (MCMC) output:
#> Start = 3001
#> End = 23000
#> Thinning interval = 1
#> beta_0 beta_1 beta_2
#> [1,] -1.835178e-04 -1.120979e-02 4.073545e-02
#> [2,] 4.148540e-05 -5.066866e-02 8.009211e-02
#> [3,] -5.196587e-04 -1.997835e-01 4.673504e-02
#> [4,] 1.329294e-03 -1.731682e-01 1.230987e-01
#> [5,] 1.984911e-04 -1.374470e-01 7.925170e-02
#> [6,] 5.428358e-04 -9.557476e-03 6.146546e-02
#> [7,] 2.060094e-04 -2.698208e-02 1.185101e-01
#> [8,] -1.221926e-04 -5.384833e-02 6.654521e-02
#> [9,] -9.140010e-05 -9.239946e-02 7.098954e-02
#> [10,] 1.850759e-04 -1.505269e-01 -2.221765e-02
#> [11,] 6.048016e-04 6.807221e-02 7.100394e-02
#> [12,] 3.682454e-04 -1.467771e-01 8.561540e-02
#> [13,] 9.566055e-04 -7.858540e-02 1.761947e-01
#> [14,] 8.393958e-04 -1.785513e-01 1.350412e-01
#> [15,] 3.458005e-04 -3.487826e-02 -1.747002e-02
#> [16,] 4.458398e-04 -1.346423e-01 6.836923e-02
#> [17,] 2.246591e-04 -2.110208e-03 -2.196046e-02
#> [18,] 7.609698e-04 1.051702e-01 7.251100e-02
#> [19,] 8.991945e-04 -1.882426e-02 7.658594e-02
#> [20,] 7.291891e-04 -2.690092e-02 1.131462e-01
#> [21,] 7.285382e-04 3.663086e-02 1.043386e-01
#> [22,] 1.016769e-03 5.352064e-02 1.502019e-01
#> [23,] 3.978863e-04 -6.753226e-02 1.513274e-01
#> [24,] 2.069198e-04 1.166387e-02 -3.758726e-02
#> [25,] 4.716094e-04 -6.918426e-04 5.726342e-02
#> [26,] 9.779594e-04 -1.966106e-02 2.664880e-02
#> [27,] 1.070077e-03 -2.431025e-02 2.882986e-01
#> [28,] 8.362810e-04 -7.794652e-02 1.820190e-01
#> [29,] 1.120966e-05 -1.212942e-01 1.712368e-01
#> [30,] 5.441010e-04 -1.310116e-01 4.973769e-02
#> [31,] 4.857631e-04 2.076848e-02 1.169969e-01
#> [32,] 1.116344e-04 -3.792015e-02 1.279239e-01
#> [33,] 8.597014e-05 -3.040293e-02 8.578922e-02
#> [ reached getOption("max.print") -- omitted 19967 rows ]
## ... tau draws from all chains merged/concatenated together
svtau(draws)
#> Markov Chain Monte Carlo (MCMC) output:
#> Start = 3001
#> End = 23000
#> Thinning interval = 1
#> tau_1 tau_2 tau_3 tau_4 tau_5 tau_6
#> tau_7 tau_8 tau_9 tau_10 tau_11 tau_12
#> tau_13 tau_14 tau_15 tau_16 tau_17 tau_18
#> tau_19 tau_20 tau_21 tau_22 tau_23 tau_24
#> tau_25 tau_26 tau_27 tau_28 tau_29 tau_30
#> tau_31 tau_32 tau_33 tau_34 tau_35 tau_36
#> tau_37 tau_38 tau_39 tau_40 tau_41 tau_42
#> tau_43 tau_44 tau_45 tau_46 tau_47 tau_48
#> tau_49 tau_50 tau_51 tau_52 tau_53 tau_54
#> tau_55 tau_56 tau_57 tau_58 tau_59 tau_60
#> tau_61 tau_62 tau_63 tau_64 tau_65 tau_66
#> tau_67 tau_68 tau_69 tau_70 tau_71 tau_72
#> tau_73 tau_74 tau_75 tau_76 tau_77 tau_78
#> tau_79 tau_80 tau_81 tau_82 tau_83 tau_84
#> tau_85 tau_86 tau_87 tau_88 tau_89 tau_90
#> tau_91 tau_92 tau_93 tau_94 tau_95 tau_96
#> tau_97 tau_98 tau_99 tau_100 tau_101 tau_102
#> tau_103 tau_104 tau_105 tau_106 tau_107 tau_108
#> tau_109 tau_110 tau_111 tau_112 tau_113 tau_114
#> tau_115 tau_116 tau_117 tau_118 tau_119 tau_120
#> tau_121 tau_122 tau_123 tau_124 tau_125 tau_126
#> tau_127 tau_128 tau_129 tau_130 tau_131 tau_132
#> tau_133 tau_134 tau_135 tau_136 tau_137 tau_138
#> tau_139 tau_140 tau_141 tau_142 tau_143 tau_144
#> tau_145 tau_146 tau_147 tau_148
#> [ reached getOption("max.print") -- omitted 20000 rows ]
## Create a new svdraws object from the first and third chain
second_chain_excluded <- draws[c(1, 3)]
# Draw from the predictive distribution
pred <- predict(draws, steps = 2)
## Extract the predicted observations as an mcmc.list object
predicted_y <- predy(pred, chain = "all")
## ... the predicted standard deviations from the second chain
predicted_sd <- predvola(pred, chain = 2)
## Create a new svpredict object from the first and third chain
second_chain_excluded <- pred[c(1, 3)]
# }