Skip to content
Permalink
Browse files

0.00.0005

  • Loading branch information...
fcbarbi committed May 3, 2016
1 parent 8ad973c commit 93bff5ae335d4eb7cd914eaabc62d3bd2116c24d
Showing with 56 additions and 30 deletions.
  1. +1 −1 DESCRIPTION
  2. +8 −1 R/urTable.R
  3. +47 −28 tests/test_all.R
@@ -1,6 +1,6 @@
Package: macror
Title: Functions for Macroeconomic time series analysis in R
Version: 0.00.004
Version: 0.00.005
Authors@R: person("Fernando", "Barbi", email = "fcbarbi@gmail.com", role = c("aut", "cre"))
Author: Fernando Barbi [aut,cre]
Maintainer: Fernando Barbi <fcbarbi@gmail.com>
@@ -26,9 +26,15 @@
#' require(tseries)
#' data(USeconomic,package="tseries")
#' data <- data.frame( USeconomic )
#'
#' dft1 <- urTable( data, tests=c("adf","pp","kpss"), file="US.csv" )
#'
#' dft2 <- urTable( data, tests=c("pp","kpss"), order=2, file="US.tex", format="latex" )
#'
#' # Even series with missing observations can be tested
#' bad <- data.frame( var1=rnorm(100), var2=cumsum(rnorm(100)) )
#' bad[seq(95,100),"var1"] <- bad[1,"var2"] <- bad[2,"var2"] <- NA
#' dft3 <- urTable( bad )

