
Last chance! 50% off unlimited learning
Sale ends in
serialCorrelationTest
is a generic function used to test for the
presence of lag-one serial correlation using either the rank
von Neumann ratio test, the normal approximation based on the Yule-Walker
estimate of lag-one correlation, or the normal approximation based on the
MLE of lag-one correlation. The function invokes particular
methods
which depend on the class
of the first
argument.
Currently, there is a default method and a method for objects of class "lm"
.serialCorrelationTest(x, ...)
## S3 method for class 'default':
serialCorrelationTest(x, test = "rank.von.Neumann",
alternative = "two.sided", conf.level = 0.95, ...)
## S3 method for class 'lm':
serialCorrelationTest(x, test = "rank.von.Neumann",
alternative = "two.sided", conf.level = 0.95, ...)
"ts"
, or an object of class "lm"
. Undefined (NaN
) and
infinite (Inf
, -Inf
) values are not allowed for "rank.von.Neumann"
(rank von Neumann ratio test; the default),
"AR1.yw"
(z-test based on Yule-Walker lag-one estimate of correlation),
and
"two.sided"
(the default), "greater"
, and "less"
.conf.level=0.95
."htest"
containing the results of the hypothesis test.
See the help file for htest.object
for details.serialCorrelationTest
tests the null hypothesis:
x
is a linear model, the function
serialCorrelationTest
tests the null hypothesis (1) for the
residuals.
The three possible alternative hypotheses are the upper one-sided alternative
(alternative="greater"
):
alternative="less"
):
serialCorrelationTest
allows
you to use one of three possible tests:
test="AR1.yw"
)
The Yule-Walker estimate of the lag-1 autocorrelation is given by:
test="AR1.mle"
)
The function serialCorrelationTest
the Rfunction arima
to
compute the MLE of the lag-one autocorrelation and the estimated variance of this
estimator. As for the test based on the Yule-Walker estimate, the z-statistic is
computed as the estimated lag-one autocorrelation divided by the square root of the
estimated variance.
Test Based on Rank von Neumann Ratio (test="rank.von.Neumann"
)
The null distribution of the serial correlation coefficient may be badly affected
by departures from normality in the underlying process (Cox, 1966; Bartels, 1977).
It is therefore a good idea to consider using a nonparametric test for randomness if
the normality of the underlying process is in doubt (Bartels, 1982).
Wald and Wolfowitz (1943) introduced the rank serial correlation coefficient, which
for lag-1 autocorrelation is simply the Yule-Walker estimate (Equation (5) above)
with the actual observations replaced with their ranks.
von Neumann et al. (1941) introduced a test for randomness in the context of
testing for trend in the mean of a process. Their statistic is given by:
shape1=
$\nu$ and shape2=
$\omega$ and:
test="rank.von.Neumann"
, the function
serialCorrelationTest
does the following:
serialCorrelationTest
issues a warning.
When the sample size is between 3 and 10, the p-value is computed based on
rounding up the computed value of $V_{rank}$ to the nearest possible value
that could be observed in the case of no ties.
Computing a Confidence Interval for the Lag-1 Autocorrelation
The function serialCorrelationTest
computes an approximate
$100(1-\alpha)%$ confidence interval for the lag-1 autocorrelation as follows:
test="AR1.yw"
or test="rank.von.Neumann"
, the Yule-Walker
estimate of lag-1 autocorrelation is used and the variance of the estimated
lag-1 autocorrelation is approximately:
test="AR1.mle"
, the MLE of the lag-1 autocorrelation is used, and its
standard deviation is estimated with the square root of the estimated variance
returned by arima
.htest.object
, acf
, ar
,
arima
, arima.sim
,
link{ts.plot}
, plot.ts
,
lag.plot
, Hypothesis Tests.# Generate a purely random normal process, then use serialCorrelationTest
# to test for the presence of correlation.
# (Note: the call to set.seed allows you to reproduce this example.)
set.seed(345)
x <- rnorm(100)
# Look at the data
#-----------------
dev.new()
ts.plot(x)
dev.new()
acf(x)
# Test for serial correlation
#----------------------------
serialCorrelationTest(x)
#Results of Hypothesis Test
#--------------------------
#
#Null Hypothesis: rho = 0
#
#Alternative Hypothesis: True rho is not equal to 0
#
#Test Name: Rank von Neumann Test for
# Lag-1 Autocorrelation
# (Beta Approximation)
#
#Estimated Parameter(s): rho = 0.02773737
#
#Estimation Method: Yule-Walker
#
#Data: x
#
#Sample Size: 100
#
#Test Statistic: RVN = 1.929733
#
#P-value: 0.7253405
#
#Confidence Interval for: rho
#
#Confidence Interval Method: Normal Approximation
#
#Confidence Interval Type: two-sided
#
#Confidence Level: 95%
#
#Confidence Interval: LCL = -0.1681836
# UCL = 0.2236584
# Clean up
#---------
rm(x)
graphics.off()
#==========
# Now use the R function arima.sim to generate an AR(1) process with a
# lag-1 autocorrelation of 0.8, then test for autocorrelation.
set.seed(432)
y <- arima.sim(model = list(ar = 0.8), n = 100)
# Look at the data
#-----------------
dev.new()
ts.plot(y)
dev.new()
acf(y)
# Test for serial correlation
#----------------------------
serialCorrelationTest(y)
#Results of Hypothesis Test
#--------------------------
#
#Null Hypothesis: rho = 0
#
#Alternative Hypothesis: True rho is not equal to 0
#
#Test Name: Rank von Neumann Test for
# Lag-1 Autocorrelation
# (Beta Approximation)
#
#Estimated Parameter(s): rho = 0.835214
#
#Estimation Method: Yule-Walker
#
#Data: y
#
#Sample Size: 100
#
#Test Statistic: RVN = 0.3743174
#
#P-value: 0
#
#Confidence Interval for: rho
#
#Confidence Interval Method: Normal Approximation
#
#Confidence Interval Type: two-sided
#
#Confidence Level: 95%
#
#Confidence Interval: LCL = 0.7274307
# UCL = 0.9429973
#----------
# Clean up
#---------
rm(y)
graphics.off()
#==========
# The data frame Air.df contains information on ozone (ppb^1/3),
# radiation (langleys), temperature (degrees F), and wind speed (mph)
# for 153 consecutive days between May 1 and September 30, 1973.
# First test for serial correlation in (the cube root of) ozone.
# Note that we must use the test based on the MLE because the time series
# contains missing values. Serial correlation appears to be present.
# Next fit a linear model that includes the predictor variables temperature,
# radiation, and wind speed, and test for the presence of serial correlation
# in the residuals. There is no evidence of serial correlation.
# Look at the data
#-----------------
Air.df
# ozone radiation temperature wind
#05/01/1973 3.448217 190 67 7.4
#05/02/1973 3.301927 118 72 8.0
#05/03/1973 2.289428 149 74 12.6
#05/04/1973 2.620741 313 62 11.5
#05/05/1973 NA NA 56 14.3
#...
#09/27/1973 NA 145 77 13.2
#09/28/1973 2.410142 191 75 14.3
#09/29/1973 2.620741 131 76 8.0
#09/30/1973 2.714418 223 68 11.5
#----------
# Test for serial correlation
#----------------------------
with(Air.df,
serialCorrelationTest(ozone, test = "AR1.mle"))
#Results of Hypothesis Test
#--------------------------
#
#Null Hypothesis: rho = 0
#
#Alternative Hypothesis: True rho is not equal to 0
#
#Test Name: z-Test for
# Lag-1 Autocorrelation
# (Wald Test Based on MLE)
#
#Estimated Parameter(s): rho = 0.5641616
#
#Estimation Method: Maximum Likelihood
#
#Data: ozone
#
#Sample Size: 153
#
#Number NA/NaN/Inf's: 37
#
#Test Statistic: z = 7.586952
#
#P-value: 3.28626e-14
#
#Confidence Interval for: rho
#
#Confidence Interval Method: Normal Approximation
#
#Confidence Interval Type: two-sided
#
#Confidence Level: 95%
#
#Confidence Interval: LCL = 0.4184197
# UCL = 0.7099034
#----------
# Next fit a linear model that includes the predictor variables temperature,
# radiation, and wind speed, and test for the presence of serial correlation
# in the residuals. Note setting the argument na.action = na.exclude in the
# call to lm to correctly deal with missing values.
#----------------------------------------------------------------------------
lm.ozone <- lm(ozone ~ radiation + temperature + wind +
I(temperature^2) + I(wind^2),
data = Air.df, na.action = na.exclude)
# Now test for serial correlation in the residuals.
#--------------------------------------------------
serialCorrelationTest(lm.ozone, test = "AR1.mle")
#Results of Hypothesis Test
#--------------------------
#
#Null Hypothesis: rho = 0
#
#Alternative Hypothesis: True rho is not equal to 0
#
#Test Name: z-Test for
# Lag-1 Autocorrelation
# (Wald Test Based on MLE)
#
#Estimated Parameter(s): rho = 0.1298024
#
#Estimation Method: Maximum Likelihood
#
#Data: Residuals
#
#Data Source: lm.ozone
#
#Sample Size: 153
#
#Number NA/NaN/Inf's: 42
#
#Test Statistic: z = 1.285963
#
#P-value: 0.1984559
#
#Confidence Interval for: rho
#
#Confidence Interval Method: Normal Approximation
#
#Confidence Interval Type: two-sided
#
#Confidence Level: 95%
#
#Confidence Interval: LCL = -0.06803223
# UCL = 0.32763704
# Clean up
#---------
rm(lm.ozone)
Run the code above in your browser using DataLab