Forum: help
Monitor Forum | Start New ThreadRE: Using Surveillance for monthly or daily d [ Reply ] By: Michael Höhle on 2011-05-20 17:50 | [forum:4469] |
Hello, The post was answered by email (had missed it here). There was a small bug in algo.bayes, which was fixed in 2009. Current versions of the surveillance package should work fine. Jus for the greater audience I take the chance to post the requested code for algo.bayes/bayes: library("surveillance") #source("~/Surveillance/surveillance/pkg/R/sts.R") set.seed(123) x <- rpois(8*365,lambda=10) dp <- create.disProg(week=1:length(x), observed=x, state=rep(0,length(x)),freq=365,start=c(2002,1)) par(mar=c(6,4,4,2)) bayes <- bayes(disProg2sts(dp), control = list(range = 2900:2920, b= 5, w=10, alpha=0.005)) epoch(bayes) <- epoch(bayes) - min(epoch(bayes)) + 1 plot(bayes, legend.opts=NULL,axes=FALSE,xlab="") axis(2) axis(1, at=1:nrow(bayes), labels=paste(year(bayes),"-",epochInYear(bayes),sep=""),las=2) #Put some NAs in the data #source("~/Surveillance/surveillance/pkg/R/algo_bayes.R") dp$observed[1:(4*365),] <- NA bayes <- bayes(disProg2sts(dp), control = list(range = 2900:2920, b= 5, w=10, alpha=0.005)) epoch(bayes) <- epoch(bayes) - min(epoch(bayes)) + 1 plot(bayes, legend.opts=NULL,axes=FALSE,xlab="") axis(2) axis(1, at=1:nrow(bayes), labels=paste(year(bayes),"-",epochInYear(bayes),sep=""),las=2) #Simulate 5 time series x <- matrix(rpois(8*365*5,lambda=10),ncol=5) dp <- new("sts", epoch=1:nrow(x), observed=x, state=rep(0,length(x)),freq=365,start=c(2002,1)) bayes <- bayes(dp, control = list(range = 2900:2920, b= 5, w=10, alpha=0.005)) hookFunc <- function() { epoch(x) <- epoch(x) - min(epoch(x)) + 1 axis(1, at=1:nrow(x), labels=paste(year(x),"-",epochInYear(x),sep=""),las=2) } #Draw axis by the hook function plot(bayes, legend.opts=NULL,axes=FALSE,xlab="", hookFunc=hookFunc) |
RE: Using Surveillance for monthly or daily d [ Reply ] By: Chris Ryan on 2009-06-17 02:07 | [forum:1626] |
I was happy to see this post about daily surveillance, because that is exactly what I am trying to do, with daily visit counts at walk-in clinics. Using the example provided, but modified to daily data, I did this: set.seed(123) x <- rpois(8*365,lambda=10) dp <- create.disProg(week=1:length(x), observed=x, state=rep(0,length(x)),freq=365,start=c(2002,1)) If I understand correctly, this should yield daily counts from 1 Jan 2002 to 31 Dec 2009 (roughly, since leap years aren't accomodated.) Could you provide example code for creating an algo object, such as algo.cdc or algo.bayes, for the latest month or so, with plot? When I try it, my x-axis covers only the left half of the graph, and the x-axis labels only go up to 2003 or so. Thanks. --Chris Ryan |
Using Surveillance for monthly or daily data [ Reply ] By: Michael Höhle on 2007-09-20 18:39 | [forum:211] |
You can of surveillance for monthly or daily data by changing the "freq" argument of the disProg object: 12 for monthly, 365 for daily (no handling of leap years) As an example: set.seed(123) x <- rpois(8*12,lambda=10) dp <- create.disProg(week=1:length(x), observed=x, state=rep(0,length(x)),freq=12,start=c(2002,1)) #or as S4 class dp <- disProg2sts(dp) plot(dp,legend=list(x="top",horiz=TRUE)) |