[Depmix-commits] r155 - in trunk: R man tests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jun 11 12:26:32 CEST 2008


Author: ingmarvisser
Date: 2008-06-11 12:26:32 +0200 (Wed, 11 Jun 2008)
New Revision: 155

Removed:
   trunk/tests/depmixNew-test2.R
Modified:
   trunk/R/depmixfit.R
   trunk/man/depmix.fit.Rd
Log:
Deleted depmixNew-test2.R as these are moved to a dontrun section in the examples of fit

Modified: trunk/R/depmixfit.R
===================================================================
--- trunk/R/depmixfit.R	2008-06-11 09:49:48 UTC (rev 154)
+++ trunk/R/depmixfit.R	2008-06-11 10:26:32 UTC (rev 155)
@@ -8,7 +8,7 @@
 		
 		# can/does EM deal with fixed constraints??? it should be possible for sure
  		if(is.null(method)) {
- 			if(is.null(equal)&is.null(conrows)) {
+ 			if(is.null(equal)&is.null(conrows)&is.null(fixed)) {
  				method="EM"
  			} else {
  				method="donlp"
Modified: trunk/man/depmix.fit.Rd
===================================================================
--- trunk/man/depmix.fit.Rd	2008-06-11 09:49:48 UTC (rev 154)
+++ trunk/man/depmix.fit.Rd	2008-06-11 10:26:32 UTC (rev 155)
@@ -117,17 +117,66 @@
 \examples{
 
 data(speed)
-# 2-state model on the RTs of the speed data with random 
+
+# 2-state model on rt and corr from speed data set with Pacc as covariate on the transition matrix
 # 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))
+tr=runif(6)
+trst=c(tr[1:2],0,tr[3:5],0,tr[6])
+mod <- depmix(list(rt~1,corr~1),data=speed,transition=~Pacc,nstates=2,family=list(gaussian(),multinomial()),
+	trstart=trst)
 # fit the model
 mod1 <- fit(mod)
 mod1 # to see the logLik and optimization information
 # to see the parameters
 summary(mod1)
 
+\dontrun{
+# NOTE: this requires Rdonlp2 package to be installed
 
+# FIX SOME PARAMETERS
+
+# get the starting values of this model to the optimized 
+# values of the previously fitted model to speed optimization
+
+pars <- c(unlist(getpars(mod1)))
+
+# constrain the initial state probs to be 0 and 1 
+# also constrain the guessing probs to be 0.5 and 0.5 
+# (ie the probabilities of corr in state 1)
+# change the ones that we want to constrain
+pars[2]=+Inf # this means the process will always start in state 2
+pars[14]=0 # the corr parameters in state 1 are now both 0, corresponding the 0.5 prob
+mod <- setpars(mod,pars)
+
+# fix the parameters by setting: 
+free <- c(0,0,rep(c(0,1),4),1,1,0,0,1,1,0,1)
+# fit the model
+mod2 <- fit(mod,fixed=!free)
+
+# likelihood ratio insignificant, hence mod2 better than mod1
+llratio(mod1,mod2)
+
+# NOW ADD SOME GENERAL LINEAR CONSTRAINTS
+
+# set the starting values of this model to the optimized 
+# values of the previously fitted model to speed optimization
+
+pars <- c(unlist(getpars(mod2)))
+mod <- setpars(mod,pars)
+
+# start with fixed and free parameters
+conpat <- c(0,0,rep(c(0,1),4),1,1,0,0,1,1,0,1)
+# constrain the beta's on the transition parameters to be equal
+conpat[4] <- conpat[8] <- 2
+conpat[6] <- conpat[10] <- 3
+
+mod3 <- fit(mod,equal=conpat)
+
+llratio(mod2,mod3)
+
+}
+
 data(balance)
 # four binary items on the balance scale task
 

Deleted: trunk/tests/depmixNew-test2.R
===================================================================
--- trunk/tests/depmixNew-test2.R	2008-06-11 09:49:48 UTC (rev 154)
+++ trunk/tests/depmixNew-test2.R	2008-06-11 10:26:32 UTC (rev 155)
@@ -1,82 +0,0 @@
-
-# 
-# Ingmar Visser & Maarten Speekenbrink, march 2008
-# 
-
-# 
-# test model with EM optimization
-# 
-
-rm(list=ls())
-
-require(depmixS4)
-
-data(speed)
-
-trstart=c(0.899,0.101,0,0,0.084,0.916,0,0)
-instart=c(0.5,0.5)
-resp <- c(5.52,0.202,0.472,0.528,6.39,0.24,0.098,0.902)
-
-mod <- depmix(list(rt~1,corr~1),data=speed,transition=~Pacc,nstates=2,family=list(gaussian(),multinomial()),
-	respstart=resp,trstart=trstart,instart=instart)
-
-mod1 <- fit(mod)
-
-ll <- logLik(mod1)
-
-cat("Test 1: ", ll, " hopefully better than 300.5701 \n")
-
-
-# 
-# NOW FIX SOME PARAMETERS
-# 
-
-# now constrain the initial state probs to be 0 and 1 
-# also constrain the guessing probs to be 0.5 and 0.5 
-
-# set the starting values of this model to the optimized 
-# values of the previously fitted model to speed optimization
-
-pars <- c(unlist(getpars(mod1)))
- 
-# set some to other values, ie the ones that we want to constrain
-
-pars[2]=+Inf pars[14]=0
-
-mod <- setpars(mod,pars) 
-
-# fix some parameter
-
-free <- c(0,0,rep(c(0,1),4),1,1,0,0,1,1,0,1)
-
-mod2 <- fit(mod,fixed=!free)
-
-llratio(mod1,mod2)
-
-cat("Test 2: likelihood ratio not significant, hence mod2 better than mod1.\n")
-
-# NOW ADD SOME GENERAL LINEAR CONSTRAINTS
-
-
-# set the starting values of this model to the optimized 
-# values of the previously fitted model to speed optimization
-
-pars <- c(unlist(getpars(mod2)))
-mod <- setpars(mod,pars)
-
-# start with fixed and free parameters
-conpat <- c(0,0,rep(c(0,1),4),1,1,0,0,1,1,0,1)
-# constrain the beta's on the transition parameters to be equal
-conpat[4] <- conpat[8] <- 2
-conpat[6] <- conpat[10] <- 3
-
-mod3 <- fit(mod,equal=conpat)
-
-llratio(mod2,mod3)
-
-cat("Test3: log Likelihood ratio significant, constraints not tenable.")
-
-
-
-
-


More information about the depmix-commits mailing list