[Depmix-commits] r90 - / trunk/R trunk/man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Mar 19 22:17:55 CET 2008
Author: ingmarvisser
Date: 2008-03-19 22:17:55 +0100 (Wed, 19 Mar 2008)
New Revision: 90
Modified:
todo
trunk/R/allGenerics.R
trunk/R/depmix.R
trunk/R/depmix.fitted.R
trunk/R/responses.R
trunk/man/depmix-class.Rd
trunk/man/depmix-internal.Rd
trunk/man/depmix.Rd
trunk/man/depmix.fit.Rd
trunk/man/depmix.fitted-class.Rd
trunk/man/llratio.Rd
trunk/man/response-class.Rd
trunk/man/response-classes.Rd
trunk/man/response.Rd
trunk/man/speed.Rd
Log:
Added links in help files and other minor stuff
Modified: todo
===================================================================
--- todo 2008-03-19 18:47:28 UTC (rev 89)
+++ todo 2008-03-19 21:17:55 UTC (rev 90)
@@ -24,11 +24,11 @@
(this involves a latent class model rather than a hidden Markov model)
Ingmar: done!!!!!
-- review summary/print functions for depmix and depmix.fitted
+- review summary/print functions for depmix and depmix.fitted: done!!!!!
-- viterbi algorithm to get maximum a posteriori states for hmmModel: Maarten, done !!!!!
+- viterbi algorithm to get maximum a posteriori states for depmix model: Maarten, done !!!!!
-- viterbi algorithm to get posterior probabilities as part of depmix.fitted
+- viterbi algorithm to get posterior probabilities as part of depmix.fitted: skip!!
- general documentation: depmix-introduction.pdf needs updating
Modified: trunk/R/allGenerics.R
===================================================================
--- trunk/R/allGenerics.R 2008-03-19 18:47:28 UTC (rev 89)
+++ trunk/R/allGenerics.R 2008-03-19 21:17:55 UTC (rev 90)
@@ -48,10 +48,13 @@
setGeneric("getpars", function(object,which="pars",...) standardGeneric("getpars"))
-setGeneric("fit",function(object,w,...) standardGeneric("fit"))
-
setGeneric("logDens",function(object,...) standardGeneric("logDens"))
setGeneric("dens",function(object,...) standardGeneric("dens"))
setGeneric("summary")
+
+setGeneric("ntimes", function(object, ...) standardGeneric("ntimes"))
+
+setGeneric("nresp", function(object, ...) standardGeneric("nresp"))
+
Modified: trunk/R/depmix.R
===================================================================
--- trunk/R/depmix.R 2008-03-19 18:47:28 UTC (rev 89)
+++ trunk/R/depmix.R 2008-03-19 21:17:55 UTC (rev 90)
@@ -266,7 +266,6 @@
function(object) return(object at npars)
)
-setGeneric("ntimes", function(object, ...) standardGeneric("ntimes"))
setMethod("ntimes","depmix",
function(object) return(object at ntimes)
)
@@ -276,7 +275,6 @@
function(object) return(object at nstates)
)
-setGeneric("nresp", function(object, ...) standardGeneric("nresp"))
setMethod("nresp","depmix",
function(object) return(object at nresp)
)
@@ -290,8 +288,6 @@
}
)
-setGeneric("logLik", function(object, ...) standardGeneric("logLik"))
-
# depends on getpars and nobs
setMethod("logLik",signature(object="depmix"),
function(object,method="lystig") {
Modified: trunk/R/depmix.fitted.R
===================================================================
--- trunk/R/depmix.fitted.R 2008-03-19 18:47:28 UTC (rev 89)
+++ trunk/R/depmix.fitted.R 2008-03-19 21:17:55 UTC (rev 90)
@@ -1,6 +1,6 @@
#
-# Ingmar Visser, 29-2-2008
+# Ingmar Visser, started 29-2-2008
#
#
@@ -15,12 +15,11 @@
contains="depmix"
)
-setMethod("fit",signature(object="depmix"),
- function(object,w=NULL,fixed=NULL,equal=NULL,conrows=NULL,conrows.upper=0,conrows.lower=0,method=NULL,...) {
+setMethod("fit",
+ signature(object="depmix"),
+ function(object,fixed=NULL,equal=NULL,conrows=NULL,conrows.upper=0,conrows.lower=0,method=NULL,...) {
- # decide on method to be used
- # em has to be added here under certain conditions
- # in particular when there are linear constraints donlp should be used
+ # when there are linear constraints donlp should be used
# otherwise EM is good
# can/does EM deal with fixed constraints??? it should be possible for sure
Modified: trunk/R/responses.R
===================================================================
--- trunk/R/responses.R 2008-03-19 18:47:28 UTC (rev 89)
+++ trunk/R/responses.R 2008-03-19 21:17:55 UTC (rev 90)
@@ -118,10 +118,10 @@
pstart <- matrix(pstart,ncol(x),byrow=TRUE)
if(ncol(x)>1) parameters$coefficients[2:ncol(x),] <- pstart[2:ncol(x),]
} else {
- parameters$coefficients <- family$linkfun(pstart[1:length(parameters$coefficients)])
+ parameters$coefficients <- family$linkfun(as.numeric(pstart[1:length(parameters$coefficients)]))
}
if(length(unlist(parameters))>length(parameters$coefficients)) {
- if(family$family=="gaussian") parameters$sd <- pstart[(length(parameters$coefficients)+1)]
+ if(family$family=="gaussian") parameters$sd <- as.numeric(pstart[(length(parameters$coefficients)+1)])
}
}
mod <- switch(family$family,
Modified: trunk/man/depmix-class.Rd
===================================================================
--- trunk/man/depmix-class.Rd 2008-03-19 18:47:28 UTC (rev 89)
+++ trunk/man/depmix-class.Rd 2008-03-19 21:17:55 UTC (rev 90)
@@ -3,29 +3,20 @@
\docType{class}
\alias{depmix-class}
-\alias{posterior}
-\alias{posterior,depmix-method}
\title{Class "depmix"}
\description{A \code{\link{depmix}} model.}
-\usage{
- \S4method{posterior}{depmix}(object)
-}
-
-\arguments{
- \item{object}{An object of class "depmix".}
-}
-
\section{Slots}{
+
\describe{
\item{\code{response}:}{List of list of \code{response} objects.}
- \item{\code{transition}}{List of \code{transInit} objects.}
+ \item{\code{transition}}{List of \code{\link{transInit}} objects.}
- \item{\code{prior}:}{\code{transInit} object.}
+ \item{\code{prior}:}{\code{\link{transInit}} object.}
\item{\code{dens}:}{Array of dimension sum(ntimes)*nresp*nstates
providing the densities of the observed responses for each state.}
Modified: trunk/man/depmix-internal.Rd
===================================================================
--- trunk/man/depmix-internal.Rd 2008-03-19 18:47:28 UTC (rev 89)
+++ trunk/man/depmix-internal.Rd 2008-03-19 21:17:55 UTC (rev 90)
@@ -5,6 +5,8 @@
\alias{fb}
\alias{logDens}
\alias{lystig}
+
+\alias{makeDepmix}
\alias{makePriorModel}
\alias{makeResponseModels}
\alias{makeTransModels}
Modified: trunk/man/depmix.Rd
===================================================================
--- trunk/man/depmix.Rd 2008-03-19 18:47:28 UTC (rev 89)
+++ trunk/man/depmix.Rd 2008-03-19 21:17:55 UTC (rev 90)
@@ -34,12 +34,22 @@
\alias{show,depmix-method}
\alias{summary,depmix-method}
+\alias{posterior}
+\alias{posterior,depmix-method}
+
\title{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.
- \item{depmix}{\code{depmix} creates an object of class \code{depmix}, a
- dependent mixture model, or hidden Markov model.}
+ \code{depmix} creates an object of class \code{depmix}, a
+ dependent mixture model, otherwise known as hidden Markov
+ model.
}
@@ -60,6 +70,7 @@
\S4method{setpars}{depmix}(object,which="pars",...)
\S4method{getpars}{depmix}(object,which="pars",...)
+ \S4method{posterior}{depmix}(object,...)
}
\arguments{
@@ -117,11 +128,11 @@
\details{
The function \code{depmix} creates an S4 object of class \code{depmix},
- which needs to be fitted using \code{\link[depmix]{depmix.fit}} to
+ which needs to be fitted using \code{\link[depmixS4]{depmix.fit}} to
optimize the parameters.
The response model(s) are created by call(s) to
- \code{\link[depmix]{response}} providing the family and optional
+ \code{\link[depmixS4]{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.
@@ -129,14 +140,14 @@
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
- \code{\link[depmix]{transInit}}.
+ \code{\link[depmixS4]{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
\code{setpars} function (see example).
Linear constraints on parameters can be provided as argument to the
- \code{\link[depmix]{depmix.fit}} function.
+ \code{\link[depmixS4]{depmix.fit}} function.
}
@@ -185,8 +196,10 @@
\author{Ingmar Visser \email{i.visser at uva.nl}}
\seealso{
- \code{\link[depmix]{depmix.fit}},\code{\link[depmix]{transInit}},
- \code{\link[depmix]{response}}.
+
+ \code{\link[depmixS4]{depmix.fit}}, \code{\link{transInit}},
+ \code{\link{response}}.
+
}
\references{
@@ -202,10 +215,23 @@
\examples{
- # create a 2 state model with one continuous and one binary response
- data(speed)
- depmix(list(rt~1,corr~1),data=speed,nstates=2,family=list(gaussian(),multinomial()))
-
+# 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
+
+
}
\keyword{methods}
Modified: trunk/man/depmix.fit.Rd
===================================================================
--- trunk/man/depmix.fit.Rd 2008-03-19 18:47:28 UTC (rev 89)
+++ trunk/man/depmix.fit.Rd 2008-03-19 21:17:55 UTC (rev 90)
@@ -11,32 +11,39 @@
\title{Fit depmix models}
-\description{\code{fit} optimizes parameters of depmix models, possibly
+\description{
+
+ \code{fit} optimizes parameters of \code{\link{depmix}} models, optionally
subject to general linear (in)equality constraints.}
\usage{
- \S4method{fit}{depmix}(object, w=NULL, fixed=NULL, equal=NULL, conrows=NULL,
+ \S4method{fit}{depmix}(object, fixed=NULL, equal=NULL, conrows=NULL,
conrows.upper=0, conrows.lower=0, method=NULL,...)
\S4method{summary}{depmix.fitted}(object)
-
}
\arguments{
+
\item{object}{An object of class \code{depmix}.}
- \item{w}{Weights??? What's this argument doing here? It's not being
- used.}
+
\item{fixed}{Vector of mode logical indicating which parameters should
be fixed.}
+
\item{equal}{Vector indicating equality constraints; see details.}
+
\item{conrows}{Rows of a general linear constraint matrix; see details.}
+
\item{conrows.upper, conrows.lower}{Upper and lower bounds for the
linear constraints; see details.}
+
\item{method}{The optimization method; mostly determined by
constraints.}
+
\item{...}{Not used currently.}
+
}
\details{
@@ -76,30 +83,34 @@
}
\value{
- \code{fit} returns an object of class \code{depmix.fitted} which contains
+
+ \code{fit} returns an object of class \code{\link[depmix.fitted-class]{depmix.fitted}} which contains
the original depmix object, and further has slots:
- message: Convergence information.
+ \item{message}{: Convergence information.}
- conMat: The constraint matrix A, see details.
- posterior: The posterior state probabilities.
+ \item{conMat}{: The constraint matrix A, see details.}
+
+ \item{posterior}{: The posterior state probabilities.}
- The print function shows the \code{message} and the parameter
- estimates.
+ The print method shows the \code{message} and the summary method
+ shows the parameter estimates.
}
\examples{
- data(speed)
- # 2-state model on the RTs of the speed data with random
- # starting values for the transition pars (without those EM does not get off the ground)
- set.seed(1)
- mod <- depmix(rt~1,data=speed,nstates=2,trstart=runif(4))
- # fit the model
- mod1 <- fit(mod)
- mod1 # to see the logLik and optimization information
- # to see the parameters
- summary(mod1)
+
+data(speed)
+# 2-state model on the RTs of the speed data with random
+# starting values for the transition pars (without those EM does not get off the ground)
+set.seed(1)
+mod <- depmix(rt~1,data=speed,nstates=2,trstart=runif(4))
+# fit the model
+mod1 <- fit(mod)
+mod1 # to see the logLik and optimization information
+# to see the parameters
+summary(mod1)
+
}
\author{Ingmar Visser}
Modified: trunk/man/depmix.fitted-class.Rd
===================================================================
--- trunk/man/depmix.fitted-class.Rd 2008-03-19 18:47:28 UTC (rev 89)
+++ trunk/man/depmix.fitted-class.Rd 2008-03-19 21:17:55 UTC (rev 90)
@@ -6,12 +6,12 @@
\title{Class "depmix.fitted"}
-\description{Class \code{depmix.fitted}.}
+\description{A fitted \code{\link{depmix}} model.}
\section{Slots}{
- A \code{depmix.fitted} object is a \code{depmix} object with two
- additional slots:
+ A \code{depmix.fitted} object is a \code{depmix} object with three
+ additional slots, here is the complete list:
\describe{
@@ -65,6 +65,10 @@
}
+\section{Extends}{
+ \code{depmix.fitted} extends the \code{depmix} class.
+}
+
\author{Ingmar Visser}
\keyword{classes}
Modified: trunk/man/llratio.Rd
===================================================================
--- trunk/man/llratio.Rd 2008-03-19 18:47:28 UTC (rev 89)
+++ trunk/man/llratio.Rd 2008-03-19 21:17:55 UTC (rev 90)
@@ -1,46 +1,49 @@
-\name{llratio}
-
-\docType{method}
-
-\alias{llratio}
-\alias{llratio,depmix.fitted-method}
-\alias{likelihoodratio}
-
-\alias{show,llratio-method}
-
-\title{Log likelihood ratio test on two fitted models}
-
-\description{Performs a log likelihood ratio test on two fitted
-\code{depmix} models.}
-
-\usage{
-
- llratio(basemodel,constrainedmodel,...)
-
-}
-
-\arguments{
-
- \item{basemodel}{Fitted depmix model.}
-
- \item{constrainedmodel}{Fitted depmix model.}
-
- \item{...}{Not currently used.}
-
-}
-
-\value{
- \code{llratio} returns an object of class \code{llratio} which has slots:
-
- \item{value}: Minus twice the loglikelihood difference.
-
- \item{df}: The degrees of freedom, ie the difference in number of freely
- estimated paraemters between the models.
-
- The print method shows the value,
-
-}
-
-\author{Ingmar Visser}
-
+
+\name{llratio}
+
+\docType{methods}
+
+\alias{llratio}
+
+\alias{loglikelihoodratio}
+
+\alias{show,llratio-method}
+
+\title{Log likelihood ratio test on two fitted models}
+
+\description{Performs a log likelihood ratio test on two fitted
+\code{depmix} models.}
+
+\usage{
+
+ llratio(basemodel, constrainedmodel, ...)
+
+}
+
+\arguments{
+
+ \item{basemodel}{Fitted model with a \code{logLik} method.}
+
+ \item{constrainedmodel}{Fitted model with a \code{logLik} method.}
+
+ \item{...}{Not currently used.}
+
+}
+
+\value{
+
+ \code{llratio} returns an object of class \code{llratio} which has slots:
+
+ \item{value}{: Minus twice the loglikelihood difference.}
+
+ \item{df}{: The degrees of freedom, ie the difference in number of freely
+ estimated paraemters between the models.}
+
+ The print method shows the value, the degrees of freedom and the
+ corresponding p-value under the chisquared distribution.
+
+}
+
+\author{Ingmar Visser}
+
\keyword{methods}
\ No newline at end of file
Modified: trunk/man/response-class.Rd
===================================================================
--- trunk/man/response-class.Rd 2008-03-19 18:47:28 UTC (rev 89)
+++ trunk/man/response-class.Rd 2008-03-19 21:17:55 UTC (rev 90)
@@ -3,15 +3,13 @@
\docType{class}
\alias{response-class}
-\alias{getdf}
-\alias{getdf,response-method}
\title{Class "response"}
-\description{A \code{\link{response}} model for depmix models.}
+\description{
-\usage{
- \S4method{getdf}{response}(object)
+A generic \code{\link{response}} model for \code{\link{depmix}} models.
+
}
\arguments{
@@ -19,21 +17,31 @@
}
\section{Slots}{
+
\describe{
\item{\code{parameters}:}{A (named) list of parameters.}
+
\item{\code{fixed}:}{A logical vector indicating which parameters
are fixed.}
+
\item{\code{y}:}{A matrix with the actual response; possibly
multivariate.}
+
\item{\code{x}:}{A design matrix; possibly only an intercept term.}
+
\item{\code{npar}:}{The number of parameters.}
}
}
\details{
+
This class offers a framework from which to build specific response
- models such as glm based responses or multinomial responses.
+ models such as glm based responses or multinomial responses. For
+ extensibility, objects with class \code{response} should have at least
+ methods: \code{dens} to return the \code{dens}'ity of responses, and
+ \code{getpars} and \code{setpars} methods to get and set parameters.
+
}
\section{Accessor Functions}{
Modified: trunk/man/response-classes.Rd
===================================================================
--- trunk/man/response-classes.Rd 2008-03-19 18:47:28 UTC (rev 89)
+++ trunk/man/response-classes.Rd 2008-03-19 21:17:55 UTC (rev 90)
@@ -2,12 +2,15 @@
\docType{class}
+\alias{response-classes}
+
\alias{GLMresponse-class}
\alias{transInit-class}
\title{Class "GLmresponse" and class "transInit"}
-\description{Specific instances of response models for depmix models.}
+\description{Specific instances of response models for \code{\link{depmix}}
+models.}
\section{Slots}{
@@ -16,24 +19,28 @@
classes have the following slots:
\describe{
- \item{\code{formula}:}{A formula that specifies the model.}
- \item{\code{family}:}{A family object specifying the link function etc.}
+
+ \item{\code{formula}:}{A formula that specifies the model.}
+
+ \item{\code{family}:}{A family object specifying the link
+ function. Currently, the only options are \code{gaussian()} from
+ the \code{\link{stats}}-package and \code{multinomial}.}
}
}
\details{
- The \code{GLMresponse}-class offers an interface to the glm functions
- that are subsequently used in fitting the \code{depmix} model of which
- the response is a part.
+ The \code{GLMresponse}-class offers an interface to the
+ \code{\link[stats]{glm}} functions that are subsequently used in fitting
+ the \code{depmix} model of which the response is a part.
The \code{transInit} is an extension of \code{response} that is used to
model the transition matrix and the initial state probabilities by the
use of a multinomial logistic model, the difference being that in fact
the response is missing as the transitions between states are not
observed. This class has its own fit function which is an interface to
- the multinom function in nnet.
+ the multinom function in \code{\link{nnet}}.
}
Modified: trunk/man/response.Rd
===================================================================
--- trunk/man/response.Rd 2008-03-19 18:47:28 UTC (rev 89)
+++ trunk/man/response.Rd 2008-03-19 21:17:55 UTC (rev 90)
@@ -9,12 +9,20 @@
\alias{transInit,formula-method}
\alias{GLMresponse,formula-method}
+\alias{getdf}
+\alias{getdf,response-method}
+
\alias{show,GLMresponse-method}
\title{Methods for creating depmix response models}
-\description{Create \code{\link[depmix]{response}} models.}
+\description{
+Create \code{response} objects for \code{\link{depmix}} models using
+formulae and family objects.
+
+}
+
\usage{
GLMresponse(formula, data=NULL, family=gaussian(), pstart=NULL,
@@ -22,7 +30,8 @@
transInit(formula, nstates, data=NULL, family=multinomial(),
pstart=NULL, fixed=NULL, prob=TRUE, ...)
-
+
+ \S4method{getdf}{response}(object)
}
\arguments{
@@ -38,6 +47,7 @@
\item{prob}{Logical indicating whether the starting values for
multinomial() family models are probabilities or logistic
parameters (see details).}
+ \item{object}{Object of class response.}
\item{...}{Not used currently.}
}
@@ -63,11 +73,11 @@
\code{GLMresponse} and \code{transInit} return objects of class
\code{GLMresponse} and \code{transInit} respectively; both classes
- extend the \code{\link[depmix]{response-class}}.
+ extend the \code{\link{response-class}}.
- For extensibility, objects with class \code{response} have at least
- methods: \code{predict} to return \code{predict}'ed responses,
- \code{dens} to return the \code{dens}'ity of responses.
+ \code{getdf} returns the number of free parameters of a
+ \code{response} model.
+
}
\author{Ingmar Visser}
Modified: trunk/man/speed.Rd
===================================================================
--- trunk/man/speed.Rd 2008-03-19 18:47:28 UTC (rev 89)
+++ trunk/man/speed.Rd 2008-03-19 21:17:55 UTC (rev 90)
@@ -9,15 +9,15 @@
\description{
This data set is a bivariate series of reaction times and accuracy
- scores of a single subject switching between slow and accurate responding
- and fast guessing on a lexical decision task. The slow and accurate
- responding, and the fast guessing can be modelled using two states,
- with a switching regime between them. The dataset further contains a
- third variable called Pacc, representing the relative pay-off for
- accurate responding, which is on a scale of zero to one. The value of
- Pacc was varied during the experiment to induce the switching.
- This data set is a subset of data from experiment 2 in \cite{Van der
- Maas et al, 2005}.
+ scores of a single subject switching between slow and accurate
+ responding and fast guessing on a lexical decision task. The slow and
+ accurate responding, and the fast guessing can be modelled using two
+ states, with a switching regime between them. The dataset further
+ contains a third variable called Pacc, representing the relative
+ pay-off for accurate responding, which is on a scale of zero to one.
+ The value of Pacc was varied during the experiment to induce the
+ switching. This data set is a from a single subject from experiment 2
+ in \cite{Van der Maas et al, 2005}.
}
@@ -27,7 +27,7 @@
\source{
- Han L. J. Van der Maas, Conor V. Dolan and Peter C. M. Molenaar (2005),
+ Han L. J. Van der Maas, Conor V. Dolan and Peter C. M. Molenaar (2007),
Phase Transitions in the Trade-Off between Speed and Accuracy in Choice
Reaction Time Tasks. \emph{Manuscript in preparation}.
More information about the depmix-commits
mailing list