Skip to main content
edited tags
Link
Richard Hardy
  • 69.5k
  • 13
  • 126
  • 278
Source Link
CuteCat
  • 295
  • 2
  • 9

Weird thing: The larger my lags, the smaller my Ljung Box test p-values

I am doing analysis to a dataset about U.S. Imports of Goods by Customs Basis from China.

I deleted the data of the first 5 years, logged the data, and then decomposed it (or HoltWinters, which also leads to this problem).

The random part passed my stationary test, so I fitted an ARIMA model and tested its residuals.

Weird thing happened: the larger my lag, the smaller my p-value.

Through spectral density plot and acf plot, I think it is not a long memory model. So... What's wrong with my model? How to improve it?

This is my code.

imp <- IMPCH$IMPCH[-c(1:60)]
length(imp)
imp.ts <- ts(imp, frequency = 12, start = 1990)
log.imp.ts <- log(imp.ts)
ts.plot(log.imp.ts)

log.imp.ts.de <- decompose(log.imp.ts)
#log.imp.ts.hw <- HoltWinters(log.imp.ts)
log.imp.ts.random <- log.imp.ts.de$random
#log.imp.ts.random <- resid(log.imp.ts.hw)


library(tseries)
adf.test(log.imp.ts.random)
pp.test(log.imp.ts.random)
kpss.test(log.imp.ts.random)

log.imp.ts.random = na.omit(log.imp.ts.random)
acf(log.imp.ts.random)
pacf(log.imp.ts.random)
spectrum(log.imp.ts.random)

library(forecast)
fit <- auto.arima(log.imp.ts.random, approximation = FALSE, stepwise = FALSE)
summary(fit)
tsdiag(fit)

# Ljung Box Test
Box.test(fit$residuals, type = "Ljung-Box")
Box.test(fit$residuals^2, type = "Ljung-Box")
Box.test(fit$residuals, lag = 24, type = "Ljung-Box")
Box.test(fit$residuals, lag = 36, type = "Ljung-Box")
log.imp.random.res <- fit$residuals
spectrum(log.imp.random.res)

This is the data I dput from R.

