[Depmix-commits] r69 - trunk
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Mar 7 15:20:46 CET 2008
Author: ingmarvisser
Date: 2008-03-07 15:20:46 +0100 (Fri, 07 Mar 2008)
New Revision: 69
Removed:
trunk/depmixS4.R
Modified:
trunk/DESCRIPTION
Log:
Deleted all redundant files
Modified: trunk/DESCRIPTION
===================================================================
--- trunk/DESCRIPTION 2008-03-07 14:14:55 UTC (rev 68)
+++ trunk/DESCRIPTION 2008-03-07 14:20:46 UTC (rev 69)
@@ -1,8 +1,8 @@
Package: depmixS4
-Version: 0.0-1
-Date: 2008-03-01
+Version: 0.1
+Date: 2008-03-07
Title: Dependent Mixture Models
-Author: Ingmar Visser <i.visser at uva.nl>, Maarten Speekenbrink
+Author: Ingmar Visser <i.visser at uva.nl>, Maarten Speekenbrink <m.speekenbrink at ucl.ac.uk>
Maintainer: Ingmar Visser <i.visser at uva.nl>
Depends: R (>= 2.6.0), MASS
Suggests: Rdonlp2
Deleted: trunk/depmixS4.R
===================================================================
--- trunk/depmixS4.R 2008-03-07 14:14:55 UTC (rev 68)
+++ trunk/depmixS4.R 2008-03-07 14:20:46 UTC (rev 69)
@@ -1,87 +0,0 @@
-
-# the main function to call
-
-# reponse is a list of formulae for each of the response variables,
-# defining a glm type equation for each of the variables conditional on the
-# state, these formulae may be one-sided, ie only having a response and no
-# covariates, family is a list of density functions for the response
-# variables
-
-# init is a one-sided formula for the covariates on the initial state
-# probabilities or class probabilities which are modelled as a multinomial
-# logistic, transition is a one-sided formula for the covariates on the
-# transition parameters
-
-# data is an optional dataframe to interpret the variables and
-# covariates in; ntimes is a list of individual sequence lengths
-
-# ..start are the starting values for the parameters
-# conpat is a vector specifying general linear constraints on the parameters
-#
-# should return: an optimized model
-# return: the likelihood of the model
-#
-
-depmix <- function(rModels,transition=~1,init=~1,data=NULL,initdata=NULL,
- trstart=NULL,instart=NULL,prob=TRUE,conpat=NULL,ntimes=NULL,base=1,...) {
- # rModels should be a list of lists, dimension rModels[[nstates]][[nresp]], with
- # each element of class "rModel"
-
- # maybe move all these checks and the construction of the transition models to hmModel as well
- # check wheter everything is well-formed and all that
- nstates <- length(rModels)
- nresp <- length(rModels[[1]])
-
- if(!all(lapply(unlist(rModels),is,"rModel"))) stop("'rModels' must be of class 'rModel'")
- if(!all(lapply(rModels, length)==nresp)) stop("number of response variables in rModels differs")
-
- tst <- FALSE
- if(!is.null(trstart)) {
- tst <- TRUE
- trstart <- matrix(trstart,nstates,byrow=TRUE)
- }
-
- # it may also be possible to do something like this for rModels, especially if
- # they all have the same form, which would usually be the case anyway
- trModel <- list()
- stationary=FALSE
- if(transition==~1) stationary=TRUE
- for(i in 1:nstates) {
- if(tst) {
- if(stationary) trModel[[i]] <- trinModel(transition,multinomial(base=base),data=data[1,,drop=FALSE],nstates,pstart=trstart[i,],prob=prob)
- else trModel[[i]] <- trinModel(transition,multinomial(base=base),data=data,nstates,pstart=trstart[i,],prob=prob)
- } else {
- if(stationary) trModel[[i]] <- trinModel(transition,multinomial(base=base),data=data[1,,drop=FALSE],nstates,prob=FALSE)
- else trModel[[i]] <- trinModel(transition,multinomial(base=base),data=data,nstates,prob=FALSE)
- }
- }
-
- if(is.null(attributes(data)$ntimes)&is.null(ntimes)) {
- ntimes <- nrow(data)
- } else {
- if(is.null(ntimes)) ntimes <- attributes(data)$ntimes
- }
-
- # initial probabilities model, depending on covariates init(=~1 by default)
- if(init==~1) {
- if(is.null(instart)) {
- initModel <- trinModel(init,data=data.frame(rep(1,length(ntimes))),nst=nstates,family=multinomial())
- } else {
- initModel <- trinModel(init,data=data.frame(rep(1,length(ntimes))),nst=nstates,family=multinomial(),pstart=instart)
- }
- } else {
- if(is.null(initdata)) {
- stop("'Argument initdata missing while the init model is non-trivial")
- } else {
- if(is.null(instart)) {
- initModel <- trinModel(init,data=initdata,nst=nstates,family=multinomial())
- } else {
- initModel <- trinModel(init,data=initdata,nst=nstates,family=multinomial(),pstart=instart)
- }
- }
- }
-
- mod <- hmModel(rModels,trModel,initModel,ntimes,STATION=stationary)
-
- return(mod)
-}
More information about the depmix-commits
mailing list