The function produces diagnostics plots for a greybox
model
# S3 method for greybox
plot(x, which = c(1, 2, 4, 6), level = 0.95,
legend = FALSE, ask = prod(par("mfcol")) < length(which) &&
dev.interactive(), lowess = TRUE, ...)
The function produces the number of plots, specified in the parameter which
.
Estimated greybox model.
Which of the plots to produce. The possible options (see details for explanations):
Actuals vs Fitted values;
Standardised residuals vs Fitted;
Studentised residuals vs Fitted;
Absolute residuals vs Fitted;
Squared residuals vs Fitted;
Q-Q plot with the specified distribution;
Fitted over time;
Standardised residuals over observations;
Studentised residuals over observations;
ACF of the residuals;
PACF of the residuals;
Cook's distance over observations with 0.5, 0.75 and 0.95 quantile lines from Fisher's distribution;
Absolute standardised residuals vs Fitted;
Squared standardised residuals vs Fitted;
ACF of the squared residuals;
PACF of the squared residuals.
Confidence level. Defines width of confidence interval. Used in plots (2), (3), (7), (8), (9), (10) and (11).
If TRUE
, then the legend is produced on plots (2), (3) and (7).
Logical; if TRUE
, the user is asked to press Enter before each plot.
Logical; if TRUE
, LOWESS lines are drawn on scatterplots, see lowess.
The parameters passed to the plot functions. Recommended to use with separate plots.
Ivan Svetunkov, ivan@svetunkov.ru
The list of produced plots includes:
Actuals vs Fitted values. Allows analysing, whether there are any issues in the fit. Does the variability of actuals increase with the increase of fitted values? Is the relation well captured? They grey line on the plot corresponds to the perfect fit of the model.
Standardised residuals vs Fitted. Plots the points and the confidence bounds
(red lines) for the specified confidence level
. Useful for the analysis of outliers;
Studentised residuals vs Fitted. This is similar to the previous plot, but with the residuals divided by the scales with the leave-one-out approach. Should be more sensitive to outliers;
Absolute residuals vs Fitted. Useful for the analysis of heteroscedasticity;
Squared residuals vs Fitted - similar to (3), but with squared values;
Q-Q plot with the specified distribution. Can be used in order to see if the
residuals follow the assumed distribution. The type of distribution depends on the one used
in the estimation (see distribution
parameter in alm);
Fitted over time. Plots actuals (black line), fitted values (purple line) and
prediction interval (red lines) of width level
, but only in the case, when there
are some values lying outside of it. Can be used in order to make sure that the model
did not miss any important events over time;
Standardised residuals vs Time. Useful if you want to see, if there is autocorrelation or if there is heteroscedasticity in time. This also shows, when the outliers happen;
Studentised residuals vs Time. Similar to previous, but with studentised residuals;
ACF of the residuals. Are the residuals autocorrelated? See acf for details;
PACF of the residuals. No, really, are they autocorrelated? See pacf for details;
Cook's distance over time. Shows influential observations. 0.5, 0.75 and 0.95 quantile lines from Fisher's distribution are also plotted. If the value is above them then the observation is influencial. This does not work well for non-normal distributions;
Absolute standardised residuals vs Fitted. Similar to the previous, but with absolute values. This is more relevant to the models where scale is calculated as an absolute value of something (e.g. Laplace);
Squared standardised residuals vs Fitted. This is an additional plot needed to diagnose
heteroscedasticity in a model with varying scale. The variance on this plot will be constant if
the adequate model for scale
was constructed. This is more appropriate for normal and
the related distributions.
Which of the plots to produce, is specified via the which
parameter. The plots 2, 3, 7,
8 and 9 also use the parameters level
, which specifies the confidence level for
the intervals.
xreg <- cbind(rlaplace(100,10,3),rnorm(100,50,5))
xreg <- cbind(100+0.5*xreg[,1]-0.75*xreg[,2]+rlaplace(100,0,3),xreg,rnorm(100,300,10))
colnames(xreg) <- c("y","x1","x2","Noise")
ourModel <- alm(y~x1+x2, xreg, distribution="dnorm")
par(mfcol=c(4,4))
plot(ourModel, c(1:14))
Run the code above in your browser using DataLab