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