[Depmix-commits] r257 - in trunk: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Feb 18 13:06:04 CET 2009
Author: ingmarvisser
Date: 2009-02-18 13:06:04 +0100 (Wed, 18 Feb 2009)
New Revision: 257
Modified:
trunk/NEWS
trunk/R/freepars.R
trunk/man/responses.Rd
Log:
Changed order of examples in responses.Rd to match the order of models listed, and added some comments
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2009-02-18 11:59:24 UTC (rev 256)
+++ trunk/NEWS 2009-02-18 12:06:04 UTC (rev 257)
@@ -1,23 +1,26 @@
Changes in depmixS4 version 0.2-1
- o Fixed a bug in the Viterbi algorithm used to compute posterior states
+ o fixed a bug in the Viterbi algorithm used to compute posterior states
- o Restructured test files somewhat
+ o restructured test files somewhat
- o Fixed a bug in the use of the conrows argument in the fit function (a missing
+ o fixed a bug in the use of the conrows argument in the fit function (a missing
drop=FALSE statement)
- o Updated help files for mix classes
+ o updated help files for mix classes
- o Fixed a bug in setting the starting values of regression coefficients in
+ o fixed a bug in setting the starting values of regression coefficients in
prior and transInit models with covariates (thanks to Verena Schmittmann
for reporting this)
- o Added newx argument to predict function of transInit objects, to be used
+ o added newx argument to predict function of transInit objects, to be used
for predicting probabilities depending on covariates (useful in eg plotting
transition probabilities as function of a covariate)
+ o added example of the use of conrows argument in fitting functions and other
+ minor updates in documentation
+
o
Changes in depmixS4 version 0.2-0
Modified: trunk/R/freepars.R
===================================================================
--- trunk/R/freepars.R 2009-02-18 11:59:24 UTC (rev 256)
+++ trunk/R/freepars.R 2009-02-18 12:06:04 UTC (rev 257)
@@ -27,7 +27,7 @@
setMethod("nlin","mix.fitted",
function(object) {
conMat <- object at conMat[which(object at lin.lower==object at lin.upper),,drop=FALSE]
- if(nrow(conMat==0) nlin <- 0
+ if(nrow(conMat==0)) nlin <- 0
else nlin <- qr(conMat)$rank
nlin
}
@@ -36,7 +36,7 @@
setMethod("nlin","depmix.fitted",
function(object) {
conMat <- object at conMat[which(object at lin.lower==object at lin.upper),,drop=FALSE]
- if(nrow(conMat==0) nlin <- 0
+ if(nrow(conMat==0)) nlin <- 0
else nlin <- qr(conMat)$rank
nlin
}
Modified: trunk/man/responses.Rd
===================================================================
--- trunk/man/responses.Rd 2009-02-18 11:59:24 UTC (rev 256)
+++ trunk/man/responses.Rd 2009-02-18 12:06:04 UTC (rev 257)
@@ -107,80 +107,57 @@
\examples{
- mod <- GLMresponse(rnorm(1000)~1)
-
- fit(mod)
-
- mod <- GLMresponse(sample(1:3,1000,rep=TRUE)~1,family=multinomial())
-
- fit(mod)
-
- colSums(mod at y)/1000
-
- x <- sample(0:1,1000,rep=TRUE)
-
- mod <- GLMresponse(sample(1:3,1000,rep=TRUE)~x,family=multinomial(),pstart=c(0.33,0.33,0.33,0,0,1))
-
- mod at y <- simulate(mod)
-
- fit(mod)
-
- colSums(mod at y[which(x==0),])/length(which(x==0))
-
- colSums(mod at y[which(x==1),])/length(which(x==1))
-
+ # binomial response model
x <- rnorm(1000)
-
library(boot)
-
p <- inv.logit(x)
-
ss <- rbinom(1000,1,p)
-
mod <- GLMresponse(cbind(ss,1-ss)~x,family=binomial())
-
fit(mod)
-
glm(cbind(ss,1-ss)~x, family=binomial)
- x <- abs(rnorm(1000,2))
-
- res <- rpois(1000,x)
-
- mod <- GLMresponse(res~x,family=poisson())
-
- fit(mod)
-
- glm(res~x, family=poisson)
-
+ # gamma response model
x=runif(1000,1,5)
-
res <- rgamma(1000,x)
-
## note that gamma needs proper starting values which are not
## provided by depmixS4 (even with them, this may produce warnings)
mod <- GLMresponse(res~x,family=Gamma(),pst=c(0.8,1/0.8))
-
fit(mod)
-
glm(res~x,family=Gamma)
- mn <- c(1,2,3)
+ # multinomial response model
+ x <- sample(0:1,1000,rep=TRUE)
+ mod <- GLMresponse(sample(1:3,1000,rep=TRUE)~x,family=multinomial(),pstart=c(0.33,0.33,0.33,0,0,1))
+ mod at y <- simulate(mod)
+ fit(mod)
+ colSums(mod at y[which(x==0),])/length(which(x==0))
+ colSums(mod at y[which(x==1),])/length(which(x==1))
+ # multivariate normal response model
+ mn <- c(1,2,3)
sig <- matrix(c(1,.5,0,.5,1,0,0,0,2),3,3)
-
y <- mvrnorm(1000,mn,sig)
-
mod <- MVNresponse(y~1)
-
fit(mod)
-
colMeans(y)
-
var(y)
+ # normal (gaussian) response model
+ y <- rnorm(1000)
+ mod <- GLMresponse(y~1)
+ fm <- fit(mod)
+ cat("Test gaussian fit: ", all.equal(getpars(fm),c(mean(y),sd(y)),check=FALSE))
+
+
+ # poisson response model
+ x <- abs(rnorm(1000,2))
+ res <- rpois(1000,x)
+ mod <- GLMresponse(res~x,family=poisson())
+ fit(mod)
+ glm(res~x, family=poisson)
+
}
-
+
\author{Maarten Speekenbrink & Ingmar Visser}
\keyword{models}
More information about the depmix-commits
mailing list