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.4898 1.71239 0.0382903 0.157654
#> phi 0.9747 0.02213 0.0004948 0.002242
#> sigma 0.2532 0.08342 0.0018653 0.010993
#>
#> 2. Quantiles for each variable:
#>
#> 2.5% 25% 50% 75% 97.5%
#> mu -14.0277 -10.8858 -10.2512 -9.7632 -8.4259
#> phi 0.9167 0.9659 0.9811 0.9898 0.9985
#> sigma 0.1229 0.1934 0.2430 0.2986 0.4430
#>
## 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.92296 0.68710 0.01536 0.03552
#>
#> 2. Quantiles for each variable:
#>
#> 2.5% 25% 50% 75% 97.5%
#> -13.23 -12.36 -11.93 -11.48 -10.55
#>
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.983 0.6494 0.014520 0.03631
#> h_2 -12.010 0.6129 0.013706 0.03479
#> h_3 -12.030 0.5861 0.013106 0.03408
#> h_4 -12.054 0.5639 0.012609 0.03226
#> h_5 -12.031 0.5341 0.011944 0.03060
#> h_6 -11.977 0.5006 0.011194 0.02737
#> h_7 -11.913 0.4687 0.010481 0.02520
#> h_8 -11.842 0.4296 0.009606 0.02294
#> h_9 -11.850 0.4388 0.009812 0.02168
#> h_10 -11.855 0.4506 0.010077 0.02148
#> h_11 -11.828 0.4434 0.009915 0.02160
#> h_12 -11.760 0.4086 0.009137 0.02107
#> h_13 -11.792 0.4289 0.009591 0.01961
#> h_14 -11.810 0.4378 0.009790 0.02028
#> h_15 -11.838 0.4621 0.010334 0.02123
#> h_16 -11.854 0.4885 0.010924 0.02355
#> h_17 -11.846 0.5036 0.011261 0.02489
#> h_18 -11.804 0.4901 0.010959 0.02252
#> h_19 -11.728 0.4735 0.010588 0.02195
#> h_20 -11.643 0.4577 0.010234 0.02192
#> h_21 -11.584 0.4657 0.010413 0.02207
#> h_22 -11.511 0.4583 0.010248 0.02131
#> h_23 -11.418 0.4549 0.010172 0.02076
#> h_24 -11.354 0.4502 0.010067 0.02043
#> h_25 -11.270 0.4380 0.009795 0.01970
#> [ reached 'max' / getOption("max.print") -- omitted 125 rows ]
#>
#> 2. Quantiles for each variable:
#>
#> 2.5% 25% 50% 75% 97.5%
#> h_1 -13.227 -12.413 -11.977 -11.578 -10.694
#> h_2 -13.173 -12.416 -12.015 -11.620 -10.773
#> h_3 -13.176 -12.420 -12.024 -11.656 -10.808
#> h_4 -13.182 -12.414 -12.036 -11.697 -10.938
#> h_5 -13.090 -12.371 -12.038 -11.691 -10.932
#> h_6 -12.922 -12.306 -11.975 -11.661 -10.937
#> h_7 -12.817 -12.225 -11.927 -11.618 -10.960
#> h_8 -12.650 -12.134 -11.871 -11.578 -10.920
#> h_9 -12.665 -12.141 -11.868 -11.559 -10.965
#> h_10 -12.720 -12.167 -11.850 -11.545 -10.971
#> h_11 -12.694 -12.111 -11.839 -11.534 -10.917
#> h_12 -12.552 -12.041 -11.775 -11.503 -10.880
#> h_13 -12.626 -12.073 -11.797 -11.532 -10.861
#> h_14 -12.658 -12.088 -11.810 -11.532 -10.931
#> h_15 -12.769 -12.134 -11.830 -11.539 -10.913
#> h_16 -12.825 -12.162 -11.861 -11.530 -10.895
#> h_17 -12.858 -12.155 -11.845 -11.515 -10.866
#> h_18 -12.801 -12.123 -11.803 -11.469 -10.873
#> h_19 -12.649 -12.059 -11.722 -11.410 -10.793
#> h_20 -12.537 -11.946 -11.646 -11.349 -10.715
#> [ reached 'max' / 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.002636 0.0009051 2.024e-05 4.894e-05
#> h_2 0.002587 0.0008347 1.867e-05 4.642e-05
#> h_3 0.002550 0.0007783 1.740e-05 4.231e-05
#> h_4 0.002510 0.0007196 1.609e-05 4.069e-05
#> h_5 0.002530 0.0006881 1.539e-05 3.821e-05
#> h_6 0.002588 0.0006642 1.485e-05 3.590e-05
#> h_7 0.002661 0.0006414 1.434e-05 3.395e-05
#> h_8 0.002746 0.0006130 1.371e-05 3.200e-05
#> h_9 0.002737 0.0006176 1.381e-05 3.012e-05
#> h_10 0.002734 0.0006232 1.394e-05 2.951e-05
#> h_11 0.002769 0.0006286 1.406e-05 3.020e-05
#> h_12 0.002854 0.0006056 1.354e-05 3.123e-05
#> h_13 0.002816 0.0006261 1.400e-05 2.817e-05
#> h_14 0.002792 0.0006207 1.388e-05 2.841e-05
#> h_15 0.002760 0.0006439 1.440e-05 2.940e-05
#> h_16 0.002747 0.0006782 1.517e-05 3.283e-05
#> h_17 0.002763 0.0006974 1.559e-05 3.345e-05
#> h_18 0.002817 0.0006956 1.555e-05 3.258e-05
#> h_19 0.002921 0.0007062 1.579e-05 3.259e-05
#> h_20 0.003042 0.0007160 1.601e-05 3.380e-05
#> h_21 0.003137 0.0007548 1.688e-05 3.528e-05
#> h_22 0.003250 0.0007630 1.706e-05 3.525e-05
#> h_23 0.003403 0.0007917 1.770e-05 3.762e-05
#> h_24 0.003513 0.0008163 1.825e-05 3.699e-05
#> h_25 0.003659 0.0008335 1.864e-05 3.603e-05
#> [ reached 'max' / getOption("max.print") -- omitted 125 rows ]
#>
#> 2. Quantiles for each variable:
#>
#> 2.5% 25% 50% 75% 97.5%
#> h_1 0.001342 0.002016 0.002507 0.003061 0.004762
#> h_2 0.001379 0.002013 0.002461 0.002997 0.004578
#> h_3 0.001377 0.002009 0.002449 0.002944 0.004498
#> h_4 0.001373 0.002015 0.002434 0.002884 0.004216
#> h_5 0.001437 0.002059 0.002432 0.002893 0.004227
#> h_6 0.001563 0.002127 0.002510 0.002937 0.004218
#> h_7 0.001647 0.002215 0.002571 0.003000 0.004170
#> h_8 0.001791 0.002318 0.002643 0.003061 0.004254
#> h_9 0.001778 0.002310 0.002648 0.003090 0.004159
#> h_10 0.001730 0.002280 0.002671 0.003111 0.004147
#> h_11 0.001752 0.002346 0.002686 0.003129 0.004259
#> h_12 0.001881 0.002428 0.002774 0.003179 0.004339
#> h_13 0.001812 0.002390 0.002744 0.003132 0.004381
#> h_14 0.001783 0.002372 0.002726 0.003132 0.004231
#> h_15 0.001688 0.002319 0.002699 0.003122 0.004269
#> h_16 0.001641 0.002286 0.002657 0.003135 0.004307
#> h_17 0.001614 0.002294 0.002679 0.003159 0.004371
#> h_18 0.001661 0.002331 0.002735 0.003232 0.004355
#> h_19 0.001792 0.002406 0.002848 0.003330 0.004532
#> h_20 0.001895 0.002547 0.002958 0.003433 0.004712
#> [ reached 'max' / 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.862238e-04 -5.702350e-02 7.356845e-02
#> [2,] 2.706937e-04 -8.781444e-02 -9.574906e-03
#> [3,] 5.784233e-04 -1.150716e-01 1.571796e-01
#> [4,] 5.051686e-04 -8.108691e-03 7.761863e-02
#> [5,] 1.087176e-03 -2.580759e-02 1.471974e-01
#> [6,] 6.194959e-04 -4.104623e-02 1.111823e-01
#> [7,] -5.789996e-05 -3.719389e-02 2.043801e-01
#> [8,] 3.749779e-04 -1.138665e-01 1.216214e-02
#> [9,] 2.586352e-04 -6.029721e-02 -9.700418e-02
#> [10,] -2.494809e-04 -6.500876e-02 6.405529e-02
#> [11,] 4.884428e-04 -1.200509e-01 1.498992e-01
#> [12,] 1.398980e-03 2.360988e-02 1.035168e-01
#> [13,] 5.367575e-04 -1.719697e-01 2.821907e-02
#> [14,] 1.116306e-03 -1.633374e-01 -5.946363e-02
#> [15,] 4.704157e-04 -1.202104e-01 8.724037e-02
#> [16,] 3.740577e-04 -1.776900e-01 1.672956e-01
#> [17,] 7.758820e-04 -1.575835e-02 1.249353e-01
#> [18,] 7.229569e-04 -1.145821e-01 9.129884e-02
#> [19,] 8.159391e-04 -1.496091e-01 2.547755e-02
#> [20,] -1.703581e-04 -1.645239e-01 -3.763863e-02
#> [21,] 4.358901e-04 -3.468730e-02 2.120595e-01
#> [22,] 7.982163e-04 -3.043565e-02 8.785245e-02
#> [23,] 4.894901e-04 1.330781e-02 3.099245e-02
#> [24,] 1.272378e-03 1.250871e-03 1.964551e-02
#> [25,] 8.574966e-04 -1.455601e-01 -3.297104e-02
#> [26,] 6.062521e-04 -9.235093e-02 -1.713279e-02
#> [27,] -4.810584e-05 5.954730e-03 -3.560951e-02
#> [28,] 3.671400e-04 -9.952185e-02 1.033242e-01
#> [29,] 5.960115e-04 -2.769101e-01 1.345330e-01
#> [30,] 6.519366e-04 -1.421516e-01 7.788255e-02
#> [31,] -4.311227e-05 -1.638834e-01 3.624852e-02
#> [32,] -1.057146e-03 -1.731765e-01 -5.146028e-02
#> [33,] 2.456403e-04 -8.339688e-02 -1.817521e-01
#> [ reached 'max' / 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
#> [1,] 1.2873439 0.8845598 0.9347552 1.1389940 0.8540759 1.5357846
#> tau_7 tau_8 tau_9 tau_10 tau_11 tau_12
#> [1,] 0.9945188 0.7423591 1.1116120 0.8398885 0.5680538 0.7407751
#> tau_13 tau_14 tau_15 tau_16 tau_17 tau_18
#> [1,] 0.9863469 0.7966529 0.8728662 0.7993353 1.1375862 0.9047032
#> tau_19 tau_20 tau_21 tau_22 tau_23 tau_24
#> [1,] 0.8695440 1.2086208 1.8352121 0.6930041 1.2183784 0.5483596
#> tau_25 tau_26 tau_27 tau_28 tau_29 tau_30 tau_31
#> [1,] 1.2586343 0.8244113 0.8191778 1.6948834 1.5229384 0.8771510 1.5116887
#> tau_32 tau_33 tau_34 tau_35 tau_36 tau_37
#> [1,] 0.6376479 1.3022743 1.1330049 0.9762348 0.7274270 0.5842005
#> tau_38 tau_39 tau_40 tau_41 tau_42 tau_43
#> [1,] 1.0818724 0.8414652 1.4532020 1.1343277 1.2352227 0.8648788
#> tau_44 tau_45 tau_46 tau_47 tau_48 tau_49
#> [1,] 0.8680254 1.1267560 1.0601183 1.3167071 0.9096682 0.9285617
#> tau_50 tau_51 tau_52 tau_53 tau_54 tau_55
#> [1,] 1.2192842 0.7985206 0.7683481 0.5968532 1.1916593 1.3708888
#> tau_56 tau_57 tau_58 tau_59 tau_60 tau_61
#> [1,] 0.7250836 0.7367753 1.0323109 1.2177284 0.6856417 1.0028624
#> tau_62 tau_63 tau_64 tau_65 tau_66 tau_67 tau_68
#> [1,] 0.7769142 1.0475745 1.3413411 1.3783098 0.7660665 0.7502320 0.6069064
#> tau_69 tau_70 tau_71 tau_72 tau_73 tau_74
#> [1,] 0.7458386 0.9218300 0.6278996 0.9106958 0.7290495 1.0073841
#> tau_75 tau_76 tau_77 tau_78 tau_79 tau_80
#> [1,] 1.0210840 0.7115080 1.1110911 0.8054689 0.9020869 1.0497858
#> tau_81 tau_82 tau_83 tau_84 tau_85 tau_86
#> [1,] 1.3186940 0.8085622 0.9387691 0.7922299 0.7931344 1.3094292
#> tau_87 tau_88 tau_89 tau_90 tau_91 tau_92
#> [1,] 1.3279687 1.0671493 1.1769948 1.0850941 1.5453500 0.7818742
#> tau_93 tau_94 tau_95 tau_96 tau_97 tau_98
#> [1,] 1.0941445 0.6840975 1.5572700 0.9852929 1.0534845 1.2148033
#> tau_99 tau_100
#> [1,] 0.7084779 1.9470033
#> [ reached 'max' / getOption("max.print") -- omitted 19999 rows and 48 columns ]
## 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)]
# }