[Depmix-commits] r327 - trunk/man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jan 28 17:02:21 CET 2010


Author: ingmarvisser
Date: 2010-01-28 17:02:21 +0100 (Thu, 28 Jan 2010)
New Revision: 327

Modified:
   trunk/man/makeDepmix.Rd
Log:
Added an example of specifying a model with a multivariate normal response.

Modified: trunk/man/makeDepmix.Rd
===================================================================
--- trunk/man/makeDepmix.Rd	2010-01-28 16:01:18 UTC (rev 326)
+++ trunk/man/makeDepmix.Rd	2010-01-28 16:02:21 UTC (rev 327)
@@ -107,24 +107,48 @@
 )
 
 trstart=c(0.9,0.1,0.1,0.9)
-
 transition <- list()
 transition[[1]] <- transInit(~1,nstates=2,data=data.frame(1),pstart=c(trstart[1:2]))
 transition[[2]] <- transInit(~1,nstates=2,data=data.frame(1),pstart=c(trstart[3:4]))
 
 instart=c(0,1)
 inMod <- transInit(~1,ns=2,ps=instart,data=data.frame(rep(1,3)))
-
 mod <- makeDepmix(response=rModels,transition=transition,prior=inMod,ntimes=attr(speed,"ntimes"))
 
-logLik(mod)
+fm1 <- fit(mod)
+fm1
+summary(fm1)
 
-fm <- fit(mod)
+# generate data from two different multivariate normal distributions
+m1 <- c(0,1)
+sd1 <- matrix(c(1,0.7,.7,1),2,2)
+m2 <- c(1,0)
+sd2 <- matrix(c(2,.1,.1,1),2,2)
+y1 <- mvrnorm(50,m1,sd1)
+y2 <- mvrnorm(50,m2,sd2)
+y <- rbind(y1,y2)
 
-fm 
+# now use makeDepmix to create a depmix model for this bivariate normal timeseries
+rModels <-  list()
+rModels[[1]] <- list(MVNresponse(y~1))
+rModels[[2]] <- list(MVNresponse(y~1))
 
-summary(fm)
+trstart=c(0.9,0.1,0.1,0.9)
 
+transition <- list()
+transition[[1]] <- transInit(~1,nstates=2,data=data.frame(1),pstart=c(trstart[1:2]))
+transition[[2]] <- transInit(~1,nstates=2,data=data.frame(1),pstart=c(trstart[3:4]))
+
+instart=runif(2)
+inMod <- transInit(~1,ns=2,ps=instart,data=data.frame(1))
+
+mod <- makeDepmix(response=rModels,transition=transition,prior=inMod)
+
+fm2 <- fit(mod)
+# where is the switch point?
+plot(as.ts(posterior(fm2)[,1]))
+
+
 # in below example we add the exgaus distribution as a response model and fit
 # this instead of the gaussian distribution to the rt slot of the speed data
 # most of the actual computations for the exgaus distribution is done by calling
@@ -252,7 +276,6 @@
 )
 
 trstart=c(0.9,0.1,0.1,0.9)
-
 transition <- list()
 transition[[1]] <- transInit(~Pacc,nstates=2,data=speed,pstart=c(trstart[1:2],0,0))
 transition[[2]] <- transInit(~Pacc,nstates=2,data=speed,pstart=c(trstart[3:4],0,0))
@@ -262,12 +285,9 @@
 
 mod <- makeDepmix(response=rModels,transition=transition,prior=inMod,ntimes=attr(speed,"ntimes"),stat=FALSE)
 
-logLik(mod)
+fm3 <- fit(mod)
+summary(fm3)
 
-fm1 <- fit(mod)
-
-summary(fm1)
-
 }
 
 \keyword{methods}



More information about the depmix-commits mailing list