Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert hmodel.object so it can be passed to hmodel argument in msm #17

Closed
wjchulme opened this issue Feb 11, 2019 · 3 comments
Closed

Comments

@wjchulme
Copy link
Contributor

For HMMs, is there a function that takes a hmodel.object (or a msm.object) and returns a list of hmmdist objects that can be passed to the hmodel argument in a new msm() call? For instance, it could be used in the following way:

# create first HMM
fit1 <- msm( y ~ time, subject = ptnum, data = example.df, 
                    qmatrix = rbind( c(0, 0.25, 0), c(0, 0, 0.2), c(0, 0, 0)),
                    hmodel = list (hmmNorm(mean=90, sd=8), hmmNorm(mean=70, sd=8), hmmIdent(-9)) 
           )

# extract hmodel.object from fit1
hmodel.fit1 <- hmodel.msm(fit1$hmodel)

# create second HMM with initial emission distribution paramaters from fit1
fit2 <- msm(y ~ time, subject = ptnum, data = example.df, 
                    qmatrix = rbind( c(0, 0.25, 0.1), c(0.1, 0, 0.2), c(0, 0, 0)),
                    hmodel = hmodel.fit1
           )

I've built a function that does this for a very specific multivariate categorical HMM but it would be useful to have a generic function that does this for any given hmodel.object.

Has this been considered? If not, could you provide any pointers on how best this might be achieved?

Cheers

@chjackson
Copy link
Owner

Not something I've ever needed, but happy to include it if you want to write it. I think it'd need a lookup table that maps the character labels identifying each class of emission distribution to the corresponding constructor functions in R/hmm-dists.R. The function could then extract the labels stored in fit1$hmodel$labels, and the parameter estimates, and build the constructors list.

@wjchulme
Copy link
Contributor Author

Thanks - I'll let you know if I ever get round to this!

@chjackson
Copy link
Owner

Implemented in a6ecdcc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants