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")

Arguments

x

svdraws object.

chain

optional either a positive integer or the string "concatenated" (default) or the string "all".

y

svpredict object.

Value

The return value depends on the actual funtion.

para(x, chain = "concatenated")

extracts the parameter draws.

latent(x, chain = "concatenated")

extracts the latent contemporaneous log-volatility draws.

latent0(x, chain = "concatenated")

extracts the latent initial log-volatility draws.

svbeta(x, chain = "concatenated")

extracts the linear regression coefficient draws.

svtau(x, chain = "concatenated")

extracts the tau draws.

vola(x, chain = "concatenated")

extracts standard deviation draws.

priors(x)

extracts the prior parameters used and returns them in a prior_spec object as generated by specify_priors.

thinning(x)

extracts the thinning parameters used and returns them in a list.

runtime(x)

extracts the runtime and returns it as a proc_time object.

sampled_parameters(x)

returns the names of time independent model parameters that were actually sampled by svsample.

predlatent(y, chain = "concatenated")

extracts the predicted latent contemporaneous log-volatility draws.

predvola(y, chain = "concatenated")

extracts predicted standard deviation draws.

predy(y, chain = "concatenated")

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.

Examples

# 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 'max' / 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 '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.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 'max' / 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 '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.010382e-03 -1.305901e-01  1.129224e-01
#>     [2,] -1.963763e-04 -9.623584e-02  9.314414e-02
#>     [3,]  3.463283e-04 -1.168315e-01  1.134246e-01
#>     [4,]  6.001777e-04 -2.076043e-01 -7.722329e-04
#>     [5,] -1.286909e-04 -2.213686e-01 -1.388705e-01
#>     [6,]  4.895227e-04 -1.983235e-01 -8.679033e-02
#>     [7,] -4.489424e-04 -2.505422e-02  8.002964e-02
#>     [8,]  1.512633e-04 -6.474043e-02  5.359761e-03
#>     [9,]  8.661908e-04 -1.357004e-01  1.689542e-01
#>    [10,]  3.660825e-04 -1.142553e-01  1.177508e-01
#>    [11,]  4.710699e-04 -3.310020e-02  8.106198e-02
#>    [12,] -3.341048e-05 -8.294801e-02 -1.551023e-02
#>    [13,] -2.757634e-05  3.466422e-02  1.813668e-01
#>    [14,] -1.523823e-04  5.171099e-02  8.830018e-02
#>    [15,] -4.984188e-04 -1.042746e-01  3.779181e-02
#>    [16,] -3.994322e-04 -4.923089e-02 -1.837484e-02
#>    [17,]  3.796274e-04  6.842401e-03  1.477681e-01
#>    [18,]  5.307687e-04 -7.063550e-02  1.695647e-01
#>    [19,]  5.256352e-04 -1.011070e-01  1.272851e-01
#>    [20,] -8.052598e-05 -1.593855e-02  3.715095e-02
#>    [21,] -2.781468e-04 -7.599851e-02  1.305111e-01
#>    [22,] -4.196321e-04 -1.083245e-01  3.259222e-02
#>    [23,] -1.840229e-04 -2.733832e-01  5.474935e-03
#>    [24,] -3.901093e-04 -1.257670e-01  1.128791e-01
#>    [25,] -2.593762e-04 -4.410597e-02  1.494210e-01
#>    [26,] -3.516463e-04  1.046024e-01  1.561641e-01
#>    [27,] -7.052887e-04 -1.907708e-02 -8.049868e-06
#>    [28,]  1.332053e-04 -1.929337e-01  2.104542e-02
#>    [29,] -2.632531e-04 -1.247064e-01 -6.908763e-02
#>    [30,]  2.633298e-04 -5.204536e-02 -8.000184e-03
#>    [31,]  5.784878e-05 -7.365038e-02  9.923094e-02
#>    [32,]  3.212865e-04 -5.564033e-03  1.343102e-01
#>    [33,]  8.067271e-04 -5.747759e-02  1.987301e-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.1867687 0.9486430 1.4126914 1.1085684 0.4923005  0.4783269
#>              tau_7      tau_8      tau_9    tau_10    tau_11     tau_12
#>     [1,] 1.1125283  1.1668627  0.7816256 0.8420614 0.6804849  0.9435526
#>             tau_13    tau_14    tau_15    tau_16    tau_17    tau_18     tau_19
#>     [1,] 1.1160392 0.6939695 0.9065651 0.9019785 0.5197409 0.6746696  1.5769449
#>              tau_20    tau_21    tau_22    tau_23    tau_24    tau_25
#>     [1,]  1.4477688 1.8612669 0.6492158 1.1245104 1.0925174 0.9821191
#>              tau_26     tau_27     tau_28    tau_29     tau_30    tau_31
#>     [1,]  0.9698278  0.9872564  0.8235348 0.7343372  1.0321727 1.2543687
#>             tau_32     tau_33     tau_34     tau_35     tau_36    tau_37
#>     [1,] 0.9944485  1.2886454  0.4663992  0.8411164  1.0937635 1.2042020
#>             tau_38    tau_39    tau_40     tau_41    tau_42    tau_43    tau_44
#>     [1,] 0.9620862 0.6347625 1.0708300  1.1726331 0.6242203 1.0654001 0.9922457
#>             tau_45     tau_46    tau_47    tau_48     tau_49    tau_50
#>     [1,] 0.9456640  0.6131284 1.4701267 1.3156766  1.2221738 0.8289488
#>             tau_51     tau_52    tau_53     tau_54    tau_55     tau_56
#>     [1,] 0.6235229  0.5507292 0.7933825  1.1273220 0.7661880  2.3463491
#>              tau_57    tau_58    tau_59    tau_60    tau_61    tau_62    tau_63
#>     [1,]  0.8943338 0.9825159 0.7643022 0.9015617 0.6417131 0.7174469 0.8109634
#>             tau_64    tau_65    tau_66    tau_67    tau_68    tau_69    tau_70
#>     [1,] 1.0708504 1.2955437 1.1558656 1.4832149 0.5401909 0.6913520 0.6160461
#>             tau_71    tau_72    tau_73    tau_74    tau_75    tau_76    tau_77
#>     [1,] 0.8391630 0.8143767 1.7905076 0.6698577 1.1012516 1.0712700 0.6594387
#>             tau_78    tau_79     tau_80     tau_81    tau_82    tau_83
#>     [1,] 1.0226071 1.0682346  2.3474336  0.6845409 1.2816217 0.9645335
#>             tau_84    tau_85     tau_86     tau_87    tau_88    tau_89
#>     [1,] 0.8480577 0.6346493  0.9483689  0.7318923 1.3427853 0.5672316
#>             tau_90    tau_91    tau_92     tau_93    tau_94    tau_95    tau_96
#>     [1,] 0.7271477 0.9512903 0.9811586  1.2867484 0.5915535 1.1738071 1.0920458
#>             tau_97    tau_98     tau_99   tau_100
#>     [1,] 1.1696127 0.8760347  1.0595801 0.7937838
#>  [ 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)]
# }