Bayesian sampling of mixture autoregressive models
bayes_mixAR.Rd
Samples parameters of a mixture autoregressive model from respective posterior distributions.
Arguments
- y
a time series (currently a numeric vector).
- model
an object of class
MixAR
. Currently only handlesMixARGaussian
objects.- fix_shift
should
shift
be kept fixed? IfFALSE
(default)shift
is sampled.- a, c
numeric hyperparameters, default values are from Richardson and Green (1997) .
- tau
numeric
vector of length g, the number of components in the mixture. Tuning parameter for M-H move in updating AR parameters. Iflength(tau)
is 1, same tuning parameter is taken for all components.- nsim
numeric
, the number of iterations.- burnin
numeric
, the number of iterations taken as burn-in period.
Value
a list with following elements:
- mix_weights
a
g
columns matrix with samples from the posterior distributions of the mixing weights.- scale
a
g
columns matrix with samples from posterior distributions of scale parameters.- precision
a
g
columns matrix with samples from posterior distributions of precision parameters, defined as1 / (scale ^ 2)
.- shift
a
g
columns matrix with samples from posterior distributions of shift parameters, namely phi_k0.- mu
a
g
columns matrix with samples from posterior distributions of component means, calculated asphi_k0 / (1 - phi_k1 - phi_k2 - ...)
.- ARcoeff
a list which elements are matrices, one for each AR component in the mixture.
- acc_rate
numeric
vector, the acceptance rate for M-H moves.- n_samp
the sample size, calculated as
nsim - burnin
.- LatentZ
the latest Z variables drawn (for utility only).
- n_comp
the number of components in the mixture.
- fix_shift
same as input, whether the shift parameter was kept fixed or not.
References
Richardson S, Green PJ (1997). “On Bayesian Analysis of Mixtures with an Unknown Number of Components.” J. R. Stat. Soc., Ser. B, Stat. Methodol. , 59(4), 731-792.
Ravagli D, Boshnakov GN (2020). “Bayesian analysis of mixture autoregressive models covering the complete parameter space.” 2006.11041, https://arxiv.org/abs/2006.11041.
Examples
prob <- c(0.5, 0.5)
sigma <- c(1, 2)
ar <- list(-0.5, 1)
model <- new("MixARGaussian", prob = prob, scale = sigma, arcoef = ar)
## MAR(1,1) model
y <- mixAR_sim(model, 300, rep(0, max(model@order)))
bayes_mixAR(y, model, fix_shift = FALSE, tau = c(.15,.25), nsim = 20, burnin = 10)
#> $mix_weights
#> [,1] [,2]
#> [1,] 0.5859404 0.4140596
#> [2,] 0.5675420 0.4324580
#> [3,] 0.6090409 0.3909591
#> [4,] 0.5816917 0.4183083
#> [5,] 0.5090090 0.4909910
#> [6,] 0.4638817 0.5361183
#> [7,] 0.4745710 0.5254290
#> [8,] 0.5371336 0.4628664
#> [9,] 0.5879339 0.4120661
#> [10,] 0.5532978 0.4467022
#>
#> $scale
#> [,1] [,2]
#> [1,] 1.1431564 2.074092
#> [2,] 1.0450437 2.314067
#> [3,] 1.0833460 1.938325
#> [4,] 1.0272325 1.843347
#> [5,] 1.0229076 2.113068
#> [6,] 1.0677279 1.984406
#> [7,] 0.9103989 2.082002
#> [8,] 0.9609276 2.259794
#> [9,] 1.1051917 2.143391
#> [10,] 1.1997655 2.147962
#>
#> $precision
#> [,1] [,2]
#> [1,] 0.7652242 0.2324578
#> [2,] 0.9156534 0.1867446
#> [3,] 0.8520510 0.2661625
#> [4,] 0.9476817 0.2942969
#> [5,] 0.9557124 0.2239614
#> [6,] 0.8771600 0.2539446
#> [7,] 1.2065256 0.2306948
#> [8,] 1.0829756 0.1958223
#> [9,] 0.8186999 0.2176694
#> [10,] 0.6947160 0.2167438
#>
#> $shift
#> [,1] [,2]
#> [1,] -0.17388804 -0.33229027
#> [2,] 0.07111309 -0.19669854
#> [3,] 0.04899561 -0.20119328
#> [4,] -0.02118783 -0.36544546
#> [5,] -0.08636606 -0.33550322
#> [6,] -0.07308396 -0.16964398
#> [7,] -0.05537787 -0.35371554
#> [8,] -0.13936048 -0.04630361
#> [9,] -0.05377540 -0.23745943
#> [10,] -0.05190417 -0.07954147
#>
#> $mu
#> [,1] [,2]
#> [1,] -0.11596246 3.1612893
#> [2,] 0.04742389 1.2848873
#> [3,] 0.03267419 1.3142482
#> [4,] -0.01412974 2.3871872
#> [5,] -0.05759580 2.1915965
#> [6,] -0.04873823 1.1081598
#> [7,] -0.03693039 2.3105643
#> [8,] -0.09293672 0.3024675
#> [9,] -0.03586174 1.5511483
#> [10,] -0.03461385 0.5195861
#>
#> $ARcoeff
#> $ARcoeff$Component_1
#> [,1]
#> [1,] -0.4995202
#> [2,] -0.4995202
#> [3,] -0.4995202
#> [4,] -0.4995202
#> [5,] -0.4995202
#> [6,] -0.4995202
#> [7,] -0.4995202
#> [8,] -0.4995202
#> [9,] -0.4995202
#> [10,] -0.4158659
#>
#> $ARcoeff$Component_2
#> [,1]
#> [1,] 1.153086
#> [2,] 1.153086
#> [3,] 1.153086
#> [4,] 1.153086
#> [5,] 1.153086
#> [6,] 1.153086
#> [7,] 1.153086
#> [8,] 1.153086
#> [9,] 1.153086
#> [10,] 1.153086
#>
#>
#> $acc_rate
#> [1] 0.1 0.1
#>
#> $n_samp
#> [1] 10
#>
#> $LatentZ
#> latent Z 1 latent Z 2
#> [1,] 0 1
#> [2,] 0 1
#> [3,] 0 1
#> [4,] 0 1
#> [5,] 1 0
#> [6,] 1 0
#> [7,] 0 1
#> [8,] 0 1
#> [9,] 1 0
#> [10,] 1 0
#> [11,] 0 1
#> [12,] 1 0
#> [13,] 1 0
#> [14,] 1 0
#> [15,] 0 1
#> [16,] 1 0
#> [17,] 0 1
#> [18,] 1 0
#> [19,] 0 1
#> [20,] 0 1
#> [21,] 1 0
#> [22,] 1 0
#> [23,] 0 1
#> [24,] 1 0
#> [25,] 1 0
#> [26,] 0 1
#> [27,] 1 0
#> [28,] 0 1
#> [29,] 0 1
#> [30,] 1 0
#> [31,] 1 0
#> [32,] 1 0
#> [33,] 0 1
#> [34,] 1 0
#> [35,] 1 0
#> [36,] 1 0
#> [37,] 0 1
#> [38,] 1 0
#> [39,] 1 0
#> [40,] 1 0
#> [41,] 1 0
#> [42,] 1 0
#> [43,] 1 0
#> [44,] 0 1
#> [45,] 0 1
#> [46,] 1 0
#> [47,] 1 0
#> [48,] 0 1
#> [49,] 1 0
#> [50,] 0 1
#> [51,] 1 0
#> [52,] 0 1
#> [53,] 1 0
#> [54,] 1 0
#> [55,] 1 0
#> [56,] 1 0
#> [57,] 0 1
#> [58,] 0 1
#> [59,] 0 1
#> [60,] 1 0
#> [61,] 0 1
#> [62,] 1 0
#> [63,] 0 1
#> [64,] 1 0
#> [65,] 0 1
#> [66,] 0 1
#> [67,] 1 0
#> [68,] 0 1
#> [69,] 1 0
#> [70,] 0 1
#> [71,] 1 0
#> [72,] 1 0
#> [73,] 0 1
#> [74,] 0 1
#> [75,] 0 1
#> [76,] 1 0
#> [77,] 1 0
#> [78,] 0 1
#> [79,] 0 1
#> [80,] 1 0
#> [81,] 0 1
#> [82,] 0 1
#> [83,] 0 1
#> [84,] 1 0
#> [85,] 0 1
#> [86,] 1 0
#> [87,] 0 1
#> [88,] 0 1
#> [89,] 1 0
#> [90,] 1 0
#> [91,] 1 0
#> [92,] 1 0
#> [93,] 0 1
#> [94,] 1 0
#> [95,] 0 1
#> [96,] 0 1
#> [97,] 1 0
#> [98,] 1 0
#> [99,] 1 0
#> [100,] 0 1
#> [101,] 0 1
#> [102,] 0 1
#> [103,] 0 1
#> [104,] 0 1
#> [105,] 1 0
#> [106,] 0 1
#> [107,] 0 1
#> [108,] 0 1
#> [109,] 0 1
#> [110,] 1 0
#> [111,] 1 0
#> [112,] 1 0
#> [113,] 1 0
#> [114,] 1 0
#> [115,] 0 1
#> [116,] 0 1
#> [117,] 1 0
#> [118,] 1 0
#> [119,] 1 0
#> [120,] 1 0
#> [121,] 1 0
#> [122,] 0 1
#> [123,] 1 0
#> [124,] 0 1
#> [125,] 0 1
#> [126,] 1 0
#> [127,] 1 0
#> [128,] 0 1
#> [129,] 0 1
#> [130,] 1 0
#> [131,] 0 1
#> [132,] 0 1
#> [133,] 0 1
#> [134,] 1 0
#> [135,] 0 1
#> [136,] 1 0
#> [137,] 1 0
#> [138,] 0 1
#> [139,] 1 0
#> [140,] 1 0
#> [141,] 1 0
#> [142,] 0 1
#> [143,] 0 1
#> [144,] 1 0
#> [145,] 0 1
#> [146,] 1 0
#> [147,] 0 1
#> [148,] 1 0
#> [149,] 1 0
#> [150,] 1 0
#> [151,] 0 1
#> [152,] 0 1
#> [153,] 1 0
#> [154,] 1 0
#> [155,] 0 1
#> [156,] 0 1
#> [157,] 0 1
#> [158,] 1 0
#> [159,] 1 0
#> [160,] 0 1
#> [161,] 1 0
#> [162,] 1 0
#> [163,] 1 0
#> [164,] 1 0
#> [165,] 0 1
#> [166,] 1 0
#> [167,] 1 0
#> [168,] 1 0
#> [169,] 1 0
#> [170,] 0 1
#> [171,] 1 0
#> [172,] 1 0
#> [173,] 1 0
#> [174,] 1 0
#> [175,] 0 1
#> [176,] 1 0
#> [177,] 0 1
#> [178,] 1 0
#> [179,] 1 0
#> [180,] 1 0
#> [181,] 0 1
#> [182,] 0 1
#> [183,] 1 0
#> [184,] 1 0
#> [185,] 0 1
#> [186,] 1 0
#> [187,] 0 1
#> [188,] 1 0
#> [189,] 0 1
#> [190,] 0 1
#> [191,] 0 1
#> [192,] 1 0
#> [193,] 1 0
#> [194,] 1 0
#> [195,] 1 0
#> [196,] 0 1
#> [197,] 0 1
#> [198,] 1 0
#> [199,] 1 0
#> [200,] 1 0
#> [201,] 0 1
#> [202,] 1 0
#> [203,] 1 0
#> [204,] 1 0
#> [205,] 0 1
#> [206,] 1 0
#> [207,] 1 0
#> [208,] 1 0
#> [209,] 1 0
#> [210,] 1 0
#> [211,] 0 1
#> [212,] 0 1
#> [213,] 1 0
#> [214,] 1 0
#> [215,] 0 1
#> [216,] 0 1
#> [217,] 1 0
#> [218,] 1 0
#> [219,] 1 0
#> [220,] 1 0
#> [221,] 0 1
#> [222,] 1 0
#> [223,] 1 0
#> [224,] 0 1
#> [225,] 1 0
#> [226,] 0 1
#> [227,] 1 0
#> [228,] 0 1
#> [229,] 1 0
#> [230,] 0 1
#> [231,] 0 1
#> [232,] 1 0
#> [233,] 0 1
#> [234,] 1 0
#> [235,] 0 1
#> [236,] 0 1
#> [237,] 0 1
#> [238,] 1 0
#> [239,] 1 0
#> [240,] 0 1
#> [241,] 0 1
#> [242,] 1 0
#> [243,] 1 0
#> [244,] 0 1
#> [245,] 1 0
#> [246,] 0 1
#> [247,] 0 1
#> [248,] 0 1
#> [249,] 0 1
#> [250,] 1 0
#> [251,] 0 1
#> [252,] 1 0
#> [253,] 1 0
#> [254,] 0 1
#> [255,] 0 1
#> [256,] 1 0
#> [257,] 1 0
#> [258,] 1 0
#> [259,] 0 1
#> [260,] 1 0
#> [261,] 1 0
#> [262,] 0 1
#> [263,] 1 0
#> [264,] 1 0
#> [265,] 1 0
#> [266,] 0 1
#> [267,] 0 1
#> [268,] 0 1
#> [269,] 0 1
#> [270,] 1 0
#> [271,] 1 0
#> [272,] 0 1
#> [273,] 0 1
#> [274,] 0 1
#> [275,] 1 0
#> [276,] 0 1
#> [277,] 1 0
#> [278,] 1 0
#> [279,] 0 1
#> [280,] 0 1
#> [281,] 1 0
#> [282,] 1 0
#> [283,] 0 1
#> [284,] 1 0
#> [285,] 1 0
#> [286,] 0 1
#> [287,] 1 0
#> [288,] 1 0
#> [289,] 0 1
#> [290,] 0 1
#> [291,] 0 1
#> [292,] 1 0
#> [293,] 0 1
#> [294,] 1 0
#> [295,] 1 0
#> [296,] 1 0
#> [297,] 1 0
#> [298,] 0 1
#> [299,] 1 0
#>
#> $ncomp
#> [1] 2
#>
#> $fix_shift
#> [1] FALSE
#>