Description Usage Arguments Details Value Author(s) References See Also Examples
Auxiliary function (i.e. not intended for the average user) called by the arx
, getsm
, getsv
and isat
functions. The diagnostics
function undertakes tests for autocorrelation, ARCH and nonnormality in a residual series x
, and  optionally  perform additional userdefined diagnostics provided via the user.fun
argument (see details). The autocorrelation and ARCH tests are conducted as Ljung and Box (1979) tests of autocorrelation in the residuals and squared residuals, respectively, whereas the test for nonnormality is that of Jarque and Bera (1980).
1 2 3 
x 
numeric vector, typically the residuals from a regression 
s2 
the standard deviation of x 
y 

xreg 

ar.LjungB 
a two element vector or 
arch.LjungB 
a two element vector or 
normality.JarqueB 

verbose 
logical. If 
user.fun 

The argument user.fun
enables the user to specify additional diagnostics. The function must be defined in the global environment (i.e. .GlobalEnv
), and the userdefined function should accept at least the first of the following four arguments: the regressand, the matrix of meanregressors, the vector of residuals, the vector of standardised residuals. Also, the arguments must enter in the order indicated (see example below). However, the userdefined function need of course not use all of these arguments within itself when doing the diagnostics.
The value returned by the userdefined function should be a matrix of dimension m x 3, where m is the number of diagnostic tests performed inside the userdefined function. (If only a single test is performed, then the returned value can be a vector of length 3.) The three columns of the m x 3 matrix should contain, in the following order: 1) the value(s) of the teststatistic(s), 2) the degrees of freedom(s) (or NA
if there are none) of the tests, and 3) the pvalue(s) of the test(s). When checking whether the model passes the diagnostics or not, the pvalue(s) is(are) checked against the value in the second entry of user.fun
If 
a 
If 
a 
Genaro Sucarrat, http://www.sucarrat.net/
C. Jarque and A. Bera (1980): 'Efficient Tests for Normality, Homoscedasticity and Serial Independence'. Economics Letters 6, pp. 255259
G. Ljung and G. Box (1979): 'On a Measure of Lack of Fit in Time Series Models'. Biometrika 66, pp. 265270
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  ##check x for autocorrelation and ARCH, and return a
##dataframe with the results:
set.seed(123)
x < rnorm(40)
diagnostics(x)
##add the JarqueBera normality test to the diagnostics:
diagnostics(x, normality.JarqueB=TRUE)
##check x for autocorrelation and ARCH, and indicate
##whether it passes the check:
diagnostics(x, verbose=FALSE)
##userdefined ShapiroWilks test for normality in the residuals:
SWtest < function(y, xreg, x, zhat, ...){
tmp < shapiro.test(x) #do test on the residuals
return( c(tmp$statistic, NA, tmp$p.value) )
}
diagnostics(x, user.fun=list(name="SWtest", pval=0.025))
diagnostics(x, user.fun=list(name="SWtest", pval=0.025), verbose=FALSE)

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
Please suggest features or report bugs in the GitHub issue tracker.
All documentation is copyright its authors; we didn't write any of that.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.