Takes a fitted
gam object produced by
gam() and produces some diagnostic information
about the fitting procedure and results. The default is to produce 4 residual
plots, some information about the convergence of the smoothness selection optimization, and to run
diagnostic tests of whether the basis dimension choises are adequate.
1 2 3 4
If you want old fashioned plots, exactly as in Wood, 2006, set to
type of residuals, see
Above this k testing uses a random sub-sample of data.
how many re-shuffles to do to get p-value for k testing.
arguments passed to
extra graphics parameters to pass to plotting functions.
Checking a fitted
gam is like checking a fitted
glm, with two main differences. Firstly,
the basis dimensions used for smooth terms need to be checked, to ensure that they are not so small that they force
oversmoothing: the defaults are arbitrary.
choose.k provides more detail, but the diagnostic tests described below and reported by this function may also help. Secondly, fitting may not always be as robust to violation of the distributional assumptions as would be the case for a regular GLM, so slightly more care may be needed here. In particular, the thoery of quasi-likelihood implies that if the mean variance relationship is OK for a GLM, then other departures from the assumed distribution are not problematic: GAMs can sometimes be more sensitive. For example, un-modelled overdispersion will typically lead to overfit, as the smoothness selection criterion tries to reduce the scale parameter to the one specified. Similarly, it is not clear how sensitive REML and ML smoothness selection will be to deviations from the assumed response dsistribution. For these reasons this routine uses an enhanced residual QQ plot.
This function plots 4 standard diagnostic plots, some smoothing parameter estimation convergence information and the results of tests which may indicate if the smoothing basis dimension for a term is too low.
Usually the 4 plots are various residual plots. For the default optimization methods the convergence information is summarized in a readable way, but for other optimization methods, whatever is returned by way of convergence diagnostics is simply printed.
The test of whether the basis dimension for a smooth is adequate is based on computing an estimate of the residual variance
based on differencing residuals that are near neighbours according to the (numeric) covariates of the smooth. This estimate divided by the residual variance is the
k-index reported. The further below 1 this is, the more likely it is that there is missed pattern left in the residuals. The
p-value is computed by simulation: the residuals are randomly re-shuffled
k.rep times to obtain the null distribution of the differencing variance estimator, if there is no pattern in the residuals. For models fitted to more than
k.sample data, the tests are based of
k.sample randomly sampled data. Low p-values may indicate that the basis dimension,
k, has been set too low, especially if the reported
edf is close to
k\', the maximum possible EDF for the term. Note the disconcerting fact that if the test statistic itself is based on random resampling and the null is true, then the associated p-values will of course vary widely from one replicate to the next. Currently smooths of factor variables are not supported and will give an
Doubling a suspect
k and re-fitting is sensible: if the reported
edf increases substantially then you may have been missing something in the first fit. Of course p-values can be low for reasons other than a too low
choose.k for fuller discussion.
The QQ plot produced is usually created by a call to
qq.gam, and plots deviance residuals
against approximate theoretical quantilies of the deviance residual distribution, according to the fitted model.
If this looks odd then investigate further using
qq.gam. Note that residuals for models fitted to binary data contain very little
information useful for model checking (it is necessary to find some way of aggregating them first), so the QQ plot is unlikely
to be useful in this case.
A vector of reference quantiles for the residual distribution, if these can be computed.
Simon N. Wood firstname.lastname@example.org
N.H. Augustin, E-A Sauleaub, S.N. Wood (2012) On quantile quantile plots for generalized linear models. Computational Statistics & Data Analysis. 56(8), 2404-3409.
Wood S.N. (2006) Generalized Additive Models: An Introduction with R. Chapman and Hall/CRC Press.
1 2 3 4 5 6
Loading required package: nlme This is mgcv 1.8-17. For overview type 'help("mgcv-package")'. Gu & Wahba 4 term additive model Method: GCV Optimizer: magic Smoothing parameter selection converged after 8 iterations. The RMS GCV score gradient at convergence was 1.072609e-05 . The Hessian was positive definite. Model rank = 37 / 37 Basis dimension (k) checking results. Low p-value (k-index<1) may indicate that k is too low, especially if edf is close to k'. k' edf k-index p-value s(x0) 9.00 2.32 1.00 0.45 s(x1) 9.00 2.31 0.97 0.35 s(x2) 9.00 7.65 0.96 0.25 s(x3) 9.00 1.23 1.04 0.68
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.