structure(list(DATE = structure(1:412, .Label = c("1985-01-01", 
"1985-02-01", "1985-03-01", "1985-04-01", "1985-05-01", "1985-06-01", 
"1985-07-01", "1985-08-01", "1985-09-01", "1985-10-01", "1985-11-01", 
"1985-12-01", "1986-01-01", "1986-02-01", "1986-03-01", "1986-04-01", 
"1986-05-01", "1986-06-01", "1986-07-01", "1986-08-01", "1986-09-01", 
"1986-10-01", "1986-11-01", "1986-12-01", "1987-01-01", "1987-02-01", 
"1987-03-01", "1987-04-01", "1987-05-01", "1987-06-01", "1987-07-01", 
"1987-08-01", "1987-09-01", "1987-10-01", "1987-11-01", "1987-12-01", 
"1988-01-01", "1988-02-01", "1988-03-01", "1988-04-01", "1988-05-01", 
"1988-06-01", "1988-07-01", "1988-08-01", "1988-09-01", "1988-10-01", 
"1988-11-01", "1988-12-01", "1989-01-01", "1989-02-01", "1989-03-01", 
"1989-04-01", "1989-05-01", "1989-06-01", "1989-07-01", "1989-08-01", 
"1989-09-01", "1989-10-01", "1989-11-01", "1989-12-01", "1990-01-01", 
"1990-02-01", "1990-03-01", "1990-04-01", "1990-05-01", "1990-06-01", 
"1990-07-01", "1990-08-01", "1990-09-01", "1990-10-01", "1990-11-01", 
"1990-12-01", "1991-01-01", "1991-02-01", "1991-03-01", "1991-04-01", 
"1991-05-01", "1991-06-01", "1991-07-01", "1991-08-01", "1991-09-01", 
"1991-10-01", "1991-11-01", "1991-12-01", "1992-01-01", "1992-02-01", 
"1992-03-01", "1992-04-01", "1992-05-01", "1992-06-01", "1992-07-01", 
"1992-08-01", "1992-09-01", "1992-10-01", "1992-11-01", "1992-12-01", 
"1993-01-01", "1993-02-01", "1993-03-01", "1993-04-01", "1993-05-01", 
"1993-06-01", "1993-07-01", "1993-08-01", "1993-09-01", "1993-10-01", 
"1993-11-01", "1993-12-01", "1994-01-01", "1994-02-01", "1994-03-01", 
"1994-04-01", "1994-05-01", "1994-06-01", "1994-07-01", "1994-08-01", 
"1994-09-01", "1994-10-01", "1994-11-01", "1994-12-01", "1995-01-01", 
"1995-02-01", "1995-03-01", "1995-04-01", "1995-05-01", "1995-06-01", 
"1995-07-01", "1995-08-01", "1995-09-01", "1995-10-01", "1995-11-01", 
"1995-12-01", "1996-01-01", "1996-02-01", "1996-03-01", "1996-04-01", 
"1996-05-01", "1996-06-01", "1996-07-01", "1996-08-01", "1996-09-01", 
"1996-10-01", "1996-11-01", "1996-12-01", "1997-01-01", "1997-02-01", 
"1997-03-01", "1997-04-01", "1997-05-01", "1997-06-01", "1997-07-01", 
"1997-08-01", "1997-09-01", "1997-10-01", "1997-11-01", "1997-12-01", 
"1998-01-01", "1998-02-01", "1998-03-01", "1998-04-01", "1998-05-01", 
"1998-06-01", "1998-07-01", "1998-08-01", "1998-09-01", "1998-10-01", 
"1998-11-01", "1998-12-01", "1999-01-01", "1999-02-01", "1999-03-01", 
"1999-04-01", "1999-05-01", "1999-06-01", "1999-07-01", "1999-08-01", 
"1999-09-01", "1999-10-01", "1999-11-01", "1999-12-01", "2000-01-01", 
"2000-02-01", "2000-03-01", "2000-04-01", "2000-05-01", "2000-06-01", 
"2000-07-01", "2000-08-01", "2000-09-01", "2000-10-01", "2000-11-01", 
"2000-12-01", "2001-01-01", "2001-02-01", "2001-03-01", "2001-04-01", 
"2001-05-01", "2001-06-01", "2001-07-01", "2001-08-01", "2001-09-01", 
"2001-10-01", "2001-11-01", "2001-12-01", "2002-01-01", "2002-02-01", 
"2002-03-01", "2002-04-01", "2002-05-01", "2002-06-01", "2002-07-01", 
"2002-08-01", "2002-09-01", "2002-10-01", "2002-11-01", "2002-12-01", 
"2003-01-01", "2003-02-01", "2003-03-01", "2003-04-01", "2003-05-01", 
"2003-06-01", "2003-07-01", "2003-08-01", "2003-09-01", "2003-10-01", 
"2003-11-01", "2003-12-01", "2004-01-01", "2004-02-01", "2004-03-01", 
"2004-04-01", "2004-05-01", "2004-06-01", "2004-07-01", "2004-08-01", 
"2004-09-01", "2004-10-01", "2004-11-01", "2004-12-01", "2005-01-01", 
"2005-02-01", "2005-03-01", "2005-04-01", "2005-05-01", "2005-06-01", 
"2005-07-01", "2005-08-01", "2005-09-01", "2005-10-01", "2005-11-01", 
"2005-12-01", "2006-01-01", "2006-02-01", "2006-03-01", "2006-04-01", 
"2006-05-01", "2006-06-01", "2006-07-01", "2006-08-01", "2006-09-01", 
"2006-10-01", "2006-11-01", "2006-12-01", "2007-01-01", "2007-02-01", 
"2007-03-01", "2007-04-01", "2007-05-01", "2007-06-01", "2007-07-01", 
"2007-08-01", "2007-09-01", "2007-10-01", "2007-11-01", "2007-12-01", 
"2008-01-01", "2008-02-01", "2008-03-01", "2008-04-01", "2008-05-01", 
"2008-06-01", "2008-07-01", "2008-08-01", "2008-09-01", "2008-10-01", 
"2008-11-01", "2008-12-01", "2009-01-01", "2009-02-01", "2009-03-01", 
"2009-04-01", "2009-05-01", "2009-06-01", "2009-07-01", "2009-08-01", 
"2009-09-01", "2009-10-01", "2009-11-01", "2009-12-01", "2010-01-01", 
"2010-02-01", "2010-03-01", "2010-04-01", "2010-05-01", "2010-06-01", 
"2010-07-01", "2010-08-01", "2010-09-01", "2010-10-01", "2010-11-01", 
"2010-12-01", "2011-01-01", "2011-02-01", "2011-03-01", "2011-04-01", 
"2011-05-01", "2011-06-01", "2011-07-01", "2011-08-01", "2011-09-01", 
"2011-10-01", "2011-11-01", "2011-12-01", "2012-01-01", "2012-02-01", 
"2012-03-01", "2012-04-01", "2012-05-01", "2012-06-01", "2012-07-01", 
"2012-08-01", "2012-09-01", "2012-10-01", "2012-11-01", "2012-12-01", 
"2013-01-01", "2013-02-01", "2013-03-01", "2013-04-01", "2013-05-01", 
"2013-06-01", "2013-07-01", "2013-08-01", "2013-09-01", "2013-10-01", 
"2013-11-01", "2013-12-01", "2014-01-01", "2014-02-01", "2014-03-01", 
"2014-04-01", "2014-05-01", "2014-06-01", "2014-07-01", "2014-08-01", 
"2014-09-01", "2014-10-01", "2014-11-01", "2014-12-01", "2015-01-01", 
"2015-02-01", "2015-03-01", "2015-04-01", "2015-05-01", "2015-06-01", 
"2015-07-01", "2015-08-01", "2015-09-01", "2015-10-01", "2015-11-01", 
"2015-12-01", "2016-01-01", "2016-02-01", "2016-03-01", "2016-04-01", 
"2016-05-01", "2016-06-01", "2016-07-01", "2016-08-01", "2016-09-01", 
"2016-10-01", "2016-11-01", "2016-12-01", "2017-01-01", "2017-02-01", 
"2017-03-01", "2017-04-01", "2017-05-01", "2017-06-01", "2017-07-01", 
"2017-08-01", "2017-09-01", "2017-10-01", "2017-11-01", "2017-12-01", 
"2018-01-01", "2018-02-01", "2018-03-01", "2018-04-01", "2018-05-01", 
"2018-06-01", "2018-07-01", "2018-08-01", "2018-09-01", "2018-10-01", 
"2018-11-01", "2018-12-01", "2019-01-01", "2019-02-01", "2019-03-01", 
"2019-04-01"), class = "factor"), IMPCH = c(293.1, 281, 293, 
283.3, 295.1, 348.7, 344.4, 311.8, 391.8, 385.5, 327.5, 306.5, 
459.5, 376.6, 401.8, 264.9, 319, 375.7, 450.2, 434.7, 413.4, 
398.5, 486, 390.7, 520.6, 565.3, 482.5, 468.3, 514.7, 536.3, 
560, 598.1, 549.6, 567.9, 489.8, 440.5, 652.8, 650.6, 509.9, 
551.9, 615.1, 720.8, 761.6, 803.9, 793.3, 834, 798.8, 818.2, 
788.9, 798.1, 667.3, 728.5, 937.9, 1021.7, 1162.7, 1279.6, 1179.3, 
1340.4, 1133.8, 951.5, 1186.1, 993.8, 931, 996.4, 1173.5, 1317.2, 
1492.5, 1568.6, 1432.1, 1652.1, 1367.9, 1126.2, 1321.6, 1253.7, 
974.3, 1104.2, 1380.8, 1525.5, 1813.2, 1872.4, 1936.3, 2236.4, 
1957.6, 1593.2, 1912.6, 1693.7, 1441.8, 1677.6, 1853.9, 2179.2, 
2503.8, 2613, 2760.5, 2748.4, 2316, 2027, 2187.6, 1862.4, 2083.2, 
2226.3, 2376.3, 2754.2, 2981.1, 3223.3, 3338.7, 3277.6, 2899.6, 
2329.6, 2763.1, 2499.2, 2183, 2491.6, 2979, 3463.3, 3645.4, 4165.8, 
4134.4, 4101.2, 3534.3, 2826.5, 3450.6, 3001.5, 2910.4, 3148.3, 
3654.9, 3960.7, 4311.8, 4804.7, 4584.1, 4714.3, 3868, 3133.9, 
3657.7, 3539.6, 2863.7, 3247.9, 3954.3, 4111.2, 4816.7, 5495.7, 
5480.7, 5812.9, 4585.4, 3947, 4667.6, 4262.4, 3628.6, 4445, 4795.1, 
5213.5, 5777.2, 6073.6, 6561.4, 6606.5, 5425.7, 5101.1, 5453.2, 
4559.6, 4798.1, 5262.9, 5539.4, 6020.2, 6556.2, 6779.9, 7125.2, 
7377.7, 6374.1, 5322.1, 5654, 5563.1, 5204, 5818.9, 6363.1, 7117.4, 
7405.7, 8022.1, 8198.2, 8207.9, 7543.5, 6690.3, 6902.1, 6584.4, 
6424.1, 7070.5, 7850.2, 8541.7, 9246.4, 10054, 10061.7, 10611.6, 
9066.8, 7604.7, 8427.5, 6375.6, 7590.2, 7686.8, 7757.9, 8398.2, 
8975.3, 10042.9, 9927.8, 10808.3, 8878.8, 7409.1, 8415.4, 8020.8, 
7259, 9097.6, 9846.9, 10727.2, 11213.2, 12671.4, 12291.5, 11455, 
12569.6, 11625, 11403.497575, 9629.62711, 10110.044562, 11521.852382, 
11884.701493, 12127.301429, 13438.63509, 13764.867008, 14747.525418, 
16458.317607, 14156.947961, 13192.779263, 14089.015496, 11267.147675, 
13800.119971, 14744.78415, 15067.110923, 16887.762591, 17562.099879, 
18067.867052, 18386.945745, 19718.157481, 19678.992143, 17412.030829, 
17885.84061, 16937.594812, 16184.944952, 18148.45816, 19053.18688, 
20976.701857, 21272.66946, 22421.292348, 23294.481679, 24382.852726, 
22426.128316, 20485.952995, 21382.505907, 17905.353467, 20531.25833, 
21459.069933, 22317.635131, 23989.699396, 24632.010765, 26713.335235, 
27570.617915, 29388.601739, 27775.079221, 24109.185573, 25640.562672, 
23038.880362, 22723.044235, 24241.522773, 25290.574442, 27070.961198, 
28601.170814, 28424.501435, 29418.96253, 31555.406402, 29780.718791, 
25656.56128, 26193.032145, 24095.886455, 22440.24177, 25951.666996, 
27634.532443, 27930.640534, 31247.270669, 31823.697889, 33078.730631, 
34032.388283, 28265.02503, 25079.514978, 24743.457402, 18845.49521, 
21224.713513, 21920.595248, 22734.147846, 23972.774237, 25671.084409, 
25798.119656, 27893.916592, 29557.782865, 27541.720775, 26470.075735, 
25215.919006, 23342.777514, 24292.213197, 25920.188141, 29052.438345, 
32843.100035, 33266.833594, 35375.288431, 35196.698854, 35083.299437, 
34564.293893, 30799.583148, 31377.353746, 27244.735813, 27599.666857, 
29580.282706, 32788.071613, 34374.830793, 35152.243254, 37374.136523, 
36418.64286, 37824.071703, 36764.911636, 32872.285127, 34417.54042, 
28105.186419, 31431.348931, 33016.253834, 34937.829923, 35949.359451, 
37930.755206, 37280.629144, 37891.823059, 40257.083524, 39543.693182, 
34857.579544, 37193.658803, 32742.677585, 27294.067203, 33131.926306, 
36617.62364, 35885.978832, 38800.430628, 39161.299515, 40144.392508, 
41845.472131, 40112.279565, 37500.212876, 38377.19956, 30700.352329, 
31420.875281, 36450.218795, 38188.13577, 39607.118661, 40319.618346, 
40093.817085, 45102.77541, 45335.351722, 42483.529438, 40395.902459, 
38589.696731, 31563.988155, 41136.91753, 36121.394467, 39082.029905, 
41453.839795, 41215.078176, 44138.055272, 45724.951242, 44309.93252, 
41884.774152, 37980.997419, 37126.43412, 36066.892525, 29812.326908, 
32920.204539, 37513.726589, 38539.190214, 39438.857738, 43221.774205, 
42020.928547, 43798.098424, 42602.631733, 39358.926061, 41339.271457, 
32788.257379, 34162.652909, 37443.227019, 41760.628206, 42261.443136, 
43565.877223, 45788.142973, 45409.011908, 48137.650772, 48107.695614, 
44456.374736, 45765.638804, 39020.588028, 38327.634757, 38303.872419, 
43965.727082, 44612.085871, 47120.590572, 47869.178478, 50014.983823, 
52202.335411, 46500.846174, 45972.109413, 41603.830547, 33194.39804, 
31175.673203, 34798.929472)), class = "data.frame", row.names = c(NA, 
-412L))