Description Usage Arguments Details Value Author(s) References Examples
View source: R/FFBS_BinomialNormal.R
Posterior (MCMC) samples for a hidden Markov model with a Binomial and Normal response using the forward-filtering backward-sampling algorithm.
1 2 3 |
FFBS_BinomialNormal(bin,norm,nstates,hyperPars=list(),ntimes,niter=1000,nburnin=0)
|
bin |
the Binomial response variable. As in the glm function, this can be a binary vector with 1 indicating success and 0 failure, a factor where the first level is considered a failure and all other leves success, or a matrix with the number of successes and failures in the columns. |
norm |
the Normal response variable. This should be a numeric vector. |
nstates |
the required number of states in the hidden Markov model. |
hyperPars |
a named |
ntimes |
the lengths of time series in arguments |
niter |
number of iterations to run the sampler for. |
nburnin |
number of initial samples to discard as burnin, |
This function runs the forward-filtering backwards-sampling MCMC algorithm for a hidden Markov model with a Binomial and Normal response variable. The response variables are assumed conditionally independent given the states.
The following conjugate prior distributions are used:
For the initial state probabilities, a Dirichlet prior with parameter vector init_alpha
For each row in the transition probability matrix, a Dirichlet prior is used. The parameters of these Dirichlet distributions are contained in the matrix trans_alpha
.
For the probability of correct in the Binomial response, a Beta prior is used, with parameters bin_alpha
and bin_beta
.
For the mean and variance of the Normal response, a Normal-inverse-Gamma prior is used.
This function was written mainly for didactive purposes, not for speed (or compatibility with other packages which provide posterior samples).
A named list with samples of the different parameters.
Maarten Speekenbrink
Visser, I., & Speekenbrink, M. (in preparation). Mixture and hidden Markov models in R.
1 2 3 4 5 6 7 8 9 10 11 | ## Not run:
data(speed)
set.seed(1)
hyperPars <- list(norm_invsigma_scale=.01,norm_invsigma_shape=.01,norm_mu_sca=.1)
mcmc_samples <- FFBS_BinomialNormal(speed$corr,speed$rt,nstates=2,
ntimes=c(168,134,137),niter=500,hyperPars = hyperPars)
plot(mcmc_samples$mu[,1])
hist(mcmc_samples$mu[,1])
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.