[Depmix-commits] r82 - in trunk: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Mar 17 16:38:32 CET 2008
Author: ingmarvisser
Date: 2008-03-17 16:38:32 +0100 (Mon, 17 Mar 2008)
New Revision: 82
Modified:
trunk/R/EM.R
trunk/R/allGenerics.R
trunk/R/depmix.R
trunk/R/depmix.fitted.R
trunk/R/responses.R
trunk/man/balance.Rd
trunk/man/depmix-class.Rd
trunk/man/depmix.Rd
trunk/man/depmix.fit.Rd
trunk/man/response-class.Rd
trunk/man/response.Rd
trunk/man/speed.Rd
Log:
Minor changes, mostly in documentation
Modified: trunk/R/EM.R
===================================================================
--- trunk/R/EM.R 2008-03-13 00:36:20 UTC (rev 81)
+++ trunk/R/EM.R 2008-03-17 15:38:32 UTC (rev 82)
@@ -64,8 +64,11 @@
}
LL <- logLik(object)
- if(verbose) cat("iteration",j,"logLik:",LL,"\n")
- if( (LL >= LL.old) & (LL - LL.old < tol)) converge <- TRUE
+ if(verbose&((j%%5)==0)) cat("iteration",j,"logLik:",LL,"\n")
+ if( (LL >= LL.old) & (LL - LL.old < tol)) {
+ cat("iteration",j,"logLik:",LL,"\n")
+ converge <- TRUE
+ }
}
class(object) <- "depmix.fitted"
Modified: trunk/R/allGenerics.R
===================================================================
--- trunk/R/allGenerics.R 2008-03-13 00:36:20 UTC (rev 81)
+++ trunk/R/allGenerics.R 2008-03-17 15:38:32 UTC (rev 82)
@@ -37,7 +37,7 @@
setGeneric("getdf",function(object) standardGeneric("getdf"))
-setGeneric("GLMresponse", function(formula, ...) standardGeneric("GLMresponse"))
+setGeneric("GLMresponse", function(formula, ... ) standardGeneric("GLMresponse"))
setGeneric("transInit", function(formula, ... ) standardGeneric("transInit"))
Modified: trunk/R/depmix.R
===================================================================
--- trunk/R/depmix.R 2008-03-13 00:36:20 UTC (rev 81)
+++ trunk/R/depmix.R 2008-03-17 15:38:32 UTC (rev 82)
@@ -40,7 +40,7 @@
setGeneric("depmix", function(response=any, transition=any, ...) standardGeneric("depmix"))
setMethod("depmix",
- signature(response = "list", transition= "list"),
+ signature(response = "list", transition= "list"),
function(response, transition, prior, ntimes=NULL, stationary=TRUE, ...) {
nstates <- length(response)
@@ -89,7 +89,7 @@
#
setMethod("depmix",
- signature(response="ANY",transition="formula"),
+ signature(response="ANY",transition="formula"),
function(response,data=NULL,nstates,transition,family=gaussian(),prior=~1,initdata=NULL,
respstart=NULL,trstart=NULL,instart=NULL,ntimes=NULL, ...) {
@@ -125,7 +125,7 @@
)
setMethod("depmix",
- signature(response="ANY",transition="missing"),
+ signature(response="ANY",transition="missing"),
function(response,data=NULL,nstates,transition=~1,family=gaussian(),prior=~1,initdata=NULL,
respstart=NULL,trstart=NULL,instart=NULL,ntimes=NULL, ...) {
Modified: trunk/R/depmix.fitted.R
===================================================================
--- trunk/R/depmix.fitted.R 2008-03-13 00:36:20 UTC (rev 81)
+++ trunk/R/depmix.fitted.R 2008-03-17 15:38:32 UTC (rev 82)
@@ -172,7 +172,6 @@
setMethod("summary","depmix.fitted",
function(object) {
- cat("Convergence info:",object at message,"\n")
cat("Initial state probabilties model \n")
print(object at prior)
cat("\n")
Modified: trunk/R/responses.R
===================================================================
--- trunk/R/responses.R 2008-03-13 00:36:20 UTC (rev 81)
+++ trunk/R/responses.R 2008-03-17 15:38:32 UTC (rev 82)
@@ -53,7 +53,7 @@
setMethod("GLMresponse",
signature(formula="formula"),
- function(formula,family,data,pstart=NULL,fixed=NULL,prob=TRUE) {
+ function(formula,data=NULL,family=gaussian(),pstart=NULL,fixed=NULL,prob=TRUE) {
call <- match.call()
mf <- match.call(expand.dots = FALSE)
m <- match(c("formula", "data"), names(mf), 0)
@@ -148,7 +148,7 @@
# are no covariates (and there are by definition no responses ...)
setMethod("transInit",
signature(formula="formula"),
- function(formula,family=multinomial(),data,nstates,pstart=NULL,prob=TRUE,fixed=NULL) {
+ function(formula,nstates,data=NULL,family=multinomial(),pstart=NULL,prob=TRUE,fixed=NULL) {
call <- match.call()
mf <- match.call(expand.dots = FALSE)
m <- match(c("formula", "data"), names(mf), 0)
Modified: trunk/man/balance.Rd
===================================================================
--- trunk/man/balance.Rd 2008-03-13 00:36:20 UTC (rev 81)
+++ trunk/man/balance.Rd 2008-03-17 15:38:32 UTC (rev 82)
@@ -1,13 +1,21 @@
+\name{balance}
-\name{balance}
\docType{data}
+
\alias{balance}
\title{Balance Scale Data}
+
\description{Balance scale data of four distance items from 779 subjects.}
+
\usage{data(balance)}
+
\format{Data.frame.}
+
\source{Jansen ... 2001}
+
\details{}
+
\references{Articles}
+
\keyword{datasets}
Modified: trunk/man/depmix-class.Rd
===================================================================
--- trunk/man/depmix-class.Rd 2008-03-13 00:36:20 UTC (rev 81)
+++ trunk/man/depmix-class.Rd 2008-03-17 15:38:32 UTC (rev 82)
@@ -1,41 +1,61 @@
\name{depmix-class}
+
\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{prior}:}{\code{transInit} object.}
- \item{\code{dens}:}{Array of dimension sum(ntimes)*nresp*nstates
- providing the densities of the observed responses for each state.}
- \item{\code{trDens}:}{Array of dimension \code{sum(ntimes)}*nstates
- providing the probability of a state transition depending on the
- predictors.}
- \item{\code{init}}{Array of dimension \code{length(ntimes)}*nstates with
- the current predictions for the initial state probabilities.}
- \item{\code{stationary}}{Logical indicating whether the transitions are
- time-dependent or not; for internal use.}
- \item{\code{ntimes}}{A vector containing the lengths of independent time
- series; if data is provided, sum(ntimes) must be equal to
- nrow(data).}
- \item{\code{nstates}}{The number of states of the model.}
- \item{\code{nresp}}{The number of independent responses.}
- \item{\code{npars}}{The 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.}
+
+ \item{\code{response}:}{List of list of \code{response} objects.}
+
+ \item{\code{transition}}{List of \code{transInit} objects.}
+
+ \item{\code{prior}:}{\code{transInit} object.}
+
+ \item{\code{dens}:}{Array of dimension sum(ntimes)*nresp*nstates
+ providing the densities of the observed responses for each state.}
+
+ \item{\code{trDens}:}{Array of dimension \code{sum(ntimes)}*nstates
+ providing the probability of a state transition depending on the
+ predictors.}
+
+ \item{\code{init}:}{Array of dimension \code{length(ntimes)}*nstates with
+ the current predictions for the initial state probabilities.}
+
+ \item{\code{stationary}:}{Logical indicating whether the transitions are
+ time-dependent or not; for internal use.}
+
+ \item{\code{ntimes}:}{A vector containing the lengths of independent time
+ series; if data is provided, sum(ntimes) must be equal to
+ nrow(data).}
+
+ \item{\code{nstates}:}{The number of states of the model.}
+
+ \item{\code{nresp}:}{The number of independent responses.}
+
+ \item{\code{npars}:}{The 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.}
+
}
}
+
\section{Accessor Functions}{
The following functions should be used for accessing the corresponding
slots:
@@ -46,5 +66,7 @@
\item{\code{ntimes}:}{The vector of independent time series lengths.}
}
}
+
\author{Ingmar Visser}
+
\keyword{classes}
Modified: trunk/man/depmix.Rd
===================================================================
--- trunk/man/depmix.Rd 2008-03-13 00:36:20 UTC (rev 81)
+++ trunk/man/depmix.Rd 2008-03-17 15:38:32 UTC (rev 82)
@@ -1,14 +1,22 @@
\name{depmix}
+\alias{depmixS4}
\alias{depmix}
+
\alias{logLik}
\alias{logLik,depmix-method}
+
\alias{AIC}
\alias{AIC,depmix-method}
+
\alias{BIC}
\alias{BIC,depmix-method}
+
+\alias{npar}
+\alias{npar,depmix-method}
+
\alias{freepars}
\alias{freepars,depmix-method}
@@ -18,6 +26,9 @@
\alias{getpars}
\alias{getpars,depmix-method}
+\alias{show,depmix-method}
+\alias{summary,depmix-method}
+
\title{Dependent Mixture Model Specifiction}
\description{
@@ -26,21 +37,25 @@
dependent mixture model, or 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,...)
+ \S4method{summary}{depmix}(object)
\S4method{logLik}{depmix}(object)
\S4method{AIC}{depmix}(object)
\S4method{BIC}{depmix}(object)
+
+ \S4method{npar}{depmix}(object)
\S4method{freepars}{depmix}(object)
- \S4method{freepars}{depmix}(object)
\S4method{setpars}{depmix}(object,which="pars",...)
\S4method{getpars}{depmix}(object,which="pars",...)
}
+
\arguments{
\item{object}{An object with class \code{depmix}.}
@@ -118,10 +133,11 @@
\code{\link[depmix]{depmix.fit}} function.
}
+
\value{
-\code{depmix} returns an object of class \code{depmix} which has print and
-summary methods. It has the following slots:
+\code{depmix} returns an object of class \code{depmix} which has the
+following slots:
\item{response}{A list of a list of response models; the first
index runs over states; the second index runs over the independent
@@ -152,9 +168,9 @@
parameters, in particular in the multinomial models for the
transitions and prior.}
-\code{logLik}, \code{AIC}, and \code{BIC} return the respective associated
-with the current parameter values. \code{nobs} returns the number of
-observations, ie \code{sum(ntimes)} that is used in computing the
+\code{logLik}, \code{AIC}, and \code{BIC} return the respective values
+associated with the current parameter values. \code{nobs} returns the
+number of observations, ie \code{sum(ntimes)} that is used in computing the
\code{BIC}. \code{npar} returns the number of paramters of a model;
\code{freepars} returns the number of non-fixed parameters.
@@ -185,6 +201,7 @@
depmix(list(rt~1,corr~1),data=speed,nstates=2,family=list(gaussian(),multinomial()))
}
-\keyword{models}
+\keyword{methods}
+
Modified: trunk/man/depmix.fit.Rd
===================================================================
--- trunk/man/depmix.fit.Rd 2008-03-13 00:36:20 UTC (rev 81)
+++ trunk/man/depmix.fit.Rd 2008-03-17 15:38:32 UTC (rev 82)
@@ -1,13 +1,16 @@
\name{fit}
+
\docType{method}
+
\alias{fit}
\alias{depmix.fit}
\alias{fit,depmix-method}
+
\alias{llratio}
\alias{llratio,depmix-method}
\alias{likelihoodratio}
-\title{Method fit}
+\title{Fit depmix models}
\description{\code{fit} optimizes parameters of depmix models, possibly
subject to general linear (in)equality constraints.}
@@ -17,10 +20,13 @@
\S4method{fit}{depmix}(object, w=NULL, fixed=NULL, equal=NULL, conrows=NULL,
conrows.upper=0, conrows.lower=0, method=NULL,...)
- llratio(object,object,...)
+ llratio(basemodel,constrainedmodel,...)
+
}
+
\arguments{
- \item{object}{An object of class "depmix".}
+ \item{object}{An object of class \code{depmix}.}
+ \item{basemodel, constrainedmodel}{Objects of class \code{depmix.fitted}.}
\item{w}{Weights??? What's this argument doing here? It's not being
used.}
\item{fixed}{Vector of mode logical indicating which parameters should
@@ -33,6 +39,7 @@
constraints.}
\item{...}{Not used currently.}
}
+
\details{
The method fits depmix models by the EM algorithm if there are no
linear constraints on the parameters and if the transition model has
@@ -68,6 +75,7 @@
of freedom.
}
+
\value{
\code{fit} returns an object of class \code{depmix.fitted} which contains
the original depmix object, and further has slots:
@@ -81,6 +89,7 @@
estimates.
}
+
\examples{
data(speed)
# 2-state model on the RTs of the speed data with random
@@ -93,5 +102,7 @@
# to see the parameters
summary(mod1)
}
+
\author{Ingmar Visser}
-\keyword{classes}
+
+\keyword{methods}
Modified: trunk/man/response-class.Rd
===================================================================
--- trunk/man/response-class.Rd 2008-03-13 00:36:20 UTC (rev 81)
+++ trunk/man/response-class.Rd 2008-03-17 15:38:32 UTC (rev 82)
@@ -1,11 +1,18 @@
\name{response-class}
+
\docType{class}
+
\alias{response-class}
+\alias{getdf}{response-method}
+
\title{Class "response"}
+
\description{A \code{\link{response}} model for depmix models.}
+
\arguments{
\item{object}{An object of class "response".}
}
+
\section{Slots}{
\describe{
\item{\code{parameters}:}{A (named) list of parameters.}
@@ -13,15 +20,17 @@
are fixed.}
\item{\code{y}:}{A matrix with the actual response; possibly
multivariate.}
- \item{\code{x}:}{A design matrix.}
+ \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.
+ models such as glm based responses or multinomial responses.
}
+
\section{Accessor Functions}{
The following functions should be used for accessing the corresponding
slots:
@@ -30,5 +39,7 @@
\item{\code{getdf}:}{The number of non-fixed parameters.}
}
}
+
\author{Ingmar Visser}
+
\keyword{classes}
Modified: trunk/man/response.Rd
===================================================================
--- trunk/man/response.Rd 2008-03-13 00:36:20 UTC (rev 81)
+++ trunk/man/response.Rd 2008-03-17 15:38:32 UTC (rev 82)
@@ -1,36 +1,34 @@
\name{response}
+
\docType{method}
+
\alias{response}
-\alias{predict}
-\alias{predict,response-method}
-\alias{dens}
-\alias{dens,response-method}
-\alias{npar}
-\alias{npar,response-method}
\alias{transInit}
\alias{GLMresponse}
-\alias{transInit,response-method}
-\alias{GLMresponse,response-method}
+
+\alias{transInit,formula,GLMresponse-method}
+\alias{GLMresponse,formula,GLMresponse-method}
+
\title{Methods for creating depmix response models}
+
\description{Create \code{\link[depmix]{response}} models.}
+
\usage{
- GLMresponse(formula, family, data, pstart=NULL, fixed=NULL)
+ GLMresponse(formula, data=NULL, family=gaussian(), pstart=NULL, fixed=NULL)
- transInit(formula, family=multinomial(), data, nstates,
+ transInit(formula, nstates, data=NULL, family=multinomial(),
pstart=NULL, prob=TRUE, fixed=NULL)
-
- npar(object,...)
+
}
+
\arguments{
- \item{object}{An object of class \code{response} or one of its
- descendents.}
\item{formula}{A model formula.}
+ \item{nstates}{The number of states of the model.}
\item{family}{A family object; currently only multinomial() and
gaussian() are allowed options.}
\item{data}{An optional data.frame to interpret the variables from the
formula argument in.}
- \item{nstates}{The number of states of the model.}
\item{pstart}{Starting values for the coefficients and other
parameters, ie the standard deviation for the gaussian() family.}
\item{fixed}{Logical vector indicating which paramters are to be fixed.}
@@ -38,6 +36,7 @@
multinomial() family models are probabilities or logistic
parameters (see details).}
}
+
\details{
Both methods use the familiar formula interface from linear and general
@@ -55,14 +54,17 @@
observed.
}
+
\value{
\code{GLMresponse} and \code{transInit} return objects of class
\code{GLMresponse} and \code{transInit} respectively; both classes
extend the \code{\link[depmix]{response-class}}.
- 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.
+ 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.
}
-\author{Ingmar Visser}
-\keyword{classes}
+
+\author{Ingmar Visser}
+
+\keyword{methods}
Modified: trunk/man/speed.Rd
===================================================================
--- trunk/man/speed.Rd 2008-03-13 00:36:20 UTC (rev 81)
+++ trunk/man/speed.Rd 2008-03-17 15:38:32 UTC (rev 82)
@@ -1,9 +1,11 @@
+\name{speed}
-\name{speed}
\docType{data}
+
\alias{speed}
\title{Speed Accuracy Switching Data}
+
\description{
This data set is a bivariate series of reaction times and accuracy
@@ -18,8 +20,11 @@
Maas et al, 2005}.
}
+
\usage{data(speed)}
+
\format{Data.frame}
+
\source{
Han L. J. Van der Maas, Conor V. Dolan and Peter C. M. Molenaar (2005),
@@ -27,4 +32,5 @@
Reaction Time Tasks. \emph{Manuscript in preparation}.
}
+
\keyword{datasets}
More information about the depmix-commits
mailing list