[Depmix-commits] r137 - in trunk: . R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Jun 9 13:55:55 CEST 2008
Author: ingmarvisser
Date: 2008-06-09 13:55:55 +0200 (Mon, 09 Jun 2008)
New Revision: 137
Added:
trunk/R/responseGLMGAMMA.R
Removed:
trunk/R/responseGLMGAMMA.r
Modified:
trunk/depmixNew-test2.R
Log:
Changed responseGLMGAMMA.r to responseGLMGAMMA.R (note the capital)
Added: trunk/R/responseGLMGAMMA.R
===================================================================
--- trunk/R/responseGLMGAMMA.R (rev 0)
+++ trunk/R/responseGLMGAMMA.R 2008-06-09 11:55:55 UTC (rev 137)
@@ -0,0 +1,35 @@
+setClass("GAMMAresponse",contains="GLMresponse")
+
+# method 'fit'
+# use: in EM (M step)
+# returns: (fitted) response with (new) estimates of parameters
+
+# methods 'logDens' & dens
+# use: instead of density slot in rModel
+# returns: matrix with log(p(y|x,parameters))
+setMethod("logDens","GAMMAresponse",
+ function(object) {
+ dpois(x=object at y,shape=predict(object),log=TRUE)
+ }
+)
+
+setMethod("dens","GAMMAresponse",
+ function(object,log=FALSE) {
+ dpois(x=object at y,shape=predict(object),log=log)
+ }
+)
+
+setMethod("simulate",signature(object="GAMMAresponse"),
+ function(object,nsim=1,seed=NULL,time) {
+ if(missing(time)) {
+ # draw in one go
+ shape <- predict(object)
+ } else {
+ shape <- predict(object)[time,]
+ }
+ nt <- nrow(shape)
+ response <- rgamma(nt*nsim,shape=shape)
+ if(nsim > 1) response <- matrix(response,ncol=nsim)
+ return(response)
+ }
+)
Deleted: trunk/R/responseGLMGAMMA.r
===================================================================
--- trunk/R/responseGLMGAMMA.r 2008-05-29 10:50:55 UTC (rev 136)
+++ trunk/R/responseGLMGAMMA.r 2008-06-09 11:55:55 UTC (rev 137)
@@ -1,35 +0,0 @@
-setClass("GAMMAresponse",contains="GLMresponse")
-
-# method 'fit'
-# use: in EM (M step)
-# returns: (fitted) response with (new) estimates of parameters
-
-# methods 'logDens' & dens
-# use: instead of density slot in rModel
-# returns: matrix with log(p(y|x,parameters))
-setMethod("logDens","GAMMAresponse",
- function(object) {
- dpois(x=object at y,shape=predict(object),log=TRUE)
- }
-)
-
-setMethod("dens","GAMMAresponse",
- function(object,log=FALSE) {
- dpois(x=object at y,shape=predict(object),log=log)
- }
-)
-
-setMethod("simulate",signature(object="GAMMAresponse"),
- function(object,nsim=1,seed=NULL,time) {
- if(missing(time)) {
- # draw in one go
- shape <- predict(object)
- } else {
- shape <- predict(object)[time,]
- }
- nt <- nrow(shape)
- response <- rgamma(nt*nsim,shape=shape)
- if(nsim > 1) response <- matrix(response,ncol=nsim)
- return(response)
- }
-)
Modified: trunk/depmixNew-test2.R
===================================================================
--- trunk/depmixNew-test2.R 2008-05-29 10:50:55 UTC (rev 136)
+++ trunk/depmixNew-test2.R 2008-06-09 11:55:55 UTC (rev 137)
@@ -22,6 +22,7 @@
logLik(mod)
mod1 <- fit(mod)
+
ll <- logLik(mod1)
#
@@ -42,6 +43,8 @@
cat("Test 1: ", ll, "(loglike of speed data with covariate, hopefully better than 300.5701) \n")
+mod2 <- fit(mod,meth="EM")
+
post <- cbind(viterbi(mod1),speed$Pacc)
More information about the depmix-commits
mailing list