urTable <- function( df ,tests=c("adf","pp","kpss"), order=1, file=NULL, format="csv" ){

@@ -62,7 +68,8 @@ urTable <- function( df ,tests=c("adf","pp","kpss"), order=1, file=NULL, format=
for (i in intorder)
for (test in tests)
for (series in colnames(df)) {
data <- df[[series]]
data <- ts(df[[series]])
data <- macror::tsComplete(data)
if (i>0) data <- diff(data,i)
col <- paste0(test,"(",i,")") # cols = test(intorder) as in "adf(0)" or "kpss(2)"
if (test=="adf") dft[series,col] <- tseries::adf.test(data)$p.value
@@ -6,23 +6,23 @@

#require(zoo)
#require(RUnit)
#require(tsworkflow)
#require(macror)

# dlog ---------------------------------------

core <- rnorm(13,mean=.2,sd=.1)
z <- zoo::zooreg( core, start=c(2007,12), freq=12 )
z1 <- tsworkflow:::deltaPX(z)
z1 <- macror:::deltaPX(z)
t <- as.ts( z )
t1 <- tsworkflow:::deltaPX(t)
t1 <- macror:::deltaPX(t)
RUnit::checkIdentical( zoo::coredata(z1), zoo::coredata(t1) )

x <- ts( rnorm(10,mean=100) )
RUnit::checkIdentical( tsworkflow::dlog(x), ts(c(NA,diff(log(x)))))
RUnit::checkIdentical( tsworkflow::dlog(x,2), ts(c(NA,diff(log(x),2))))
RUnit::checkIdentical( macror::dlog(x), ts(c(NA,diff(log(x)))))
RUnit::checkIdentical( macror::dlog(x,2), ts(c(NA,diff(log(x),2))))

x <- zoo::zooreg( rnorm(10,mean=100) )
RUnit::checkIdentical( tsworkflow::dlog(x), zoo::zooreg(c(NA,diff(log(x)))))
RUnit::checkIdentical( macror::dlog(x), zoo::zooreg(c(NA,diff(log(x)))))

# x1 <- ts( seq(-.3,.6,.1) )
# x11<-dlog( x1, lag=1 )
@@ -35,10 +35,10 @@ RUnit::checkIdentical( tsworkflow::dlog(x), zoo::zooreg(c(NA,diff(log(x)))))

# genEVtime ---------------------------------------

RUnit::checkIdentical( tsworkflow::genEVtime("1947Y1","1949Y1"), c("1947","1948","1949"))
RUnit::checkIdentical( tsworkflow::genEVtime("1947q3","1948Q02"), c("1947Q3", "1947Q4", "1948Q1", "1948Q2") )
RUnit::checkIdentical( tsworkflow::genEVtime("1947S2","1949S1"), c("1947S2","1948S1","1948S2","1949S1") )
RUnit::checkIdentical( tsworkflow::genEVtime("1947m1",qobs=6), c("1947M1","1947M2","1947M3","1947M4","1947M5","1947M6") )
RUnit::checkIdentical( macror::genEVtime("1947Y1","1949Y1"), c("1947","1948","1949"))
RUnit::checkIdentical( macror::genEVtime("1947q3","1948Q02"), c("1947Q3", "1947Q4", "1948Q1", "1948Q2") )
RUnit::checkIdentical( macror::genEVtime("1947S2","1949S1"), c("1947S2","1948S1","1948S2","1949S1") )
RUnit::checkIdentical( macror::genEVtime("1947m1",qobs=6), c("1947M1","1947M2","1947M3","1947M4","1947M5","1947M6") )

# removeOutliers ---------------------------------------
#
@@ -53,14 +53,21 @@ RUnit::checkIdentical( tsworkflow::genEVtime("1947m1",qobs=6), c("1947M1","1947M
# ix <- numToIndex(x)
# RUnit::checkIdentical( ix, ts( c(100,100.1,100.2,101.1,110.1,200.1) ) )

# x2 <- ts( c(0.1,0.2,0.3,-0.1,-0.2,0.0,0.4))
x2 <- ts( c(1,2,3,-1,-2,0,4))
ix2 <- tsworkflow::pVarToIndex(x2)
ok <- ts( c(100,101.0,103.02,106.1106,105.0495,102.9485,102.9485) )
RUnit::checkIdentical( ix2, ok )
ix2 <- macror::tsVarToIndex(x2)
ok <- c(100,101.0,103.02,106.1106,105.0495,102.9485,102.9485)
RUnit::checkIdentical( ix2, ts(ok) )

x3 <- zoo::as.zoo(x2)
ix3 <- macror::tsVarToIndex(x3)
RUnit::checkIdentical( ix3, zoo::zooreg(ok) )

# x <- ts( c(1000,1010,999,1200.1) )
# RUnit::checkIdentical( tsNumToIndex( x ), ts( c(100,101,99.9,120.01) ) )
#
# x <- zoo::zooreg( c(1000,1010,999,1200.1) )
# RUnit::checkIdentical( tsNumToIndex( x ), zoo::zooreg( c(100,101,99.9,120.01) ) )

x <- ts( c(1000,1010,999,1200.1), start=c(1980,1), freq=12 )
RUnit::checkIdentical( tsworkflow::numToIndex( x ), ts( c(100,101,99.9,120.01), start=c(1980,1), freq=12 ))

# tsComplete --------------------------------------------

@@ -70,13 +77,13 @@ a2 <- ts(a,start=c(2000,1),freq=4)
b2 <- ts(b,start=c(2000,2),freq=4)
a3 <- zoo::zooreg(a,start=c(2000,1),freq=4)
b3 <- zoo::zooreg(b,start=c(2000,2),freq=4)
aa2 <- tsworkflow::tsComplete(a2)
ab1 <- tsworkflow::tsComplete(a2,b2)
ab2 <- tsworkflow::tsComplete(a2,b2,fill="na")
ab3 <- tsworkflow::tsComplete(a2,b3)
ab4 <- tsworkflow::tsComplete(b3,a2)
ab5 <- tsworkflow::tsComplete(a3,b3)
ab6 <- tsworkflow::tsComplete(a3,b3,fill="fill")
aa2 <- macror::tsComplete(a2)
ab1 <- macror::tsComplete(a2,b2)
ab2 <- macror::tsComplete(a2,b2,fill="na")
ab3 <- macror::tsComplete(a2,b3)
ab4 <- macror::tsComplete(b3,a2)
ab5 <- macror::tsComplete(a3,b3)
ab6 <- macror::tsComplete(a3,b3,fill="fill")
b2m <- ts(b,start=c(2000,2),freq=12)

RUnit::checkIdentical( aa2, ts(c(1,1,2,3,4,5,5),start=c(2000,1),freq=4) )
@@ -87,21 +94,33 @@ RUnit::checkIdentical( ab4, zoo::zooreg( c(1,1,12,12.5,13,5,15,16),start=c(2000,
RUnit::checkIdentical( ab5, zoo::zooreg( c(1,1,2,7.5,13,5,15,16),start=c(2000,1),freq=4) )
RUnit::checkIdentical( ab6, zoo::zooreg( c(1,1,2,7.5,13,5,15,16),start=c(2000,1),freq=4) )

RUnit::checkException( tsworkflow::tsCombine(b2m,a2), silent=TRUE ) # cant combine diff freq
RUnit::checkException( macror::tsCombine(b2m,a2), silent=TRUE ) # cant combine diff freq

#RUnit::checkIdentical( tsCombine(a,b,fill="int"), ts(c(1,2,13,9,5)) ) # DANGER shorter!
#RUnit::checkIdentical( tsCombine(a,b,fill="rep"), ts(c(1,2,13,13,5,5)) ) # DANGER shorter!

# tsDummy ---------------------------------------

d1 <- tsworkflow::tsDummy( start=c(2000,1), end=c(2001,12), freq=12, period=list( c(2001,9), c(2001,11) ) )
d2 <- tsworkflow::tsDummy( start=c(2000,1), end=c(2001,12), freq=12, dates=list( c(2001,9), c(2001,10), c(2001,11) ) )
d1 <- macror::tsDummy( start=c(2000,1), end=c(2001,12), freq=12, period=list( c(2001,9), c(2001,11) ) )
d2 <- macror::tsDummy( start=c(2000,1), end=c(2001,12), freq=12, dates=list( c(2001,9), c(2001,10), c(2001,11) ) )
RUnit::checkIdentical( d1, d2 )

# tsMapOutliers ---------------------------------------

x <- ts( c(8,rnorm(10),-5) )
xo <- tsworkflow::tsMapOutliers( x, c(.05,.95) )
xo <- macror::tsMapOutliers( x, c(.05,.95) )
RUnit::checkIdentical( xo, ts(c(1,rep(0,10),1)) )

# usTable ---------------------------------------
# urTable ---------------------------------------

# data(USeconomic) # from tseries
# data <- data.frame( USeconomic )
# dft1 <- macror::urTable( data, tests=c("adf","pp","kpss"), file="USeconomic.csv" )
# dft2 <- macror::urTable( data, tests=c("pp","kpss"), order=2, file="USeconomic.tex", format="latex" )

bad <- data.frame( var1=rnorm(100), var2=cumsum(rnorm(100)) )
bad[seq(95,100),"var1"] <- bad[seq(1,5),"var2"] <- bad[seq(50,55),"var2"] <- NA
dft3 <- macror::urTable( bad )


#eof

0 comments on commit 93bff5a

Please sign in to comment.
You can’t perform that action at this time.