Learn R Programming

depmixS4 (version 0.1-1)

depmix: Dependent Mixture Model Specifiction

Description

depmixS4 is a framework for specifying and fitting dependent mixture models, otherwise known as hidden or latent Markov models. Optimization is done with the EM algorithm or optionally with Rdonlp2 when constraints on parameters are imposed. Models for different distributions can easily be added. depmix creates an object of class depmix, a dependent mixture model, otherwise known as hidden Markov model.

Usage

depmix(response, data=NULL, nstates, transition=~1, family=gaussian(), 
		prior=~1, initdata=NULL, respstart=NULL, trstart=NULL, instart=NULL,
		ntimes=NULL,...)
	
	## S3 method for class 'depmix':
summary(object)
	## S3 method for class 'depmix':
logLik(object, method="lystig")
	## S3 method for class 'depmix':
AIC(object, ..., k=2)
	## S3 method for class 'depmix':
BIC(object, ...)
	## S3 method for class 'depmix':
nobs(object, ...)
	
	## S3 method for class 'depmix':
npar(object)
	## S3 method for class 'depmix':
freepars(object)
	## S3 method for class 'depmix':
setpars(object,values,which="pars",...)
	## S3 method for class 'depmix':
getpars(object,which="pars",...)

Arguments

object
An object with class depmix.
response
The response to be modeled; either a formula or a list of formulae in the multivariate case. See details.
data
An optional data.frame to interpret the variables in response and transition.
nstates
The number of states of the model.
transition
A one-sided formula specifying the model for the transitions. See details.
family
A family argument for the response. This must be a list of family's if the response is multivariate.
prior
A one-sided formula specifying the density for the prior or initial state probabilities.
initdata
An optional data.frame to interpret the variables occuring in prior. The number of rows of this data.frame must be equal to the number of cases being modeled. See details.
respstart
Starting values for the parameters of the response models.
trstart
Starting values for the parameters of the transition models.
instart
Starting values for the parameters of the prior or initial state probability model.
ntimes
A vector specifying the lengths of individual, ie independent, time series. If not specified, the responses are assumed to form a single time series. If the data argument has an attribute ntimes, then this is used.
method
Can be used to compute the likelihood by calling the forward backward routine instead of the recursion defined by Lystig & Hughes (2002). The latter is faster as it does not compute backward variables which are not neccessary for computing the li
which
The default "pars" returns a vector of all parameters of a depmix object; the alternative value "fixed" return a logical vector of the same length indicating which parameters are fixed. The setpars functions sets parameters (or the logi
values
In setpars used to set the parameters to these values.
k
The penalty factor in the AIC which defaults to 2. log(nobs) can be used to get the BIC.
...
Not used currently.

Value

  • depmix returns an object of class depmix which has the following slots:
  • responseA list of a list of response models; the first index runs over states; the second index runs over the independent responses in case a multivariate response is provided.
  • transitionA list of transInit models, ie multinomial logistic models with length the number of states.
  • priorA multinomial logistic model for the initial state probabilities.
  • dens,trDens,initSee depmix-class help for details. For internal use.
  • stationaryLogical indicating whether the transitions are time-dependent or not; for internal use.
  • ntimesA vector containing the lengths of independent time series; if data is provided, sum(ntimes) must be equal to nrow(data).
  • nstatesThe number of states of the model.
  • nrespThe number of independent responses.
  • nparsThe total number of parameters of the model. This is not the degrees of freedom, ie there are redundancies in the parameters, in particular in the multinomial models for the transitions and prior.
  • logLik, AIC, and BIC return the respective values associated with the current parameter values. nobs returns the number of observations, ie sum(ntimes) that is used in computing the BIC. npar returns the number of paramters of a model; freepars returns the number of non-fixed parameters.

Details

The function depmix creates an S4 object of class depmix, which needs to be fitted using depmix.fit to optimize the parameters. The response model(s) are created by call(s) to response providing the family and optional predictors. If response is a list of formulae, the response's are assumed to be independent conditional on the latent state. The transitions are modeled as a multinomial logistic model for each state. Hence, the transition matrix can be modeled as time-dependent, depending on predictors. The prior density is also modeled as a multinomial logistic. Both are created by calls to transInit. Starting values may be provided by the respective arguments. The order in which parameters must be provided can be easily studied by using the setpars function (see example). Linear constraints on parameters can be provided as argument to the depmix.fit function.

References

On hidden Markov models: Lawrence R. Rabiner (1989). A tutorial on hidden Markov models and selected applications in speech recognition. Proceedings of IEEE, 77-2, p. 267-295. On latent class models: A. L. McCutcheon (1987). Latent class analysis. Sage Publications.

See Also

depmix.fit, transInit, response.

Examples

Run this code
# create a 2 state model with one continuous and one binary response
data(speed)
mod <- depmix(list(rt~1,corr~1),data=speed,nstates=2,family=list(gaussian(),multinomial()))
# print the model, formulae and parameter values
mod

# to see the ordering of parameters to use in setpars
mod <- setpars(mod, value=1:npar(mod))
mod

# to see which parameters are fixed (by default only baseline parameters in
# the multinomial logistic models for the transition models and the initial
# state probabilities model
mod <- setpars(mod, getpars(mod,which="fixed"))
mod

Run the code above in your browser using DataLab