Bayesian sampling of mixture autoregressive models
bayes_mixAR.RdSamples 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 handlesMixARGaussianobjects.- fix_shift
should
shiftbe kept fixed? IfFALSE(default)shiftis sampled.- a, c
numeric hyperparameters, default values are from Richardson and Green (1997) .
- tau
numericvector 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
gcolumns matrix with samples from the posterior distributions of the mixing weights.- scale
a
gcolumns matrix with samples from posterior distributions of scale parameters.- precision
a
gcolumns matrix with samples from posterior distributions of precision parameters, defined as1 / (scale ^ 2).- shift
a
gcolumns matrix with samples from posterior distributions of shift parameters, namely phi_k0.- mu
a
gcolumns 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
numericvector, 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.4469353 0.5530647
#> [2,] 0.5077049 0.4922951
#> [3,] 0.5031994 0.4968006
#> [4,] 0.5146808 0.4853192
#> [5,] 0.4224212 0.5775788
#> [6,] 0.3797978 0.6202022
#> [7,] 0.4152256 0.5847744
#> [8,] 0.5289495 0.4710505
#> [9,] 0.5632558 0.4367442
#> [10,] 0.5535357 0.4464643
#>
#> $scale
#> [,1] [,2]
#> [1,] 0.9957309 1.727833
#> [2,] 0.8654635 1.888234
#> [3,] 0.9022960 2.046855
#> [4,] 0.8471184 2.007714
#> [5,] 0.8865657 1.896346
#> [6,] 0.9888646 1.558373
#> [7,] 1.0868707 1.748489
#> [8,] 1.0555062 1.899021
#> [9,] 0.9398628 1.767463
#> [10,] 0.9523629 1.872702
#>
#> $precision
#> [,1] [,2]
#> [1,] 1.0085932 0.3349627
#> [2,] 1.3350652 0.2804713
#> [3,] 1.2282928 0.2386853
#> [4,] 1.3935153 0.2480826
#> [5,] 1.2722666 0.2780768
#> [6,] 1.0226484 0.4117721
#> [7,] 0.8465337 0.3270953
#> [8,] 0.8975909 0.2772940
#> [9,] 1.1320642 0.3201101
#> [10,] 1.1025418 0.2851430
#>
#> $shift
#> [,1] [,2]
#> [1,] -0.05047451 0.0000000000
#> [2,] -0.18251981 0.0000000000
#> [3,] -0.13754283 0.0000000000
#> [4,] -0.16192461 0.0003015860
#> [5,] -0.06745231 -0.0026234814
#> [6,] -0.06167837 0.0015410389
#> [7,] -0.24232069 0.0008145325
#> [8,] -0.25325227 0.0270565855
#> [9,] -0.09345518 0.0547571828
#> [10,] -0.13722744 -0.0267399327
#>
#> $mu
#> [,1] [,2]
#> [1,] -0.03286227 -2.5872012
#> [2,] -0.11883254 0.6788446
#> [3,] -0.08954953 -2.9569437
#> [4,] -0.10542370 -0.5297184
#> [5,] -0.04391595 4.6079944
#> [6,] -0.04015672 -2.7067463
#> [7,] -0.15776690 -1.4306795
#> [8,] -0.16488408 -1.0140484
#> [9,] -0.06084554 -2.0522335
#> [10,] -0.08811032 1.0021806
#>
#> $ARcoeff
#> $ARcoeff$Component_1
#> [,1]
#> [1,] -0.5359413
#> [2,] -0.5359413
#> [3,] -0.5359413
#> [4,] -0.5359413
#> [5,] -0.5359413
#> [6,] -0.5359413
#> [7,] -0.5359413
#> [8,] -0.5359413
#> [9,] -0.5574503
#> [10,] -0.5574503
#>
#> $ARcoeff$Component_2
#> [,1]
#> [1,] 1.0000000
#> [2,] 1.0000000
#> [3,] 1.0005693
#> [4,] 1.0005693
#> [5,] 1.0005693
#> [6,] 1.0005693
#> [7,] 1.0266818
#> [8,] 1.0266818
#> [9,] 1.0266818
#> [10,] 0.9230759
#>
#>
#> $acc_rate
#> [1] 0.1 0.3
#>
#> $n_samp
#> [1] 10
#>
#> $LatentZ
#> latent Z 1 latent Z 2
#> [1,] 1 0
#> [2,] 1 0
#> [3,] 0 1
#> [4,] 1 0
#> [5,] 0 1
#> [6,] 1 0
#> [7,] 0 1
#> [8,] 1 0
#> [9,] 0 1
#> [10,] 0 1
#> [11,] 1 0
#> [12,] 1 0
#> [13,] 0 1
#> [14,] 1 0
#> [15,] 1 0
#> [16,] 1 0
#> [17,] 1 0
#> [18,] 0 1
#> [19,] 0 1
#> [20,] 0 1
#> [21,] 1 0
#> [22,] 1 0
#> [23,] 1 0
#> [24,] 1 0
#> [25,] 0 1
#> [26,] 0 1
#> [27,] 0 1
#> [28,] 0 1
#> [29,] 0 1
#> [30,] 0 1
#> [31,] 0 1
#> [32,] 0 1
#> [33,] 1 0
#> [34,] 1 0
#> [35,] 1 0
#> [36,] 0 1
#> [37,] 1 0
#> [38,] 0 1
#> [39,] 1 0
#> [40,] 1 0
#> [41,] 1 0
#> [42,] 0 1
#> [43,] 0 1
#> [44,] 0 1
#> [45,] 0 1
#> [46,] 0 1
#> [47,] 0 1
#> [48,] 1 0
#> [49,] 0 1
#> [50,] 1 0
#> [51,] 0 1
#> [52,] 0 1
#> [53,] 0 1
#> [54,] 1 0
#> [55,] 0 1
#> [56,] 0 1
#> [57,] 1 0
#> [58,] 0 1
#> [59,] 1 0
#> [60,] 1 0
#> [61,] 0 1
#> [62,] 1 0
#> [63,] 0 1
#> [64,] 0 1
#> [65,] 0 1
#> [66,] 1 0
#> [67,] 0 1
#> [68,] 0 1
#> [69,] 0 1
#> [70,] 1 0
#> [71,] 0 1
#> [72,] 1 0
#> [73,] 0 1
#> [74,] 0 1
#> [75,] 0 1
#> [76,] 1 0
#> [77,] 0 1
#> [78,] 1 0
#> [79,] 0 1
#> [80,] 1 0
#> [81,] 0 1
#> [82,] 0 1
#> [83,] 1 0
#> [84,] 0 1
#> [85,] 1 0
#> [86,] 1 0
#> [87,] 1 0
#> [88,] 1 0
#> [89,] 1 0
#> [90,] 0 1
#> [91,] 1 0
#> [92,] 0 1
#> [93,] 0 1
#> [94,] 1 0
#> [95,] 1 0
#> [96,] 1 0
#> [97,] 1 0
#> [98,] 0 1
#> [99,] 1 0
#> [100,] 1 0
#> [101,] 0 1
#> [102,] 0 1
#> [103,] 1 0
#> [104,] 1 0
#> [105,] 0 1
#> [106,] 0 1
#> [107,] 1 0
#> [108,] 1 0
#> [109,] 1 0
#> [110,] 1 0
#> [111,] 1 0
#> [112,] 0 1
#> [113,] 1 0
#> [114,] 0 1
#> [115,] 0 1
#> [116,] 1 0
#> [117,] 1 0
#> [118,] 1 0
#> [119,] 1 0
#> [120,] 1 0
#> [121,] 0 1
#> [122,] 1 0
#> [123,] 0 1
#> [124,] 1 0
#> [125,] 0 1
#> [126,] 0 1
#> [127,] 0 1
#> [128,] 0 1
#> [129,] 0 1
#> [130,] 1 0
#> [131,] 0 1
#> [132,] 1 0
#> [133,] 1 0
#> [134,] 1 0
#> [135,] 0 1
#> [136,] 1 0
#> [137,] 0 1
#> [138,] 0 1
#> [139,] 1 0
#> [140,] 1 0
#> [141,] 1 0
#> [142,] 1 0
#> [143,] 0 1
#> [144,] 0 1
#> [145,] 1 0
#> [146,] 1 0
#> [147,] 1 0
#> [148,] 1 0
#> [149,] 1 0
#> [150,] 0 1
#> [151,] 0 1
#> [152,] 1 0
#> [153,] 0 1
#> [154,] 1 0
#> [155,] 1 0
#> [156,] 0 1
#> [157,] 0 1
#> [158,] 1 0
#> [159,] 1 0
#> [160,] 1 0
#> [161,] 0 1
#> [162,] 1 0
#> [163,] 1 0
#> [164,] 1 0
#> [165,] 0 1
#> [166,] 1 0
#> [167,] 0 1
#> [168,] 1 0
#> [169,] 1 0
#> [170,] 0 1
#> [171,] 0 1
#> [172,] 1 0
#> [173,] 1 0
#> [174,] 0 1
#> [175,] 1 0
#> [176,] 0 1
#> [177,] 0 1
#> [178,] 0 1
#> [179,] 0 1
#> [180,] 1 0
#> [181,] 1 0
#> [182,] 1 0
#> [183,] 1 0
#> [184,] 1 0
#> [185,] 1 0
#> [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,] 1 0
#> [197,] 1 0
#> [198,] 0 1
#> [199,] 1 0
#> [200,] 0 1
#> [201,] 0 1
#> [202,] 0 1
#> [203,] 0 1
#> [204,] 1 0
#> [205,] 1 0
#> [206,] 0 1
#> [207,] 0 1
#> [208,] 1 0
#> [209,] 0 1
#> [210,] 0 1
#> [211,] 0 1
#> [212,] 0 1
#> [213,] 0 1
#> [214,] 0 1
#> [215,] 0 1
#> [216,] 1 0
#> [217,] 1 0
#> [218,] 1 0
#> [219,] 0 1
#> [220,] 1 0
#> [221,] 0 1
#> [222,] 0 1
#> [223,] 0 1
#> [224,] 1 0
#> [225,] 1 0
#> [226,] 0 1
#> [227,] 1 0
#> [228,] 0 1
#> [229,] 0 1
#> [230,] 0 1
#> [231,] 0 1
#> [232,] 1 0
#> [233,] 0 1
#> [234,] 0 1
#> [235,] 0 1
#> [236,] 1 0
#> [237,] 0 1
#> [238,] 1 0
#> [239,] 1 0
#> [240,] 0 1
#> [241,] 0 1
#> [242,] 1 0
#> [243,] 0 1
#> [244,] 1 0
#> [245,] 0 1
#> [246,] 1 0
#> [247,] 0 1
#> [248,] 0 1
#> [249,] 0 1
#> [250,] 1 0
#> [251,] 1 0
#> [252,] 1 0
#> [253,] 0 1
#> [254,] 0 1
#> [255,] 0 1
#> [256,] 1 0
#> [257,] 1 0
#> [258,] 1 0
#> [259,] 0 1
#> [260,] 0 1
#> [261,] 1 0
#> [262,] 1 0
#> [263,] 1 0
#> [264,] 1 0
#> [265,] 0 1
#> [266,] 1 0
#> [267,] 0 1
#> [268,] 1 0
#> [269,] 1 0
#> [270,] 1 0
#> [271,] 0 1
#> [272,] 0 1
#> [273,] 1 0
#> [274,] 0 1
#> [275,] 1 0
#> [276,] 1 0
#> [277,] 0 1
#> [278,] 1 0
#> [279,] 0 1
#> [280,] 1 0
#> [281,] 1 0
#> [282,] 1 0
#> [283,] 1 0
#> [284,] 1 0
#> [285,] 0 1
#> [286,] 1 0
#> [287,] 1 0
#> [288,] 0 1
#> [289,] 1 0
#> [290,] 0 1
#> [291,] 1 0
#> [292,] 1 0
#> [293,] 1 0
#> [294,] 0 1
#> [295,] 1 0
#> [296,] 1 0
#> [297,] 1 0
#> [298,] 1 0
#> [299,] 1 0
#>
#> $ncomp
#> [1] 2
#>
#> $fix_shift
#> [1] FALSE
#>