r - Testing multiple time -
i trying test multiple stationarity tests on data set:
> library(data.table) > library(fpp) > library(xts) > > dput(datsel) structure(list(gesamtbaukost = c(59373l, 59209l, 58935l, 58551l, 58496l, 58458l, 58368l, 58039l, 57582l, 57472l, 57289l, 56742l, 56156l, 56248l, 56046l, 55919l, 55243l, 55075l, 55045l, 53988l, 53436l, 53298l, 52930l, 52915l, 52947l, 53834l, 52946l, 51567l, 50433l, 50449l, 50357l, 49557l, 48932l, 48671l, 47722l, 46772l, 46213l, 45865l, 45919l, 45826l, 45612l, 45276l, 44994l, 44041l, 43225l, 42983l, 42715l, 42232l, 41870l, 41843l, 41777l, 41321l, 41132l, 41240l, 41172l, 40743l, 40587l, 40352l, 40127l, 39814l ), lohn = c(96819l, 96819l, 96090l, 94632l, 94632l, 94632l, 93727l, 91917l, 91917l, 91917l, 90779l, 88503l, 88416l, 88416l, 88270l, 87978l, 87996l, 87996l, 87566l, 86706l, 86706l, 86706l, 85794l, 83970l, 83970l, 83970l, 83007l, 81081l, 81081l, 81081l, 80423l, 79107l, 79107l, 79107l, 78321l, 76749l, 76533l, 76533l, 75983l, 74883l, 74883l, 74883l, 74575l, 73959l, 73959l, 73959l, 73167l, 71583l, 71583l, 71583l, 70858l, 69408l, 69408l, 69408l, 68594l, 66966l, 66831l, 66342l, 65853l, 64875l), resprop.dwell = c(144.5, 146.5, 147.3, 143.3, 140.1, 142.8, 141.2, 140.2, 137.8, 137.4, 136.6, 137.6, 125.5, 125.7, 120.5, 124.2, 121.5, 119.8, 121.3, 122, 114.1, 114.4, 114.7, 116.1, 112.8, 111.8, 110.2, 111.7, 112.2, 113.7, 112.7, 110.5, 107, 107.5, 108, 107.1, 106.7, 103.3, 104.2, 104.3, 104.1, 101.3, 100.5, 94.3, 105.6, 101, 102, 103.1, 101.4, 105.5, 100.5, 102.8, 100.5, 105.1, 98.8, 105.1, 98.2, 98.2, 100.6, 103), resprop.dwell.1 = c(132.2, 133.9, 133.5, 126, 125, 122.6, 122.6, 123.8, 124.5, 120.2, 120.2, 123.5, 105.2, 116.4, 111.5, 116.4, 116.1, 114.3, 117, 117.9, 107.1, 104.5, 110.6, 110.5, 104.2, 105.4, 106.2, 110.3, 106.8, 111.4, 111.2, 108.5, 93.5, 101.5, 101.4, 101.3, 101.7, 96.8, 97.3, 100, 97.5, 99.4, 94.8, 93.8, 101.9, 97.4, 97.7, 98.4, 100.6, 100.1, 96.3, 98.1, 93.4, 99.3, 97.3, 99.6, 99.2, 97.8, 100.1, 102.9), resprop.dwell.2 = c(149.8, 151.9, 153.2, 150.7, 146.5, 151.5, 149.2, 147.3, 143.6, 144.8, 143.6, 143.7, 134.1, 129.7, 124.3, 127.5, 123.7, 122.2, 123.1, 123.8, 117.1, 118.6, 116.4, 118.4, 116.4, 114.6, 111.9, 112.2, 114.5, 114.6, 113.4, 111.3, 112.8, 110.1, 110.8, 109.5, 108.8, 106.1, 107.1, 106.1, 107, 102.1, 103, 94.5, 107.2, 102.5, 103.9, 105.1, 101.7, 107.8, 102.4, 104.8, 103.6, 107.6, 99.5, 107.4, 97.8, 98.4, 100.8, 103), resprop.dwell.3 = c(155.2, 157.6, 159, 156.5, 151.4, 155, 152, 149, 146.4, 147.9, 146.6, 146.3, 137.1, 131.1, 124.5, 127.5, 123.1, 121.9, 123, 123.5, 116.4, 117.7, 116.4, 118.1, 116.5, 113.7, 110.2, 111, 113.9, 113.9, 113.6, 110.9, 113.2, 109.9, 111.7, 109.7, 110.1, 106.3, 107.4, 105.9, 107.2, 101.6, 103.8, 94.1, 108.4, 102.7, 104.1, 105.1, 101.5, 108.8, 102.3, 105.4, 103, 107.2, 99.3, 107.6, 97.4, 97.6, 101.2, 103.9), resprop.dwell.4 = c(112.6, 112.7, 113.6, 110.7, 113.4, 127.1, 130.1, 135.7, 123.7, 123.2, 123, 125.5, 113.5, 120.2, 123.3, 128, 128.2, 124.6, 124, 125.8, 122.2, 124.8, 116.6, 120.4, 115.9, 120.6, 124, 120.6, 119, 120.1, 111.6, 114, 110.2, 111.6, 104.5, 107.9, 100.4, 104.7, 105, 106.9, 105.1, 105.8, 97.3, 96.6, 99.1, 101.1, 102.5, 105.2, 103, 101, 102.7, 100.5, 107.4, 110.1, 101.3, 105.7, 100.3, 104.1, 98.4, 97.2), date = structure(c(60l, 30l, 15l, 45l, 59l, 29l, 14l, 44l, 58l, 28l, 13l, 43l, 57l, 27l, 12l, 42l, 56l, 26l, 11l, 41l, 55l, 25l, 10l, 40l, 54l, 24l, 9l, 39l, 53l, 23l, 8l, 38l, 52l, 22l, 7l, 37l, 51l, 21l, 6l, 36l, 50l, 20l, 5l, 35l, 49l, 19l, 4l, 34l, 48l, 18l, 3l, 33l, 47l, 17l, 2l, 32l, 46l, 16l, 1l, 31l), .label = c("30.06.2000", "30.06.2001", "30.06.2002", "30.06.2003", "30.06.2004", "30.06.2005", "30.06.2006", "30.06.2007", "30.06.2008", "30.06.2009", "30.06.2010", "30.06.2011", "30.06.2012", "30.06.2013", "30.06.2014", "30.09.2000", "30.09.2001", "30.09.2002", "30.09.2003", "30.09.2004", "30.09.2005", "30.09.2006", "30.09.2007", "30.09.2008", "30.09.2009", "30.09.2010", "30.09.2011", "30.09.2012", "30.09.2013", "30.09.2014", "31.03.2000", "31.03.2001", "31.03.2002", "31.03.2003", "31.03.2004", "31.03.2005", "31.03.2006", "31.03.2007", "31.03.2008", "31.03.2009", "31.03.2010", "31.03.2011", "31.03.2012", "31.03.2013", "31.03.2014", "31.12.2000", "31.12.2001", "31.12.2002", "31.12.2003", "31.12.2004", "31.12.2005", "31.12.2006", "31.12.2007", "31.12.2008", "31.12.2009", "31.12.2010", "31.12.2011", "31.12.2012", "31.12.2013", "31.12.2014"), class = "factor")), .names = c("gesamtbaukost", "lohn", "resprop.dwell", "resprop.dwell.1", "resprop.dwell.2", "resprop.dwell.3", "resprop.dwell.4", "date"), row.names = c(na, -60l), class = "data.frame") > dt <- as.data.table(datsel) > dt[,date := as.date(date,format='%d.%m.%y')] > dt[,{ x = xts(datsel[1:7],date) + list(box= box.test(x)$p.value <0.05 , + adf= adf.test(x)$p.value <0.05 , + kpss= kpss.test(x)$p.value >0.05) + }] error in box.test(x) : x not vector or univariate time series
as can see problem that, x not vector or univariate time series
. hence, cannot use multiple vectors in dt
function.
any suggestion doing wrong?
i appreciate replies!
if need logical values output
dt[order(date), lapply(.sd, function(x) c(box=box.test(x)$p.value < 0.05, adf=adf.test(x)$p.value < 0.05, kpss=kpss.test(x)$p.value>0.05)), .sdcols=1:7]
or if converting xts
, need values based on condition
x1 <- xts(datsel[1:7], order.by = as.date(datsel$date, format='%d.%m.%y')) apply(x1, 2, function(x) { val <- c(box=box.test(x)$p.value, adf=adf.test(x)$p.value, kpss=kpss.test(x)$p.value) val[1:2] <- ifelse(val[1:2] >=0.05, na, val[1:2]) val[3] <- ifelse(val[3] <= 0.05, na, val[3]) val})
Comments
Post a Comment