Last updated on 2018-06-17 19:49:37 CEST.
Flavor | Version | Tinstall | Tcheck | Ttotal | Status | Flags |
---|---|---|---|---|---|---|
r-devel-linux-x86_64-debian-clang | 1.4-2 | 2.10 | 26.43 | 28.53 | ERROR | |
r-devel-linux-x86_64-debian-gcc | 1.4-2 | 1.85 | 20.45 | 22.30 | ERROR | |
r-devel-linux-x86_64-fedora-clang | 1.4-2 | 49.39 | ERROR | |||
r-devel-linux-x86_64-fedora-gcc | 1.4-2 | 25.02 | ERROR | |||
r-devel-windows-ix86+x86_64 | 1.4-2 | 5.00 | 50.00 | 55.00 | ERROR | |
r-patched-linux-x86_64 | 1.4-2 | 2.30 | 25.08 | 27.38 | ERROR | |
r-patched-solaris-x86 | 1.4-2 | 66.60 | ERROR | |||
r-release-linux-x86_64 | 1.4-2 | 2.58 | 25.11 | 27.69 | ERROR | |
r-release-windows-ix86+x86_64 | 1.4-2 | 6.00 | 74.00 | 80.00 | ERROR | |
r-release-osx-x86_64 | 1.4-2 | NOTE | ||||
r-oldrel-windows-ix86+x86_64 | 1.4-2 | 2.00 | 54.00 | 56.00 | ERROR | |
r-oldrel-osx-x86_64 | 1.4-2 | NOTE |
Version: 1.4-2
Check: package dependencies
Result: NOTE
Package suggested but not available for checking: ‘FKF’
Flavors: r-devel-linux-x86_64-debian-clang, r-devel-linux-x86_64-debian-gcc, r-devel-linux-x86_64-fedora-clang, r-devel-linux-x86_64-fedora-gcc, r-patched-linux-x86_64, r-patched-solaris-x86, r-release-linux-x86_64, r-release-osx-x86_64
Version: 1.4-2
Check: dependencies in R code
Result: NOTE
'library' or 'require' calls in package code:
‘FKF’ ‘dlm’
Please use :: or requireNamespace() instead.
See section 'Suggested packages' in the 'Writing R Extensions' manual.
Missing or unexported object: ‘dlm::dlmSmooth.dlmFiltered’
Flavors: r-devel-linux-x86_64-debian-clang, r-devel-linux-x86_64-debian-gcc, r-devel-linux-x86_64-fedora-clang, r-devel-linux-x86_64-fedora-gcc, r-devel-windows-ix86+x86_64, r-patched-linux-x86_64, r-patched-solaris-x86, r-release-linux-x86_64, r-release-windows-ix86+x86_64, r-oldrel-windows-ix86+x86_64
Version: 1.4-2
Check: S3 generic/method consistency
Result: NOTE
Found the following apparent S3 methods exported but not registered:
%%.dlmodeler *.dlmodeler +.dlmodeler
See section ‘Registering S3 methods’ in the ‘Writing R Extensions’
manual.
Flavors: r-devel-linux-x86_64-debian-clang, r-devel-linux-x86_64-debian-gcc, r-devel-linux-x86_64-fedora-clang, r-devel-linux-x86_64-fedora-gcc, r-patched-linux-x86_64, r-patched-solaris-x86, r-release-linux-x86_64
Version: 1.4-2
Check: R code for possible problems
Result: NOTE
dlmodeler.extract: no visible global function definition for ‘qnorm’
dlmodeler.fit.MAD: no visible global function definition for ‘optim’
dlmodeler.fit.MAPE: no visible global function definition for ‘optim’
dlmodeler.fit.MLE: no visible global function definition for ‘optim’
dlmodeler.fit.MSE: no visible global function definition for ‘optim’
dlmodeler.fit.sigma : fit.fun: no visible global function definition
for ‘var’
dlmodeler.fit.sigma: no visible global function definition for ‘optim’
dlmodeler.forecast: no visible global function definition for ‘qnorm’
Undefined global functions or variables:
optim qnorm var
Consider adding
importFrom("stats", "optim", "qnorm", "var")
to your NAMESPACE file.
Flavors: r-devel-linux-x86_64-debian-clang, r-devel-linux-x86_64-debian-gcc, r-devel-linux-x86_64-fedora-clang, r-devel-linux-x86_64-fedora-gcc, r-devel-windows-ix86+x86_64, r-patched-linux-x86_64, r-patched-solaris-x86, r-release-linux-x86_64, r-release-windows-ix86+x86_64, r-release-osx-x86_64, r-oldrel-windows-ix86+x86_64, r-oldrel-osx-x86_64
Version: 1.4-2
Check: examples
Result: ERROR
Running examples in ‘dlmodeler-Ex.R’ failed
The error most likely occurred in:
> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: dlmodeler.forecast
> ### Title: Forecast function
> ### Aliases: dlmodeler.forecast
> ### Keywords: dlm kalman forecast
>
> ### ** Examples
>
> require(dlmodeler)
>
> # generate some quarterly data
> n <- 80
> level <- 12
> sigma <- .75
> season <- c(5,6,8,2)
> y <- level + 3*sin((1:n)/10) + rep(season,n/4) + rnorm(n, 0, sigma)
> y <- matrix(y,nrow=1)
>
> # fit a stochastic level + quarterly seasonal model to the data by
> # maximum likelihood estimation
> build.fun <- function(p) {
+ sigmaH <- exp(p[1])
+ sigmaQ <- exp(p[2])*sigmaH
+ mod <- dlmodeler.build.polynomial(0,sigmaH=sigmaH,sigmaQ=sigmaQ) +
+ dlmodeler.build.dseasonal(4,sigmaH=0)
+ return(mod)
+ }
> fit <- dlmodeler.fit.MLE(y, build.fun, c(0,0))
Error in dlmodeler.build.polynomial(0, sigmaH = sigmaH, sigmaQ = sigmaQ) + :
non-numeric argument to binary operator
Calls: dlmodeler.fit.MLE ... optim -> <Anonymous> -> fn -> dlmodeler.filter -> build.fun
Execution halted
Flavors: r-devel-linux-x86_64-debian-clang, r-devel-linux-x86_64-debian-gcc, r-patched-linux-x86_64, r-release-linux-x86_64
Version: 1.4-2
Check: tests
Result: ERROR
Running ‘tests.R’ [0s/1s]
Running the tests in ‘tests/tests.R’ failed.
Complete output:
>
> require(dlmodeler)
Loading required package: dlmodeler
>
> ####################
> # tests for 'core' #
> ####################
>
> # create a DLM by specifying its vectors and matrices
> # check if the model is valid
> mod <- dlmodeler.build(
+ a0 = c(0,0), # initial state: (level, trend)
+ P0 = diag(c(0,0)), # initial state variance set to...
+ P0inf = diag(2), # ...use exact diffuse initialization
+ matrix(c(1,0,1,1),2,2), # state transition matrix
+ diag(c(1,1)), # state disturbance selection matrix
+ diag(c(.5,.05)), # state disturbance variance matrix
+ matrix(c(1,0),1,2), # observation design matrix
+ matrix(1,1,1) # observation disturbance variance matrix
+ )
>
> print(mod)
constant dlmodel(state dim=2, dist dim=2, obs dim=1) 'noname'
- model has 1 component: noname
> if(!(dlmodeler.check(mod)$status==TRUE)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$m==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$r==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$d==1)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$timevar==FALSE)) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Tt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Rt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Qt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Zt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Ht))) stop("unit test failed")
>
>
> # an empty DLM with 4 state variables (3 of which are stochastic)
> # and bi-variate observations, check if the model is valid
> mod <- dlmodeler.build(dimensions=c(4,3,2))
>
> print(mod)
constant dlmodel(state dim=4, dist dim=3, obs dim=2) 'noname'
- model has 1 component: noname
> if(!(dlmodeler.check(mod)$status==TRUE)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$m==4)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$r==3)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$d==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$timevar==FALSE)) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Tt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Rt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Qt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Zt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Ht))) stop("unit test failed")
>
>
> # operations on matrices
> v1 <- matrix(1:9,nrow=3,ncol=3)
> v2 <- array(1:18,dim=c(3,3,2))
>
> m1 <- dlmodeler:::dlmodeler.timevar.fun(v1,v1,function(x,y) x+y)
> if(!(sum(abs(m1-v1-v1))==0)) stop("unit test failed")
> m21 <- dlmodeler:::dlmodeler.timevar.fun(v2,v1,function(x,y) x+y)
> if(!(sum(abs(m21[,,1]-v1-v1))==0)) stop("unit test failed")
> if(!(sum(abs(m21[,,2]-v1-v1-9))==0)) stop("unit test failed")
> m22 <- dlmodeler:::dlmodeler.timevar.fun(v1,v2,function(x,y) x+y)
> if(!(sum(abs(m22[,,1]-m21[,,1]))==0)) stop("unit test failed")
> if(!(sum(abs(m22[,,2]-m21[,,2]))==0)) stop("unit test failed")
> m3 <- dlmodeler:::dlmodeler.timevar.fun(v2,v1,function(x,y) x+y)
> if(!(sum(abs(m3[,,1]-v1-v1))==0)) stop("unit test failed")
> if(!(sum(abs(m3[,,2]-v1-matrix(10:18,nrow=3,ncol=3)))==0)) stop("unit test failed")
>
> mt <- matrix(c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9,9,0,0,0,9,9,9,0,0,0,9,9,9),nrow=6,ncol=6)
> md <- dlmodeler:::dlmodeler.timevar.fun(v1,v2,dlmodeler:::dlmodeler.bdiag)
> if(!(sum(abs(md[,,2]-md[,,1]-mt))==0)) stop("unit test failed")
>
> # operators
> m1 <- dlmodeler.build.dseasonal(12)
> m2 <- dlmodeler.build.polynomial(0)
> m3 <- dlmodeler.build.dseasonal(5)
> m4 <- dlmodeler.build.constant(4)
>
> m1+m2+m3
Error in m1 + m2 : non-numeric argument to binary operator
Execution halted
Flavors: r-devel-linux-x86_64-debian-clang, r-devel-linux-x86_64-debian-gcc, r-patched-linux-x86_64, r-release-linux-x86_64
Version: 1.4-2
Check: tests
Result: ERROR
Running ‘tests.R’ [15s/19s]
Running the tests in ‘tests/tests.R’ failed.
Complete output:
>
> require(dlmodeler)
Loading required package: dlmodeler
>
> ####################
> # tests for 'core' #
> ####################
>
> # create a DLM by specifying its vectors and matrices
> # check if the model is valid
> mod <- dlmodeler.build(
+ a0 = c(0,0), # initial state: (level, trend)
+ P0 = diag(c(0,0)), # initial state variance set to...
+ P0inf = diag(2), # ...use exact diffuse initialization
+ matrix(c(1,0,1,1),2,2), # state transition matrix
+ diag(c(1,1)), # state disturbance selection matrix
+ diag(c(.5,.05)), # state disturbance variance matrix
+ matrix(c(1,0),1,2), # observation design matrix
+ matrix(1,1,1) # observation disturbance variance matrix
+ )
>
> print(mod)
constant dlmodel(state dim=2, dist dim=2, obs dim=1) 'noname'
- model has 1 component: noname
> if(!(dlmodeler.check(mod)$status==TRUE)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$m==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$r==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$d==1)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$timevar==FALSE)) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Tt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Rt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Qt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Zt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Ht))) stop("unit test failed")
>
>
> # an empty DLM with 4 state variables (3 of which are stochastic)
> # and bi-variate observations, check if the model is valid
> mod <- dlmodeler.build(dimensions=c(4,3,2))
>
> print(mod)
constant dlmodel(state dim=4, dist dim=3, obs dim=2) 'noname'
- model has 1 component: noname
> if(!(dlmodeler.check(mod)$status==TRUE)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$m==4)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$r==3)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$d==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$timevar==FALSE)) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Tt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Rt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Qt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Zt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Ht))) stop("unit test failed")
>
>
> # operations on matrices
> v1 <- matrix(1:9,nrow=3,ncol=3)
> v2 <- array(1:18,dim=c(3,3,2))
>
> m1 <- dlmodeler:::dlmodeler.timevar.fun(v1,v1,function(x,y) x+y)
> if(!(sum(abs(m1-v1-v1))==0)) stop("unit test failed")
> m21 <- dlmodeler:::dlmodeler.timevar.fun(v2,v1,function(x,y) x+y)
> if(!(sum(abs(m21[,,1]-v1-v1))==0)) stop("unit test failed")
> if(!(sum(abs(m21[,,2]-v1-v1-9))==0)) stop("unit test failed")
> m22 <- dlmodeler:::dlmodeler.timevar.fun(v1,v2,function(x,y) x+y)
> if(!(sum(abs(m22[,,1]-m21[,,1]))==0)) stop("unit test failed")
> if(!(sum(abs(m22[,,2]-m21[,,2]))==0)) stop("unit test failed")
> m3 <- dlmodeler:::dlmodeler.timevar.fun(v2,v1,function(x,y) x+y)
> if(!(sum(abs(m3[,,1]-v1-v1))==0)) stop("unit test failed")
> if(!(sum(abs(m3[,,2]-v1-matrix(10:18,nrow=3,ncol=3)))==0)) stop("unit test failed")
>
> mt <- matrix(c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9,9,0,0,0,9,9,9,0,0,0,9,9,9),nrow=6,ncol=6)
> md <- dlmodeler:::dlmodeler.timevar.fun(v1,v2,dlmodeler:::dlmodeler.bdiag)
> if(!(sum(abs(md[,,2]-md[,,1]-mt))==0)) stop("unit test failed")
>
> # operators
> m1 <- dlmodeler.build.dseasonal(12)
> m2 <- dlmodeler.build.polynomial(0)
> m3 <- dlmodeler.build.dseasonal(5)
> m4 <- dlmodeler.build.constant(4)
>
> m1+m2+m3
constant dlmodel(state dim=16, dist dim=3, obs dim=1) 'dseasonal+level+dseasonal'
- model has 5 components: dseasonal, level, dseasonal+level, dseasonal, dseasonal+level+dseasonal
- model has 1 unknown parameter
> m1+m2+m3+m4
constant dlmodel(state dim=17, dist dim=4, obs dim=1) 'dseasonal+level+dseasonal+constant'
- model has 7 components: dseasonal, level, dseasonal+level, dseasonal, dseasonal+level+dseasonal, constant, dseasonal+level+dseasonal+constant
- model has 1 unknown parameter
> m1%%m2%%m3
constant dlmodel(state dim=16, dist dim=3, obs dim=3) 'dseasonal&level&dseasonal'
- model has 5 components: dseasonal, level, dseasonal&level, dseasonal, dseasonal&level&dseasonal
- model has 3 unknown parameters
> m1%%m2%%m3%%m4
constant dlmodel(state dim=17, dist dim=4, obs dim=4) 'dseasonal&level&dseasonal&constant'
- model has 7 components: dseasonal, level, dseasonal&level, dseasonal, dseasonal&level&dseasonal, constant, dseasonal&level&dseasonal&constant
- model has 3 unknown parameters
> dlmodeler.add(m1,1)
constant dlmodel(state dim=12, dist dim=2, obs dim=1) 'dseasonal+constant'
- model has 3 components: dseasonal, constant, dseasonal+constant
- model has 1 unknown parameter
> m1+1+m2
constant dlmodel(state dim=13, dist dim=3, obs dim=1) 'dseasonal+constant+level'
- model has 5 components: dseasonal, constant, dseasonal+constant, level, dseasonal+constant+level
- model has 1 unknown parameter
> dlmodeler.add(1,m1)
constant dlmodel(state dim=12, dist dim=2, obs dim=1) 'constant+dseasonal'
- model has 3 components: constant, dseasonal, constant+dseasonal
- model has 1 unknown parameter
> 1+m1+m2
constant dlmodel(state dim=13, dist dim=3, obs dim=1) 'constant+dseasonal+level'
- model has 5 components: constant, dseasonal, constant+dseasonal, level, constant+dseasonal+level
- model has 1 unknown parameter
> dlmodeler.multiply(m2,2)
constant dlmodel(state dim=1, dist dim=1, obs dim=1) 'level'
- model has 1 component: level
- model has 1 unknown parameter
> m1*5
constant dlmodel(state dim=11, dist dim=1, obs dim=1) 'dseasonal'
- model has 1 component: dseasonal
- model has 1 unknown parameter
> dlmodeler.multiply(2,m2)
constant dlmodel(state dim=1, dist dim=1, obs dim=1) 'level'
- model has 1 component: level
- model has 1 unknown parameter
> 5*m1
constant dlmodel(state dim=11, dist dim=1, obs dim=1) 'dseasonal'
- model has 1 component: dseasonal
- model has 1 unknown parameter
> 2*m1+3*m2+4*m3+5*m4
constant dlmodel(state dim=17, dist dim=4, obs dim=1) 'dseasonal+level+dseasonal+constant'
- model has 7 components: dseasonal, level, dseasonal+level, dseasonal, dseasonal+level+dseasonal, constant, dseasonal+level+dseasonal+constant
- model has 1 unknown parameter
> (2*m1+3*m2+4*m3+5*m4)$Zt
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
[1,] 2 0 0 0 0 0 0 0 0 0 0 3 4 0
[,15] [,16] [,17]
[1,] 0 0 5
>
>
> #####################################
> # univariate and time-varying tests #
> #####################################
> # this example is fairly complete, covers 'add', 'filter', 'smooth'
> # 'extract', 'polynomial', 'dseasonal', 'tseasonal', 'regression'
> # test it with various backends
>
> # generate some data
> set.seed(19820605)
> N <- 365*10
> t <- c(1:N,rep(NA,365))
> a <- rnorm(N+365,0,.5)
> y <- pi + cos(2*pi*t/365.25) + .25*sin(2*pi*t/365.25*3) +
+ exp(1)*a + rnorm(N+365,0,.5)
>
> # build a model for this data
> m1 <- dlmodeler.build.polynomial(0,sigmaH=.5,name='level')
> m2 <- dlmodeler.build.dseasonal(7,sigmaH=0,name='week')
> m3 <- dlmodeler.build.tseasonal(365.25,3,sigmaH=0,name='year')
> m4 <- dlmodeler.build.regression(a,sigmaH=0,name='reg')
> m <- m1+m2+m3+m4
>
> test.backend <- function(backend)
+ {
+ cat(backend,"\n")
+ test.ok <- TRUE
+
+ system.time(f <- dlmodeler.filter(y, m, raw.result=TRUE, backend=backend))
+
+ # extract all the components
+ m.state.mean <- dlmodeler.extract(f,m,type="state",value="mean")
+ m.state.cov <- dlmodeler.extract(f,m,type="state",value="covariance")
+ m.obs.mean <- dlmodeler.extract(f,m,type="observation",value="mean")
+ m.obs.cov <- dlmodeler.extract(f,m,type="observation",value="covariance")
+ m.obs.int <- dlmodeler.extract(f,m,type="observation",value="interval",prob=.01)
+
+ par(mfrow=c(2,1))
+
+ # show the one step ahead forecasts & 99\% prediction intervals
+ #plot(y,xlim=c(N-10,N+30))
+ #lines(m.obs.int$mymodel$upper[1,],col='light grey')
+ #lines(m.obs.int$mymodel$lower[1,],col='light grey')
+ #lines(m.obs.int$mymodel$mean[1,],col=2)
+
+ # see to which values the filter has converged:
+ test.ok <- test.ok & abs(m.state.mean$level[,N]-pi)/pi < .05 # should be close to pi
+ test.ok <- test.ok & abs(mean(abs(m.state.mean$week[,N]))) < .05 # should be close to 0
+ test.ok <- test.ok & abs(m.state.mean$year[1,N]-1) < .05 # should be close to 1
+ test.ok <- test.ok & abs(m.state.mean$year[6,N]-.25) < .05 # should be close to .25
+ test.ok <- test.ok & abs(m.state.mean$reg[,N]-exp(1))/exp(1) < .05 # should be close to e
+
+ # show the filtered level+year components
+ #plot(m.obs.mean$level[1,]+m.obs.mean$year[1,],
+ # type='l',ylim=c(pi-2,pi+2),col='light green',
+ # ylab="smoothed & filtered level+year")
+
+ if(backend!='FKF') {
+ system.time(s <- dlmodeler.smooth(f))
+
+ # show the smoothed level+year components
+ s.obs.mean <- dlmodeler.extract(s,m,type="observation",value="mean")
+ #lines(s.obs.mean$level[1,]+s.obs.mean$year[1,],type='l',
+ # ylim=c(pi-2,pi+2),col='dark green')
+ }
+
+ return(test.ok)
+ }
>
> #if(require('KFAS')) {
> # cat('Found package KFAS. Testing...\n')
> if(!(test.backend('KFAS'))) stop("KFAS unit test failed")
KFAS
Warning message:
In KFAS::KFS(filt$raw.result$model, smoothing = "state") :
Possible error in smoothing: Negative variances in V, check the model or try changing the tolerance parameter tol or P1/P1inf of the model.
> #}
>
> if(require('FKF')) {
+ cat('Found package FKF. Testing...\n')
+ if(!(test.backend('FKF'))) stop("FKF unit test failed")
+ }
Loading required package: FKF
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called 'FKF'
>
> if(require('dlm')) {
+ cat('Found package dlm. Testing...\n')
+ if(!(test.backend('dlm'))) stop("dlm unit test failed")
+ }
Loading required package: dlm
Found package dlm. Testing...
dlm
Error: 'dlmSmooth.dlmFiltered' is not an exported object from 'namespace:dlm'
Timing stopped at: 0 0 0.001
Execution halted
Flavor: r-devel-linux-x86_64-fedora-clang
Version: 1.4-2
Check: tests
Result: ERROR
Running ‘tests.R’
Running the tests in ‘tests/tests.R’ failed.
Complete output:
>
> require(dlmodeler)
Loading required package: dlmodeler
>
> ####################
> # tests for 'core' #
> ####################
>
> # create a DLM by specifying its vectors and matrices
> # check if the model is valid
> mod <- dlmodeler.build(
+ a0 = c(0,0), # initial state: (level, trend)
+ P0 = diag(c(0,0)), # initial state variance set to...
+ P0inf = diag(2), # ...use exact diffuse initialization
+ matrix(c(1,0,1,1),2,2), # state transition matrix
+ diag(c(1,1)), # state disturbance selection matrix
+ diag(c(.5,.05)), # state disturbance variance matrix
+ matrix(c(1,0),1,2), # observation design matrix
+ matrix(1,1,1) # observation disturbance variance matrix
+ )
>
> print(mod)
constant dlmodel(state dim=2, dist dim=2, obs dim=1) 'noname'
- model has 1 component: noname
> if(!(dlmodeler.check(mod)$status==TRUE)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$m==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$r==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$d==1)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$timevar==FALSE)) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Tt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Rt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Qt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Zt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Ht))) stop("unit test failed")
>
>
> # an empty DLM with 4 state variables (3 of which are stochastic)
> # and bi-variate observations, check if the model is valid
> mod <- dlmodeler.build(dimensions=c(4,3,2))
>
> print(mod)
constant dlmodel(state dim=4, dist dim=3, obs dim=2) 'noname'
- model has 1 component: noname
> if(!(dlmodeler.check(mod)$status==TRUE)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$m==4)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$r==3)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$d==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$timevar==FALSE)) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Tt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Rt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Qt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Zt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Ht))) stop("unit test failed")
>
>
> # operations on matrices
> v1 <- matrix(1:9,nrow=3,ncol=3)
> v2 <- array(1:18,dim=c(3,3,2))
>
> m1 <- dlmodeler:::dlmodeler.timevar.fun(v1,v1,function(x,y) x+y)
> if(!(sum(abs(m1-v1-v1))==0)) stop("unit test failed")
> m21 <- dlmodeler:::dlmodeler.timevar.fun(v2,v1,function(x,y) x+y)
> if(!(sum(abs(m21[,,1]-v1-v1))==0)) stop("unit test failed")
> if(!(sum(abs(m21[,,2]-v1-v1-9))==0)) stop("unit test failed")
> m22 <- dlmodeler:::dlmodeler.timevar.fun(v1,v2,function(x,y) x+y)
> if(!(sum(abs(m22[,,1]-m21[,,1]))==0)) stop("unit test failed")
> if(!(sum(abs(m22[,,2]-m21[,,2]))==0)) stop("unit test failed")
> m3 <- dlmodeler:::dlmodeler.timevar.fun(v2,v1,function(x,y) x+y)
> if(!(sum(abs(m3[,,1]-v1-v1))==0)) stop("unit test failed")
> if(!(sum(abs(m3[,,2]-v1-matrix(10:18,nrow=3,ncol=3)))==0)) stop("unit test failed")
>
> mt <- matrix(c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9,9,0,0,0,9,9,9,0,0,0,9,9,9),nrow=6,ncol=6)
> md <- dlmodeler:::dlmodeler.timevar.fun(v1,v2,dlmodeler:::dlmodeler.bdiag)
> if(!(sum(abs(md[,,2]-md[,,1]-mt))==0)) stop("unit test failed")
>
> # operators
> m1 <- dlmodeler.build.dseasonal(12)
> m2 <- dlmodeler.build.polynomial(0)
> m3 <- dlmodeler.build.dseasonal(5)
> m4 <- dlmodeler.build.constant(4)
>
> m1+m2+m3
constant dlmodel(state dim=16, dist dim=3, obs dim=1) 'dseasonal+level+dseasonal'
- model has 5 components: dseasonal, level, dseasonal+level, dseasonal, dseasonal+level+dseasonal
- model has 1 unknown parameter
> m1+m2+m3+m4
constant dlmodel(state dim=17, dist dim=4, obs dim=1) 'dseasonal+level+dseasonal+constant'
- model has 7 components: dseasonal, level, dseasonal+level, dseasonal, dseasonal+level+dseasonal, constant, dseasonal+level+dseasonal+constant
- model has 1 unknown parameter
> m1%%m2%%m3
constant dlmodel(state dim=16, dist dim=3, obs dim=3) 'dseasonal&level&dseasonal'
- model has 5 components: dseasonal, level, dseasonal&level, dseasonal, dseasonal&level&dseasonal
- model has 3 unknown parameters
> m1%%m2%%m3%%m4
constant dlmodel(state dim=17, dist dim=4, obs dim=4) 'dseasonal&level&dseasonal&constant'
- model has 7 components: dseasonal, level, dseasonal&level, dseasonal, dseasonal&level&dseasonal, constant, dseasonal&level&dseasonal&constant
- model has 3 unknown parameters
> dlmodeler.add(m1,1)
constant dlmodel(state dim=12, dist dim=2, obs dim=1) 'dseasonal+constant'
- model has 3 components: dseasonal, constant, dseasonal+constant
- model has 1 unknown parameter
> m1+1+m2
constant dlmodel(state dim=13, dist dim=3, obs dim=1) 'dseasonal+constant+level'
- model has 5 components: dseasonal, constant, dseasonal+constant, level, dseasonal+constant+level
- model has 1 unknown parameter
> dlmodeler.add(1,m1)
constant dlmodel(state dim=12, dist dim=2, obs dim=1) 'constant+dseasonal'
- model has 3 components: constant, dseasonal, constant+dseasonal
- model has 1 unknown parameter
> 1+m1+m2
constant dlmodel(state dim=13, dist dim=3, obs dim=1) 'constant+dseasonal+level'
- model has 5 components: constant, dseasonal, constant+dseasonal, level, constant+dseasonal+level
- model has 1 unknown parameter
> dlmodeler.multiply(m2,2)
constant dlmodel(state dim=1, dist dim=1, obs dim=1) 'level'
- model has 1 component: level
- model has 1 unknown parameter
> m1*5
constant dlmodel(state dim=11, dist dim=1, obs dim=1) 'dseasonal'
- model has 1 component: dseasonal
- model has 1 unknown parameter
> dlmodeler.multiply(2,m2)
constant dlmodel(state dim=1, dist dim=1, obs dim=1) 'level'
- model has 1 component: level
- model has 1 unknown parameter
> 5*m1
constant dlmodel(state dim=11, dist dim=1, obs dim=1) 'dseasonal'
- model has 1 component: dseasonal
- model has 1 unknown parameter
> 2*m1+3*m2+4*m3+5*m4
constant dlmodel(state dim=17, dist dim=4, obs dim=1) 'dseasonal+level+dseasonal+constant'
- model has 7 components: dseasonal, level, dseasonal+level, dseasonal, dseasonal+level+dseasonal, constant, dseasonal+level+dseasonal+constant
- model has 1 unknown parameter
> (2*m1+3*m2+4*m3+5*m4)$Zt
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
[1,] 2 0 0 0 0 0 0 0 0 0 0 3 4 0
[,15] [,16] [,17]
[1,] 0 0 5
>
>
> #####################################
> # univariate and time-varying tests #
> #####################################
> # this example is fairly complete, covers 'add', 'filter', 'smooth'
> # 'extract', 'polynomial', 'dseasonal', 'tseasonal', 'regression'
> # test it with various backends
>
> # generate some data
> set.seed(19820605)
> N <- 365*10
> t <- c(1:N,rep(NA,365))
> a <- rnorm(N+365,0,.5)
> y <- pi + cos(2*pi*t/365.25) + .25*sin(2*pi*t/365.25*3) +
+ exp(1)*a + rnorm(N+365,0,.5)
>
> # build a model for this data
> m1 <- dlmodeler.build.polynomial(0,sigmaH=.5,name='level')
> m2 <- dlmodeler.build.dseasonal(7,sigmaH=0,name='week')
> m3 <- dlmodeler.build.tseasonal(365.25,3,sigmaH=0,name='year')
> m4 <- dlmodeler.build.regression(a,sigmaH=0,name='reg')
> m <- m1+m2+m3+m4
>
> test.backend <- function(backend)
+ {
+ cat(backend,"\n")
+ test.ok <- TRUE
+
+ system.time(f <- dlmodeler.filter(y, m, raw.result=TRUE, backend=backend))
+
+ # extract all the components
+ m.state.mean <- dlmodeler.extract(f,m,type="state",value="mean")
+ m.state.cov <- dlmodeler.extract(f,m,type="state",value="covariance")
+ m.obs.mean <- dlmodeler.extract(f,m,type="observation",value="mean")
+ m.obs.cov <- dlmodeler.extract(f,m,type="observation",value="covariance")
+ m.obs.int <- dlmodeler.extract(f,m,type="observation",value="interval",prob=.01)
+
+ par(mfrow=c(2,1))
+
+ # show the one step ahead forecasts & 99\% prediction intervals
+ #plot(y,xlim=c(N-10,N+30))
+ #lines(m.obs.int$mymodel$upper[1,],col='light grey')
+ #lines(m.obs.int$mymodel$lower[1,],col='light grey')
+ #lines(m.obs.int$mymodel$mean[1,],col=2)
+
+ # see to which values the filter has converged:
+ test.ok <- test.ok & abs(m.state.mean$level[,N]-pi)/pi < .05 # should be close to pi
+ test.ok <- test.ok & abs(mean(abs(m.state.mean$week[,N]))) < .05 # should be close to 0
+ test.ok <- test.ok & abs(m.state.mean$year[1,N]-1) < .05 # should be close to 1
+ test.ok <- test.ok & abs(m.state.mean$year[6,N]-.25) < .05 # should be close to .25
+ test.ok <- test.ok & abs(m.state.mean$reg[,N]-exp(1))/exp(1) < .05 # should be close to e
+
+ # show the filtered level+year components
+ #plot(m.obs.mean$level[1,]+m.obs.mean$year[1,],
+ # type='l',ylim=c(pi-2,pi+2),col='light green',
+ # ylab="smoothed & filtered level+year")
+
+ if(backend!='FKF') {
+ system.time(s <- dlmodeler.smooth(f))
+
+ # show the smoothed level+year components
+ s.obs.mean <- dlmodeler.extract(s,m,type="observation",value="mean")
+ #lines(s.obs.mean$level[1,]+s.obs.mean$year[1,],type='l',
+ # ylim=c(pi-2,pi+2),col='dark green')
+ }
+
+ return(test.ok)
+ }
>
> #if(require('KFAS')) {
> # cat('Found package KFAS. Testing...\n')
> if(!(test.backend('KFAS'))) stop("KFAS unit test failed")
KFAS
Warning message:
In KFAS::KFS(filt$raw.result$model, smoothing = "state") :
Possible error in smoothing: Negative variances in V, check the model or try changing the tolerance parameter tol or P1/P1inf of the model.
> #}
>
> if(require('FKF')) {
+ cat('Found package FKF. Testing...\n')
+ if(!(test.backend('FKF'))) stop("FKF unit test failed")
+ }
Loading required package: FKF
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called 'FKF'
>
> if(require('dlm')) {
+ cat('Found package dlm. Testing...\n')
+ if(!(test.backend('dlm'))) stop("dlm unit test failed")
+ }
Loading required package: dlm
Found package dlm. Testing...
dlm
Error: 'dlmSmooth.dlmFiltered' is not an exported object from 'namespace:dlm'
Timing stopped at: 0 0.001 0
Execution halted
Flavor: r-devel-linux-x86_64-fedora-gcc
Version: 1.4-2
Check: tests
Result: ERROR
Running 'tests.R' [16s]
Running the tests in 'tests/tests.R' failed.
Complete output:
>
> require(dlmodeler)
Loading required package: dlmodeler
>
> ####################
> # tests for 'core' #
> ####################
>
> # create a DLM by specifying its vectors and matrices
> # check if the model is valid
> mod <- dlmodeler.build(
+ a0 = c(0,0), # initial state: (level, trend)
+ P0 = diag(c(0,0)), # initial state variance set to...
+ P0inf = diag(2), # ...use exact diffuse initialization
+ matrix(c(1,0,1,1),2,2), # state transition matrix
+ diag(c(1,1)), # state disturbance selection matrix
+ diag(c(.5,.05)), # state disturbance variance matrix
+ matrix(c(1,0),1,2), # observation design matrix
+ matrix(1,1,1) # observation disturbance variance matrix
+ )
>
> print(mod)
constant dlmodel(state dim=2, dist dim=2, obs dim=1) 'noname'
- model has 1 component: noname
> if(!(dlmodeler.check(mod)$status==TRUE)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$m==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$r==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$d==1)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$timevar==FALSE)) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Tt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Rt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Qt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Zt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Ht))) stop("unit test failed")
>
>
> # an empty DLM with 4 state variables (3 of which are stochastic)
> # and bi-variate observations, check if the model is valid
> mod <- dlmodeler.build(dimensions=c(4,3,2))
>
> print(mod)
constant dlmodel(state dim=4, dist dim=3, obs dim=2) 'noname'
- model has 1 component: noname
> if(!(dlmodeler.check(mod)$status==TRUE)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$m==4)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$r==3)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$d==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$timevar==FALSE)) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Tt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Rt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Qt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Zt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Ht))) stop("unit test failed")
>
>
> # operations on matrices
> v1 <- matrix(1:9,nrow=3,ncol=3)
> v2 <- array(1:18,dim=c(3,3,2))
>
> m1 <- dlmodeler:::dlmodeler.timevar.fun(v1,v1,function(x,y) x+y)
> if(!(sum(abs(m1-v1-v1))==0)) stop("unit test failed")
> m21 <- dlmodeler:::dlmodeler.timevar.fun(v2,v1,function(x,y) x+y)
> if(!(sum(abs(m21[,,1]-v1-v1))==0)) stop("unit test failed")
> if(!(sum(abs(m21[,,2]-v1-v1-9))==0)) stop("unit test failed")
> m22 <- dlmodeler:::dlmodeler.timevar.fun(v1,v2,function(x,y) x+y)
> if(!(sum(abs(m22[,,1]-m21[,,1]))==0)) stop("unit test failed")
> if(!(sum(abs(m22[,,2]-m21[,,2]))==0)) stop("unit test failed")
> m3 <- dlmodeler:::dlmodeler.timevar.fun(v2,v1,function(x,y) x+y)
> if(!(sum(abs(m3[,,1]-v1-v1))==0)) stop("unit test failed")
> if(!(sum(abs(m3[,,2]-v1-matrix(10:18,nrow=3,ncol=3)))==0)) stop("unit test failed")
>
> mt <- matrix(c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9,9,0,0,0,9,9,9,0,0,0,9,9,9),nrow=6,ncol=6)
> md <- dlmodeler:::dlmodeler.timevar.fun(v1,v2,dlmodeler:::dlmodeler.bdiag)
> if(!(sum(abs(md[,,2]-md[,,1]-mt))==0)) stop("unit test failed")
>
> # operators
> m1 <- dlmodeler.build.dseasonal(12)
> m2 <- dlmodeler.build.polynomial(0)
> m3 <- dlmodeler.build.dseasonal(5)
> m4 <- dlmodeler.build.constant(4)
>
> m1+m2+m3
constant dlmodel(state dim=16, dist dim=3, obs dim=1) 'dseasonal+level+dseasonal'
- model has 5 components: dseasonal, level, dseasonal+level, dseasonal, dseasonal+level+dseasonal
- model has 1 unknown parameter
> m1+m2+m3+m4
constant dlmodel(state dim=17, dist dim=4, obs dim=1) 'dseasonal+level+dseasonal+constant'
- model has 7 components: dseasonal, level, dseasonal+level, dseasonal, dseasonal+level+dseasonal, constant, dseasonal+level+dseasonal+constant
- model has 1 unknown parameter
> m1%%m2%%m3
constant dlmodel(state dim=16, dist dim=3, obs dim=3) 'dseasonal&level&dseasonal'
- model has 5 components: dseasonal, level, dseasonal&level, dseasonal, dseasonal&level&dseasonal
- model has 3 unknown parameters
> m1%%m2%%m3%%m4
constant dlmodel(state dim=17, dist dim=4, obs dim=4) 'dseasonal&level&dseasonal&constant'
- model has 7 components: dseasonal, level, dseasonal&level, dseasonal, dseasonal&level&dseasonal, constant, dseasonal&level&dseasonal&constant
- model has 3 unknown parameters
> dlmodeler.add(m1,1)
constant dlmodel(state dim=12, dist dim=2, obs dim=1) 'dseasonal+constant'
- model has 3 components: dseasonal, constant, dseasonal+constant
- model has 1 unknown parameter
> m1+1+m2
constant dlmodel(state dim=13, dist dim=3, obs dim=1) 'dseasonal+constant+level'
- model has 5 components: dseasonal, constant, dseasonal+constant, level, dseasonal+constant+level
- model has 1 unknown parameter
> dlmodeler.add(1,m1)
constant dlmodel(state dim=12, dist dim=2, obs dim=1) 'constant+dseasonal'
- model has 3 components: constant, dseasonal, constant+dseasonal
- model has 1 unknown parameter
> 1+m1+m2
constant dlmodel(state dim=13, dist dim=3, obs dim=1) 'constant+dseasonal+level'
- model has 5 components: constant, dseasonal, constant+dseasonal, level, constant+dseasonal+level
- model has 1 unknown parameter
> dlmodeler.multiply(m2,2)
constant dlmodel(state dim=1, dist dim=1, obs dim=1) 'level'
- model has 1 component: level
- model has 1 unknown parameter
> m1*5
constant dlmodel(state dim=11, dist dim=1, obs dim=1) 'dseasonal'
- model has 1 component: dseasonal
- model has 1 unknown parameter
> dlmodeler.multiply(2,m2)
constant dlmodel(state dim=1, dist dim=1, obs dim=1) 'level'
- model has 1 component: level
- model has 1 unknown parameter
> 5*m1
constant dlmodel(state dim=11, dist dim=1, obs dim=1) 'dseasonal'
- model has 1 component: dseasonal
- model has 1 unknown parameter
> 2*m1+3*m2+4*m3+5*m4
constant dlmodel(state dim=17, dist dim=4, obs dim=1) 'dseasonal+level+dseasonal+constant'
- model has 7 components: dseasonal, level, dseasonal+level, dseasonal, dseasonal+level+dseasonal, constant, dseasonal+level+dseasonal+constant
- model has 1 unknown parameter
> (2*m1+3*m2+4*m3+5*m4)$Zt
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
[1,] 2 0 0 0 0 0 0 0 0 0 0 3 4 0
[,15] [,16] [,17]
[1,] 0 0 5
>
>
> #####################################
> # univariate and time-varying tests #
> #####################################
> # this example is fairly complete, covers 'add', 'filter', 'smooth'
> # 'extract', 'polynomial', 'dseasonal', 'tseasonal', 'regression'
> # test it with various backends
>
> # generate some data
> set.seed(19820605)
> N <- 365*10
> t <- c(1:N,rep(NA,365))
> a <- rnorm(N+365,0,.5)
> y <- pi + cos(2*pi*t/365.25) + .25*sin(2*pi*t/365.25*3) +
+ exp(1)*a + rnorm(N+365,0,.5)
>
> # build a model for this data
> m1 <- dlmodeler.build.polynomial(0,sigmaH=.5,name='level')
> m2 <- dlmodeler.build.dseasonal(7,sigmaH=0,name='week')
> m3 <- dlmodeler.build.tseasonal(365.25,3,sigmaH=0,name='year')
> m4 <- dlmodeler.build.regression(a,sigmaH=0,name='reg')
> m <- m1+m2+m3+m4
>
> test.backend <- function(backend)
+ {
+ cat(backend,"\n")
+ test.ok <- TRUE
+
+ system.time(f <- dlmodeler.filter(y, m, raw.result=TRUE, backend=backend))
+
+ # extract all the components
+ m.state.mean <- dlmodeler.extract(f,m,type="state",value="mean")
+ m.state.cov <- dlmodeler.extract(f,m,type="state",value="covariance")
+ m.obs.mean <- dlmodeler.extract(f,m,type="observation",value="mean")
+ m.obs.cov <- dlmodeler.extract(f,m,type="observation",value="covariance")
+ m.obs.int <- dlmodeler.extract(f,m,type="observation",value="interval",prob=.01)
+
+ par(mfrow=c(2,1))
+
+ # show the one step ahead forecasts & 99\% prediction intervals
+ #plot(y,xlim=c(N-10,N+30))
+ #lines(m.obs.int$mymodel$upper[1,],col='light grey')
+ #lines(m.obs.int$mymodel$lower[1,],col='light grey')
+ #lines(m.obs.int$mymodel$mean[1,],col=2)
+
+ # see to which values the filter has converged:
+ test.ok <- test.ok & abs(m.state.mean$level[,N]-pi)/pi < .05 # should be close to pi
+ test.ok <- test.ok & abs(mean(abs(m.state.mean$week[,N]))) < .05 # should be close to 0
+ test.ok <- test.ok & abs(m.state.mean$year[1,N]-1) < .05 # should be close to 1
+ test.ok <- test.ok & abs(m.state.mean$year[6,N]-.25) < .05 # should be close to .25
+ test.ok <- test.ok & abs(m.state.mean$reg[,N]-exp(1))/exp(1) < .05 # should be close to e
+
+ # show the filtered level+year components
+ #plot(m.obs.mean$level[1,]+m.obs.mean$year[1,],
+ # type='l',ylim=c(pi-2,pi+2),col='light green',
+ # ylab="smoothed & filtered level+year")
+
+ if(backend!='FKF') {
+ system.time(s <- dlmodeler.smooth(f))
+
+ # show the smoothed level+year components
+ s.obs.mean <- dlmodeler.extract(s,m,type="observation",value="mean")
+ #lines(s.obs.mean$level[1,]+s.obs.mean$year[1,],type='l',
+ # ylim=c(pi-2,pi+2),col='dark green')
+ }
+
+ return(test.ok)
+ }
>
> #if(require('KFAS')) {
> # cat('Found package KFAS. Testing...\n')
> if(!(test.backend('KFAS'))) stop("KFAS unit test failed")
KFAS
Warning message:
In KFAS::KFS(filt$raw.result$model, smoothing = "state") :
Possible error in smoothing: Negative variances in V, check the model or try changing the tolerance parameter tol or P1/P1inf of the model.
> #}
>
> if(require('FKF')) {
+ cat('Found package FKF. Testing...\n')
+ if(!(test.backend('FKF'))) stop("FKF unit test failed")
+ }
Loading required package: FKF
Loading required package: RUnit
Found package FKF. Testing...
FKF
>
> if(require('dlm')) {
+ cat('Found package dlm. Testing...\n')
+ if(!(test.backend('dlm'))) stop("dlm unit test failed")
+ }
Loading required package: dlm
Found package dlm. Testing...
dlm
Error: 'dlmSmooth.dlmFiltered' is not an exported object from 'namespace:dlm'
Timing stopped at: 0 0 0
Execution halted
Flavor: r-devel-windows-ix86+x86_64
Version: 1.4-2
Check: tests
Result: ERROR
Running ‘tests.R’ [20s/23s]
Running the tests in ‘tests/tests.R’ failed.
Complete output:
>
> require(dlmodeler)
Loading required package: dlmodeler
>
> ####################
> # tests for 'core' #
> ####################
>
> # create a DLM by specifying its vectors and matrices
> # check if the model is valid
> mod <- dlmodeler.build(
+ a0 = c(0,0), # initial state: (level, trend)
+ P0 = diag(c(0,0)), # initial state variance set to...
+ P0inf = diag(2), # ...use exact diffuse initialization
+ matrix(c(1,0,1,1),2,2), # state transition matrix
+ diag(c(1,1)), # state disturbance selection matrix
+ diag(c(.5,.05)), # state disturbance variance matrix
+ matrix(c(1,0),1,2), # observation design matrix
+ matrix(1,1,1) # observation disturbance variance matrix
+ )
>
> print(mod)
constant dlmodel(state dim=2, dist dim=2, obs dim=1) 'noname'
- model has 1 component: noname
> if(!(dlmodeler.check(mod)$status==TRUE)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$m==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$r==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$d==1)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$timevar==FALSE)) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Tt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Rt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Qt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Zt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Ht))) stop("unit test failed")
>
>
> # an empty DLM with 4 state variables (3 of which are stochastic)
> # and bi-variate observations, check if the model is valid
> mod <- dlmodeler.build(dimensions=c(4,3,2))
>
> print(mod)
constant dlmodel(state dim=4, dist dim=3, obs dim=2) 'noname'
- model has 1 component: noname
> if(!(dlmodeler.check(mod)$status==TRUE)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$m==4)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$r==3)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$d==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$timevar==FALSE)) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Tt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Rt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Qt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Zt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Ht))) stop("unit test failed")
>
>
> # operations on matrices
> v1 <- matrix(1:9,nrow=3,ncol=3)
> v2 <- array(1:18,dim=c(3,3,2))
>
> m1 <- dlmodeler:::dlmodeler.timevar.fun(v1,v1,function(x,y) x+y)
> if(!(sum(abs(m1-v1-v1))==0)) stop("unit test failed")
> m21 <- dlmodeler:::dlmodeler.timevar.fun(v2,v1,function(x,y) x+y)
> if(!(sum(abs(m21[,,1]-v1-v1))==0)) stop("unit test failed")
> if(!(sum(abs(m21[,,2]-v1-v1-9))==0)) stop("unit test failed")
> m22 <- dlmodeler:::dlmodeler.timevar.fun(v1,v2,function(x,y) x+y)
> if(!(sum(abs(m22[,,1]-m21[,,1]))==0)) stop("unit test failed")
> if(!(sum(abs(m22[,,2]-m21[,,2]))==0)) stop("unit test failed")
> m3 <- dlmodeler:::dlmodeler.timevar.fun(v2,v1,function(x,y) x+y)
> if(!(sum(abs(m3[,,1]-v1-v1))==0)) stop("unit test failed")
> if(!(sum(abs(m3[,,2]-v1-matrix(10:18,nrow=3,ncol=3)))==0)) stop("unit test failed")
>
> mt <- matrix(c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9,9,0,0,0,9,9,9,0,0,0,9,9,9),nrow=6,ncol=6)
> md <- dlmodeler:::dlmodeler.timevar.fun(v1,v2,dlmodeler:::dlmodeler.bdiag)
> if(!(sum(abs(md[,,2]-md[,,1]-mt))==0)) stop("unit test failed")
>
> # operators
> m1 <- dlmodeler.build.dseasonal(12)
> m2 <- dlmodeler.build.polynomial(0)
> m3 <- dlmodeler.build.dseasonal(5)
> m4 <- dlmodeler.build.constant(4)
>
> m1+m2+m3
constant dlmodel(state dim=16, dist dim=3, obs dim=1) 'dseasonal+level+dseasonal'
- model has 5 components: dseasonal, level, dseasonal+level, dseasonal, dseasonal+level+dseasonal
- model has 1 unknown parameter
> m1+m2+m3+m4
constant dlmodel(state dim=17, dist dim=4, obs dim=1) 'dseasonal+level+dseasonal+constant'
- model has 7 components: dseasonal, level, dseasonal+level, dseasonal, dseasonal+level+dseasonal, constant, dseasonal+level+dseasonal+constant
- model has 1 unknown parameter
> m1%%m2%%m3
constant dlmodel(state dim=16, dist dim=3, obs dim=3) 'dseasonal&level&dseasonal'
- model has 5 components: dseasonal, level, dseasonal&level, dseasonal, dseasonal&level&dseasonal
- model has 3 unknown parameters
> m1%%m2%%m3%%m4
constant dlmodel(state dim=17, dist dim=4, obs dim=4) 'dseasonal&level&dseasonal&constant'
- model has 7 components: dseasonal, level, dseasonal&level, dseasonal, dseasonal&level&dseasonal, constant, dseasonal&level&dseasonal&constant
- model has 3 unknown parameters
> dlmodeler.add(m1,1)
constant dlmodel(state dim=12, dist dim=2, obs dim=1) 'dseasonal+constant'
- model has 3 components: dseasonal, constant, dseasonal+constant
- model has 1 unknown parameter
> m1+1+m2
constant dlmodel(state dim=13, dist dim=3, obs dim=1) 'dseasonal+constant+level'
- model has 5 components: dseasonal, constant, dseasonal+constant, level, dseasonal+constant+level
- model has 1 unknown parameter
> dlmodeler.add(1,m1)
constant dlmodel(state dim=12, dist dim=2, obs dim=1) 'constant+dseasonal'
- model has 3 components: constant, dseasonal, constant+dseasonal
- model has 1 unknown parameter
> 1+m1+m2
constant dlmodel(state dim=13, dist dim=3, obs dim=1) 'constant+dseasonal+level'
- model has 5 components: constant, dseasonal, constant+dseasonal, level, constant+dseasonal+level
- model has 1 unknown parameter
> dlmodeler.multiply(m2,2)
constant dlmodel(state dim=1, dist dim=1, obs dim=1) 'level'
- model has 1 component: level
- model has 1 unknown parameter
> m1*5
constant dlmodel(state dim=11, dist dim=1, obs dim=1) 'dseasonal'
- model has 1 component: dseasonal
- model has 1 unknown parameter
> dlmodeler.multiply(2,m2)
constant dlmodel(state dim=1, dist dim=1, obs dim=1) 'level'
- model has 1 component: level
- model has 1 unknown parameter
> 5*m1
constant dlmodel(state dim=11, dist dim=1, obs dim=1) 'dseasonal'
- model has 1 component: dseasonal
- model has 1 unknown parameter
> 2*m1+3*m2+4*m3+5*m4
constant dlmodel(state dim=17, dist dim=4, obs dim=1) 'dseasonal+level+dseasonal+constant'
- model has 7 components: dseasonal, level, dseasonal+level, dseasonal, dseasonal+level+dseasonal, constant, dseasonal+level+dseasonal+constant
- model has 1 unknown parameter
> (2*m1+3*m2+4*m3+5*m4)$Zt
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
[1,] 2 0 0 0 0 0 0 0 0 0 0 3 4 0
[,15] [,16] [,17]
[1,] 0 0 5
>
>
> #####################################
> # univariate and time-varying tests #
> #####################################
> # this example is fairly complete, covers 'add', 'filter', 'smooth'
> # 'extract', 'polynomial', 'dseasonal', 'tseasonal', 'regression'
> # test it with various backends
>
> # generate some data
> set.seed(19820605)
> N <- 365*10
> t <- c(1:N,rep(NA,365))
> a <- rnorm(N+365,0,.5)
> y <- pi + cos(2*pi*t/365.25) + .25*sin(2*pi*t/365.25*3) +
+ exp(1)*a + rnorm(N+365,0,.5)
>
> # build a model for this data
> m1 <- dlmodeler.build.polynomial(0,sigmaH=.5,name='level')
> m2 <- dlmodeler.build.dseasonal(7,sigmaH=0,name='week')
> m3 <- dlmodeler.build.tseasonal(365.25,3,sigmaH=0,name='year')
> m4 <- dlmodeler.build.regression(a,sigmaH=0,name='reg')
> m <- m1+m2+m3+m4
>
> test.backend <- function(backend)
+ {
+ cat(backend,"\n")
+ test.ok <- TRUE
+
+ system.time(f <- dlmodeler.filter(y, m, raw.result=TRUE, backend=backend))
+
+ # extract all the components
+ m.state.mean <- dlmodeler.extract(f,m,type="state",value="mean")
+ m.state.cov <- dlmodeler.extract(f,m,type="state",value="covariance")
+ m.obs.mean <- dlmodeler.extract(f,m,type="observation",value="mean")
+ m.obs.cov <- dlmodeler.extract(f,m,type="observation",value="covariance")
+ m.obs.int <- dlmodeler.extract(f,m,type="observation",value="interval",prob=.01)
+
+ par(mfrow=c(2,1))
+
+ # show the one step ahead forecasts & 99\% prediction intervals
+ #plot(y,xlim=c(N-10,N+30))
+ #lines(m.obs.int$mymodel$upper[1,],col='light grey')
+ #lines(m.obs.int$mymodel$lower[1,],col='light grey')
+ #lines(m.obs.int$mymodel$mean[1,],col=2)
+
+ # see to which values the filter has converged:
+ test.ok <- test.ok & abs(m.state.mean$level[,N]-pi)/pi < .05 # should be close to pi
+ test.ok <- test.ok & abs(mean(abs(m.state.mean$week[,N]))) < .05 # should be close to 0
+ test.ok <- test.ok & abs(m.state.mean$year[1,N]-1) < .05 # should be close to 1
+ test.ok <- test.ok & abs(m.state.mean$year[6,N]-.25) < .05 # should be close to .25
+ test.ok <- test.ok & abs(m.state.mean$reg[,N]-exp(1))/exp(1) < .05 # should be close to e
+
+ # show the filtered level+year components
+ #plot(m.obs.mean$level[1,]+m.obs.mean$year[1,],
+ # type='l',ylim=c(pi-2,pi+2),col='light green',
+ # ylab="smoothed & filtered level+year")
+
+ if(backend!='FKF') {
+ system.time(s <- dlmodeler.smooth(f))
+
+ # show the smoothed level+year components
+ s.obs.mean <- dlmodeler.extract(s,m,type="observation",value="mean")
+ #lines(s.obs.mean$level[1,]+s.obs.mean$year[1,],type='l',
+ # ylim=c(pi-2,pi+2),col='dark green')
+ }
+
+ return(test.ok)
+ }
>
> #if(require('KFAS')) {
> # cat('Found package KFAS. Testing...\n')
> if(!(test.backend('KFAS'))) stop("KFAS unit test failed")
KFAS
Warning message:
In KFAS::KFS(filt$raw.result$model, smoothing = "state") :
Possible error in smoothing: Negative variances in V, check the model or try changing the tolerance parameter tol or P1/P1inf of the model.
> #}
>
> if(require('FKF')) {
+ cat('Found package FKF. Testing...\n')
+ if(!(test.backend('FKF'))) stop("FKF unit test failed")
+ }
Loading required package: FKF
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called 'FKF'
>
> if(require('dlm')) {
+ cat('Found package dlm. Testing...\n')
+ if(!(test.backend('dlm'))) stop("dlm unit test failed")
+ }
Loading required package: dlm
Found package dlm. Testing...
dlm
Error: 'dlmSmooth.dlmFiltered' is not an exported object from 'namespace:dlm'
Timing stopped at: 0.001 0.001 0.002
Execution halted
Flavor: r-patched-solaris-x86
Version: 1.4-2
Check: tests
Result: ERROR
Running 'tests.R' [24s]
Running the tests in 'tests/tests.R' failed.
Complete output:
>
> require(dlmodeler)
Loading required package: dlmodeler
>
> ####################
> # tests for 'core' #
> ####################
>
> # create a DLM by specifying its vectors and matrices
> # check if the model is valid
> mod <- dlmodeler.build(
+ a0 = c(0,0), # initial state: (level, trend)
+ P0 = diag(c(0,0)), # initial state variance set to...
+ P0inf = diag(2), # ...use exact diffuse initialization
+ matrix(c(1,0,1,1),2,2), # state transition matrix
+ diag(c(1,1)), # state disturbance selection matrix
+ diag(c(.5,.05)), # state disturbance variance matrix
+ matrix(c(1,0),1,2), # observation design matrix
+ matrix(1,1,1) # observation disturbance variance matrix
+ )
>
> print(mod)
constant dlmodel(state dim=2, dist dim=2, obs dim=1) 'noname'
- model has 1 component: noname
> if(!(dlmodeler.check(mod)$status==TRUE)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$m==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$r==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$d==1)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$timevar==FALSE)) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Tt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Rt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Qt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Zt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Ht))) stop("unit test failed")
>
>
> # an empty DLM with 4 state variables (3 of which are stochastic)
> # and bi-variate observations, check if the model is valid
> mod <- dlmodeler.build(dimensions=c(4,3,2))
>
> print(mod)
constant dlmodel(state dim=4, dist dim=3, obs dim=2) 'noname'
- model has 1 component: noname
> if(!(dlmodeler.check(mod)$status==TRUE)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$m==4)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$r==3)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$d==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$timevar==FALSE)) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Tt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Rt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Qt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Zt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Ht))) stop("unit test failed")
>
>
> # operations on matrices
> v1 <- matrix(1:9,nrow=3,ncol=3)
> v2 <- array(1:18,dim=c(3,3,2))
>
> m1 <- dlmodeler:::dlmodeler.timevar.fun(v1,v1,function(x,y) x+y)
> if(!(sum(abs(m1-v1-v1))==0)) stop("unit test failed")
> m21 <- dlmodeler:::dlmodeler.timevar.fun(v2,v1,function(x,y) x+y)
> if(!(sum(abs(m21[,,1]-v1-v1))==0)) stop("unit test failed")
> if(!(sum(abs(m21[,,2]-v1-v1-9))==0)) stop("unit test failed")
> m22 <- dlmodeler:::dlmodeler.timevar.fun(v1,v2,function(x,y) x+y)
> if(!(sum(abs(m22[,,1]-m21[,,1]))==0)) stop("unit test failed")
> if(!(sum(abs(m22[,,2]-m21[,,2]))==0)) stop("unit test failed")
> m3 <- dlmodeler:::dlmodeler.timevar.fun(v2,v1,function(x,y) x+y)
> if(!(sum(abs(m3[,,1]-v1-v1))==0)) stop("unit test failed")
> if(!(sum(abs(m3[,,2]-v1-matrix(10:18,nrow=3,ncol=3)))==0)) stop("unit test failed")
>
> mt <- matrix(c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9,9,0,0,0,9,9,9,0,0,0,9,9,9),nrow=6,ncol=6)
> md <- dlmodeler:::dlmodeler.timevar.fun(v1,v2,dlmodeler:::dlmodeler.bdiag)
> if(!(sum(abs(md[,,2]-md[,,1]-mt))==0)) stop("unit test failed")
>
> # operators
> m1 <- dlmodeler.build.dseasonal(12)
> m2 <- dlmodeler.build.polynomial(0)
> m3 <- dlmodeler.build.dseasonal(5)
> m4 <- dlmodeler.build.constant(4)
>
> m1+m2+m3
constant dlmodel(state dim=16, dist dim=3, obs dim=1) 'dseasonal+level+dseasonal'
- model has 5 components: dseasonal, level, dseasonal+level, dseasonal, dseasonal+level+dseasonal
- model has 1 unknown parameter
> m1+m2+m3+m4
constant dlmodel(state dim=17, dist dim=4, obs dim=1) 'dseasonal+level+dseasonal+constant'
- model has 7 components: dseasonal, level, dseasonal+level, dseasonal, dseasonal+level+dseasonal, constant, dseasonal+level+dseasonal+constant
- model has 1 unknown parameter
> m1%%m2%%m3
constant dlmodel(state dim=16, dist dim=3, obs dim=3) 'dseasonal&level&dseasonal'
- model has 5 components: dseasonal, level, dseasonal&level, dseasonal, dseasonal&level&dseasonal
- model has 3 unknown parameters
> m1%%m2%%m3%%m4
constant dlmodel(state dim=17, dist dim=4, obs dim=4) 'dseasonal&level&dseasonal&constant'
- model has 7 components: dseasonal, level, dseasonal&level, dseasonal, dseasonal&level&dseasonal, constant, dseasonal&level&dseasonal&constant
- model has 3 unknown parameters
> dlmodeler.add(m1,1)
constant dlmodel(state dim=12, dist dim=2, obs dim=1) 'dseasonal+constant'
- model has 3 components: dseasonal, constant, dseasonal+constant
- model has 1 unknown parameter
> m1+1+m2
constant dlmodel(state dim=13, dist dim=3, obs dim=1) 'dseasonal+constant+level'
- model has 5 components: dseasonal, constant, dseasonal+constant, level, dseasonal+constant+level
- model has 1 unknown parameter
> dlmodeler.add(1,m1)
constant dlmodel(state dim=12, dist dim=2, obs dim=1) 'constant+dseasonal'
- model has 3 components: constant, dseasonal, constant+dseasonal
- model has 1 unknown parameter
> 1+m1+m2
constant dlmodel(state dim=13, dist dim=3, obs dim=1) 'constant+dseasonal+level'
- model has 5 components: constant, dseasonal, constant+dseasonal, level, constant+dseasonal+level
- model has 1 unknown parameter
> dlmodeler.multiply(m2,2)
constant dlmodel(state dim=1, dist dim=1, obs dim=1) 'level'
- model has 1 component: level
- model has 1 unknown parameter
> m1*5
constant dlmodel(state dim=11, dist dim=1, obs dim=1) 'dseasonal'
- model has 1 component: dseasonal
- model has 1 unknown parameter
> dlmodeler.multiply(2,m2)
constant dlmodel(state dim=1, dist dim=1, obs dim=1) 'level'
- model has 1 component: level
- model has 1 unknown parameter
> 5*m1
constant dlmodel(state dim=11, dist dim=1, obs dim=1) 'dseasonal'
- model has 1 component: dseasonal
- model has 1 unknown parameter
> 2*m1+3*m2+4*m3+5*m4
constant dlmodel(state dim=17, dist dim=4, obs dim=1) 'dseasonal+level+dseasonal+constant'
- model has 7 components: dseasonal, level, dseasonal+level, dseasonal, dseasonal+level+dseasonal, constant, dseasonal+level+dseasonal+constant
- model has 1 unknown parameter
> (2*m1+3*m2+4*m3+5*m4)$Zt
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
[1,] 2 0 0 0 0 0 0 0 0 0 0 3 4 0
[,15] [,16] [,17]
[1,] 0 0 5
>
>
> #####################################
> # univariate and time-varying tests #
> #####################################
> # this example is fairly complete, covers 'add', 'filter', 'smooth'
> # 'extract', 'polynomial', 'dseasonal', 'tseasonal', 'regression'
> # test it with various backends
>
> # generate some data
> set.seed(19820605)
> N <- 365*10
> t <- c(1:N,rep(NA,365))
> a <- rnorm(N+365,0,.5)
> y <- pi + cos(2*pi*t/365.25) + .25*sin(2*pi*t/365.25*3) +
+ exp(1)*a + rnorm(N+365,0,.5)
>
> # build a model for this data
> m1 <- dlmodeler.build.polynomial(0,sigmaH=.5,name='level')
> m2 <- dlmodeler.build.dseasonal(7,sigmaH=0,name='week')
> m3 <- dlmodeler.build.tseasonal(365.25,3,sigmaH=0,name='year')
> m4 <- dlmodeler.build.regression(a,sigmaH=0,name='reg')
> m <- m1+m2+m3+m4
>
> test.backend <- function(backend)
+ {
+ cat(backend,"\n")
+ test.ok <- TRUE
+
+ system.time(f <- dlmodeler.filter(y, m, raw.result=TRUE, backend=backend))
+
+ # extract all the components
+ m.state.mean <- dlmodeler.extract(f,m,type="state",value="mean")
+ m.state.cov <- dlmodeler.extract(f,m,type="state",value="covariance")
+ m.obs.mean <- dlmodeler.extract(f,m,type="observation",value="mean")
+ m.obs.cov <- dlmodeler.extract(f,m,type="observation",value="covariance")
+ m.obs.int <- dlmodeler.extract(f,m,type="observation",value="interval",prob=.01)
+
+ par(mfrow=c(2,1))
+
+ # show the one step ahead forecasts & 99\% prediction intervals
+ #plot(y,xlim=c(N-10,N+30))
+ #lines(m.obs.int$mymodel$upper[1,],col='light grey')
+ #lines(m.obs.int$mymodel$lower[1,],col='light grey')
+ #lines(m.obs.int$mymodel$mean[1,],col=2)
+
+ # see to which values the filter has converged:
+ test.ok <- test.ok & abs(m.state.mean$level[,N]-pi)/pi < .05 # should be close to pi
+ test.ok <- test.ok & abs(mean(abs(m.state.mean$week[,N]))) < .05 # should be close to 0
+ test.ok <- test.ok & abs(m.state.mean$year[1,N]-1) < .05 # should be close to 1
+ test.ok <- test.ok & abs(m.state.mean$year[6,N]-.25) < .05 # should be close to .25
+ test.ok <- test.ok & abs(m.state.mean$reg[,N]-exp(1))/exp(1) < .05 # should be close to e
+
+ # show the filtered level+year components
+ #plot(m.obs.mean$level[1,]+m.obs.mean$year[1,],
+ # type='l',ylim=c(pi-2,pi+2),col='light green',
+ # ylab="smoothed & filtered level+year")
+
+ if(backend!='FKF') {
+ system.time(s <- dlmodeler.smooth(f))
+
+ # show the smoothed level+year components
+ s.obs.mean <- dlmodeler.extract(s,m,type="observation",value="mean")
+ #lines(s.obs.mean$level[1,]+s.obs.mean$year[1,],type='l',
+ # ylim=c(pi-2,pi+2),col='dark green')
+ }
+
+ return(test.ok)
+ }
>
> #if(require('KFAS')) {
> # cat('Found package KFAS. Testing...\n')
> if(!(test.backend('KFAS'))) stop("KFAS unit test failed")
KFAS
Warning message:
In KFAS::KFS(filt$raw.result$model, smoothing = "state") :
Possible error in smoothing: Negative variances in V, check the model or try changing the tolerance parameter tol or P1/P1inf of the model.
> #}
>
> if(require('FKF')) {
+ cat('Found package FKF. Testing...\n')
+ if(!(test.backend('FKF'))) stop("FKF unit test failed")
+ }
Loading required package: FKF
Loading required package: RUnit
Found package FKF. Testing...
FKF
>
> if(require('dlm')) {
+ cat('Found package dlm. Testing...\n')
+ if(!(test.backend('dlm'))) stop("dlm unit test failed")
+ }
Loading required package: dlm
Found package dlm. Testing...
dlm
Error: 'dlmSmooth.dlmFiltered' is not an exported object from 'namespace:dlm'
Timing stopped at: 0 0 0
Execution halted
Flavor: r-release-windows-ix86+x86_64
Version: 1.4-2
Check: dependencies in R code
Result: NOTE
'library' or 'require' calls in package code:
‘FKF’ ‘dlm’
Please use :: or requireNamespace() instead.
See section 'Suggested packages' in the 'Writing R Extensions' manual.
Flavors: r-release-osx-x86_64, r-oldrel-osx-x86_64
Version: 1.4-2
Check: tests
Result: ERROR
Running 'tests.R' [20s]
Running the tests in 'tests/tests.R' failed.
Complete output:
>
> require(dlmodeler)
Loading required package: dlmodeler
>
> ####################
> # tests for 'core' #
> ####################
>
> # create a DLM by specifying its vectors and matrices
> # check if the model is valid
> mod <- dlmodeler.build(
+ a0 = c(0,0), # initial state: (level, trend)
+ P0 = diag(c(0,0)), # initial state variance set to...
+ P0inf = diag(2), # ...use exact diffuse initialization
+ matrix(c(1,0,1,1),2,2), # state transition matrix
+ diag(c(1,1)), # state disturbance selection matrix
+ diag(c(.5,.05)), # state disturbance variance matrix
+ matrix(c(1,0),1,2), # observation design matrix
+ matrix(1,1,1) # observation disturbance variance matrix
+ )
>
> print(mod)
constant dlmodel(state dim=2, dist dim=2, obs dim=1) 'noname'
- model has 1 component: noname
> if(!(dlmodeler.check(mod)$status==TRUE)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$m==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$r==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$d==1)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$timevar==FALSE)) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Tt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Rt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Qt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Zt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Ht))) stop("unit test failed")
>
>
> # an empty DLM with 4 state variables (3 of which are stochastic)
> # and bi-variate observations, check if the model is valid
> mod <- dlmodeler.build(dimensions=c(4,3,2))
>
> print(mod)
constant dlmodel(state dim=4, dist dim=3, obs dim=2) 'noname'
- model has 1 component: noname
> if(!(dlmodeler.check(mod)$status==TRUE)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$m==4)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$r==3)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$d==2)) stop("unit test failed")
> if(!(dlmodeler.check(mod)$timevar==FALSE)) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Tt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Rt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Qt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Zt))) stop("unit test failed")
> if(!(is.na(dlmodeler.check(mod)$timevar.Ht))) stop("unit test failed")
>
>
> # operations on matrices
> v1 <- matrix(1:9,nrow=3,ncol=3)
> v2 <- array(1:18,dim=c(3,3,2))
>
> m1 <- dlmodeler:::dlmodeler.timevar.fun(v1,v1,function(x,y) x+y)
> if(!(sum(abs(m1-v1-v1))==0)) stop("unit test failed")
> m21 <- dlmodeler:::dlmodeler.timevar.fun(v2,v1,function(x,y) x+y)
> if(!(sum(abs(m21[,,1]-v1-v1))==0)) stop("unit test failed")
> if(!(sum(abs(m21[,,2]-v1-v1-9))==0)) stop("unit test failed")
> m22 <- dlmodeler:::dlmodeler.timevar.fun(v1,v2,function(x,y) x+y)
> if(!(sum(abs(m22[,,1]-m21[,,1]))==0)) stop("unit test failed")
> if(!(sum(abs(m22[,,2]-m21[,,2]))==0)) stop("unit test failed")
> m3 <- dlmodeler:::dlmodeler.timevar.fun(v2,v1,function(x,y) x+y)
> if(!(sum(abs(m3[,,1]-v1-v1))==0)) stop("unit test failed")
> if(!(sum(abs(m3[,,2]-v1-matrix(10:18,nrow=3,ncol=3)))==0)) stop("unit test failed")
>
> mt <- matrix(c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9,9,0,0,0,9,9,9,0,0,0,9,9,9),nrow=6,ncol=6)
> md <- dlmodeler:::dlmodeler.timevar.fun(v1,v2,dlmodeler:::dlmodeler.bdiag)
> if(!(sum(abs(md[,,2]-md[,,1]-mt))==0)) stop("unit test failed")
>
> # operators
> m1 <- dlmodeler.build.dseasonal(12)
> m2 <- dlmodeler.build.polynomial(0)
> m3 <- dlmodeler.build.dseasonal(5)
> m4 <- dlmodeler.build.constant(4)
>
> m1+m2+m3
constant dlmodel(state dim=16, dist dim=3, obs dim=1) 'dseasonal+level+dseasonal'
- model has 5 components: dseasonal, level, dseasonal+level, dseasonal, dseasonal+level+dseasonal
- model has 1 unknown parameter
> m1+m2+m3+m4
constant dlmodel(state dim=17, dist dim=4, obs dim=1) 'dseasonal+level+dseasonal+constant'
- model has 7 components: dseasonal, level, dseasonal+level, dseasonal, dseasonal+level+dseasonal, constant, dseasonal+level+dseasonal+constant
- model has 1 unknown parameter
> m1%%m2%%m3
constant dlmodel(state dim=16, dist dim=3, obs dim=3) 'dseasonal&level&dseasonal'
- model has 5 components: dseasonal, level, dseasonal&level, dseasonal, dseasonal&level&dseasonal
- model has 3 unknown parameters
> m1%%m2%%m3%%m4
constant dlmodel(state dim=17, dist dim=4, obs dim=4) 'dseasonal&level&dseasonal&constant'
- model has 7 components: dseasonal, level, dseasonal&level, dseasonal, dseasonal&level&dseasonal, constant, dseasonal&level&dseasonal&constant
- model has 3 unknown parameters
> dlmodeler.add(m1,1)
constant dlmodel(state dim=12, dist dim=2, obs dim=1) 'dseasonal+constant'
- model has 3 components: dseasonal, constant, dseasonal+constant
- model has 1 unknown parameter
> m1+1+m2
constant dlmodel(state dim=13, dist dim=3, obs dim=1) 'dseasonal+constant+level'
- model has 5 components: dseasonal, constant, dseasonal+constant, level, dseasonal+constant+level
- model has 1 unknown parameter
> dlmodeler.add(1,m1)
constant dlmodel(state dim=12, dist dim=2, obs dim=1) 'constant+dseasonal'
- model has 3 components: constant, dseasonal, constant+dseasonal
- model has 1 unknown parameter
> 1+m1+m2
constant dlmodel(state dim=13, dist dim=3, obs dim=1) 'constant+dseasonal+level'
- model has 5 components: constant, dseasonal, constant+dseasonal, level, constant+dseasonal+level
- model has 1 unknown parameter
> dlmodeler.multiply(m2,2)
constant dlmodel(state dim=1, dist dim=1, obs dim=1) 'level'
- model has 1 component: level
- model has 1 unknown parameter
> m1*5
constant dlmodel(state dim=11, dist dim=1, obs dim=1) 'dseasonal'
- model has 1 component: dseasonal
- model has 1 unknown parameter
> dlmodeler.multiply(2,m2)
constant dlmodel(state dim=1, dist dim=1, obs dim=1) 'level'
- model has 1 component: level
- model has 1 unknown parameter
> 5*m1
constant dlmodel(state dim=11, dist dim=1, obs dim=1) 'dseasonal'
- model has 1 component: dseasonal
- model has 1 unknown parameter
> 2*m1+3*m2+4*m3+5*m4
constant dlmodel(state dim=17, dist dim=4, obs dim=1) 'dseasonal+level+dseasonal+constant'
- model has 7 components: dseasonal, level, dseasonal+level, dseasonal, dseasonal+level+dseasonal, constant, dseasonal+level+dseasonal+constant
- model has 1 unknown parameter
> (2*m1+3*m2+4*m3+5*m4)$Zt
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
[1,] 2 0 0 0 0 0 0 0 0 0 0 3 4 0
[,15] [,16] [,17]
[1,] 0 0 5
>
>
> #####################################
> # univariate and time-varying tests #
> #####################################
> # this example is fairly complete, covers 'add', 'filter', 'smooth'
> # 'extract', 'polynomial', 'dseasonal', 'tseasonal', 'regression'
> # test it with various backends
>
> # generate some data
> set.seed(19820605)
> N <- 365*10
> t <- c(1:N,rep(NA,365))
> a <- rnorm(N+365,0,.5)
> y <- pi + cos(2*pi*t/365.25) + .25*sin(2*pi*t/365.25*3) +
+ exp(1)*a + rnorm(N+365,0,.5)
>
> # build a model for this data
> m1 <- dlmodeler.build.polynomial(0,sigmaH=.5,name='level')
> m2 <- dlmodeler.build.dseasonal(7,sigmaH=0,name='week')
> m3 <- dlmodeler.build.tseasonal(365.25,3,sigmaH=0,name='year')
> m4 <- dlmodeler.build.regression(a,sigmaH=0,name='reg')
> m <- m1+m2+m3+m4
>
> test.backend <- function(backend)
+ {
+ cat(backend,"\n")
+ test.ok <- TRUE
+
+ system.time(f <- dlmodeler.filter(y, m, raw.result=TRUE, backend=backend))
+
+ # extract all the components
+ m.state.mean <- dlmodeler.extract(f,m,type="state",value="mean")
+ m.state.cov <- dlmodeler.extract(f,m,type="state",value="covariance")
+ m.obs.mean <- dlmodeler.extract(f,m,type="observation",value="mean")
+ m.obs.cov <- dlmodeler.extract(f,m,type="observation",value="covariance")
+ m.obs.int <- dlmodeler.extract(f,m,type="observation",value="interval",prob=.01)
+
+ par(mfrow=c(2,1))
+
+ # show the one step ahead forecasts & 99\% prediction intervals
+ #plot(y,xlim=c(N-10,N+30))
+ #lines(m.obs.int$mymodel$upper[1,],col='light grey')
+ #lines(m.obs.int$mymodel$lower[1,],col='light grey')
+ #lines(m.obs.int$mymodel$mean[1,],col=2)
+
+ # see to which values the filter has converged:
+ test.ok <- test.ok & abs(m.state.mean$level[,N]-pi)/pi < .05 # should be close to pi
+ test.ok <- test.ok & abs(mean(abs(m.state.mean$week[,N]))) < .05 # should be close to 0
+ test.ok <- test.ok & abs(m.state.mean$year[1,N]-1) < .05 # should be close to 1
+ test.ok <- test.ok & abs(m.state.mean$year[6,N]-.25) < .05 # should be close to .25
+ test.ok <- test.ok & abs(m.state.mean$reg[,N]-exp(1))/exp(1) < .05 # should be close to e
+
+ # show the filtered level+year components
+ #plot(m.obs.mean$level[1,]+m.obs.mean$year[1,],
+ # type='l',ylim=c(pi-2,pi+2),col='light green',
+ # ylab="smoothed & filtered level+year")
+
+ if(backend!='FKF') {
+ system.time(s <- dlmodeler.smooth(f))
+
+ # show the smoothed level+year components
+ s.obs.mean <- dlmodeler.extract(s,m,type="observation",value="mean")
+ #lines(s.obs.mean$level[1,]+s.obs.mean$year[1,],type='l',
+ # ylim=c(pi-2,pi+2),col='dark green')
+ }
+
+ return(test.ok)
+ }
>
> #if(require('KFAS')) {
> # cat('Found package KFAS. Testing...\n')
> if(!(test.backend('KFAS'))) stop("KFAS unit test failed")
KFAS
Warning message:
In KFAS::KFS(filt$raw.result$model, smoothing = "state") :
Possible error in smoothing: Negative variances in V, check the model or try changing the tolerance parameter tol or P1/P1inf of the model.
> #}
>
> if(require('FKF')) {
+ cat('Found package FKF. Testing...\n')
+ if(!(test.backend('FKF'))) stop("FKF unit test failed")
+ }
Loading required package: FKF
Loading required package: RUnit
Found package FKF. Testing...
FKF
>
> if(require('dlm')) {
+ cat('Found package dlm. Testing...\n')
+ if(!(test.backend('dlm'))) stop("dlm unit test failed")
+ }
Loading required package: dlm
Found package dlm. Testing...
dlm
Error: 'dlmSmooth.dlmFiltered' is not an exported object from 'namespace:dlm'
Timing stopped at: 0 0 0
Execution halted
Flavor: r-oldrel-windows-ix86+x86_64