R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("sspir-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('sspir') Loading required package: MASS ------------------------------------------------------------- sspir: State Space Models in R , version 0.1.0 A glm-like formula language to define dynamic generalized linear models (state space models). Includes functions for Kalman filtering and smoothing. Read help(sspir) to get started. Authors: Claus Dethlefsen and Søren Lundbye-Christensen Maintained by Claus Dethlefsen Built: R 2.1.1; ; 2005-07-13 19:56:34; unix ------------------------------------------------------------- > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "SS" > > ### * SS > > flush(stderr()); flush(stdout()) > > ### Name: SS > ### Title: Representation of Gaussian State Space Model > ### Aliases: SS plot.SS print.SS > ### Keywords: models > > ### ** Examples > > time <- 1:length(UKgas) > gasmodel <- ssm( log10(UKgas) ~ -1+ + tvar(polytime(time,1))+ + tvar(sumseason(time,12)),time=time) > > gasmodel$ss$phi <- StructTS(log10(UKgas),type="BSM")$coef[c(4,1,2,3)] > > fit <- kfs(gasmodel) > > plot( ts( t(fit$m[1:3,]) ) ) > > > > cleanEx(); ..nameEx <- "kfs" > > ### * kfs > > flush(stderr()); flush(stdout()) > > ### Name: kfs > ### Title: (Iterated extended) Kalman smoother > ### Aliases: kfs kfs.ssm > ### Keywords: models > > ### ** Examples > > data(mumpsdat) > time <- 1:nrow(mumpsdat) > m3 <- ssm( mumps ~ -1 + tvar(polytime(time,1)) + + tvar(polytrig(time,12,1)), + family=poisson(link=log),time=time,data=mumpsdat) > m3$ss$phi["epsilon"] <- 0 > m3$ss$phi["polytime(time, 1)time0"] <- 0 > m3$ss$phi["polytime(time, 1)time1"] <- 0.0005 > m3$ss$phi["polytrig(time,12,1)"] <- 0.0001 > diag(m3$ss$C0) <- 1 > > m3.fit <- kfs(m3) > > > > cleanEx(); ..nameEx <- "ssm" > > ### * ssm > > flush(stderr()); flush(stdout()) > > ### Name: ssm > ### Title: Define state-space model in a glm-style call. > ### Aliases: ssm kfilter.ssm smoother.ssm > ### Keywords: models > > ### ** Examples > > data(vandrivers) > vd <- ssm( y ~ tvar(1) + seatbelt + sumseason(time,12), + time=time, family=poisson(link="log"), + data=vandrivers) > vd$ss$phi["(Intercept)"] <- exp(- 2*3.703307 ) > vd$ss$C0 <- diag(13)*1000 > vd.res <- kfs(vd) > > plot( ts( t(vd.res$m[1:3,]) )) > > attach(vandrivers) > plot(y,ylim=c(0,20)) > lines(exp(vd.res$m[1,]+vd.res$m[2,]*seatbelt),lwd=2 ) > > > > ### *