githubEdit

R Example

Visser & Speekenbrink: Sec 3

S&P 500

Objective

  1. Easy fitting Gaussian mixture using lca function

  2. Obtain posterior probability

# load package 
require(hmmr)
data('sp500')

# fit data using lca, default is Gaussian distribution. 
m1 <- lca(sp500$logret, nclasses = 1)
m2 <- lca(sp500$logret, nclasses = 2)
m3 <- lca(sp500$logret, nclasses = 3)

# obtain posterior probability 
# method for obtain posterior probability, such as vertibit, smoothing 
# smoothing in mixture model gives exact posterior probability defined previously 
pst1 <- posterior(m2, type = 'smoothing')

# local method directly gives component based on maximum posterior probability  
pstState <- posterior(m2, type = 'local')

# actual posterior probability is very different from the estimated probability
# indicates components not well separated
table(pstState) / sum(table(pstState))

Conservation data

Context:

Response variables at 5 different trials, r1 to r5. At each trial, there is a correct strategy and incorrect strategy.

  1. Use BIC weights to get relative likelihood of model

  2. Fitting multivariate distribution

  3. Debugging on issue around singularity

  4. Fitting independent Gaussian

BIC weights and relative probability

Fitting multivariate normal distribution response model

  1. MVNresponse creates default multivariate normal distributed response.

  2. transInit is specified as no response. The response in our case is the latent component probability.

  3. transition argument for makeMix is skipped since they are used for HMM model.

Degenerate solutions due to singular covariance matrix

This is because our estimated covariance matrix for one component is singular. The covariance matrix transform to correlation matrix result in a 2 by 2 matrix of ones. This suggests perfect collinearity between two dimensions. So our bivariate Gaussian ellipses is just a line in 2D space. This often is a sign of mis-specification. This can also be seen from the relative small estimated state probability, singling not too much population in that component.

Fitting Independent Gaussian Distribution

Last updated