Skip to contents

Takes the output from a MCMC simulation of parameters of a mixture, and detects whether labels switch has occured while sampling, using the method by Celeux (2000).

Usage

label_switch(x, m)

Arguments

x

output from an MCMC sampling of a mixture. A matrix, each column corresponds to one component of the mixture.

m

the number of observations in the sample that will be used to initialise the algorithm. m~100 is recommended.

Details

Function can be directly executed when x is one of mix_weights, scale, precision, shift or mu from bayes_mixAR output. ARcoeff cannot be input as it is, but element from the list may be used.

Value

A list of 2:

x

The input matrix, with adjusted labels

true_perm

The "true" permutation at each iteration.

References

Celeux2000mixAR

Author

Davide Ravagli

Note

There is no absolute choice on what x should be to obtain the "true" permutation at any given point. User is subject to make the most suitable choice, given output of their MCMC.

See also

Examples

model <- new("MixARGaussian",
             prob   = exampleModels$WL_At@prob,      # c(0.5, 0.5)
             scale  = exampleModels$WL_At@scale,     # c(1, 2)        
             arcoef = exampleModels$WL_At@arcoef@a ) # list(-0.5, 1.1)

y <- mixAR_sim(model, n = 300, init = rep(0, which.max(model@order)))

## just examples, use larger numbers in practice
nsim <- 30   # 200
burnin <- 10  # 100
x <- bayes_mixAR(y, model, fix_shift = FALSE, tau = c(.15, .25),
              nsim = nsim, burnin = burnin)

label_switch(x$mix_weights, m = 5)
#> $x
#>            [,1]      [,2]
#>  [1,] 0.4857270 0.5142730
#>  [2,] 0.4221668 0.5778332
#>  [3,] 0.4457839 0.5542161
#>  [4,] 0.4616305 0.5383695
#>  [5,] 0.4520209 0.5479791
#>  [6,] 0.4828118 0.5171882
#>  [7,] 0.4357387 0.5642613
#>  [8,] 0.4152270 0.5847730
#>  [9,] 0.4550276 0.5449724
#> [10,] 0.4846237 0.5153763
#> [11,] 0.4842792 0.5157208
#> [12,] 0.4987070 0.5012930
#> [13,] 0.4680085 0.5319915
#> [14,] 0.4628079 0.5371921
#> [15,] 0.4750042 0.5249958
#> [16,] 0.4486247 0.5513753
#> [17,] 0.4785073 0.5214927
#> [18,] 0.4975636 0.5024364
#> [19,] 0.4573973 0.5426027
#> [20,] 0.4971300 0.5028700
#> 
#> $true_perm
#>       [,1] [,2]
#>  [1,]    2    1
#>  [2,]    2    1
#>  [3,]    2    1
#>  [4,]    2    1
#>  [5,]    2    1
#>  [6,]    2    1
#>  [7,]    2    1
#>  [8,]    2    1
#>  [9,]    1    2
#> [10,]    2    1
#> [11,]    2    1
#> [12,]    2    1
#> [13,]    1    2
#> [14,]    2    1
#> [15,]    1    2
#>