plot.gvf.fit | R Documentation |
This function provides basic diagnostic plots for fitted GVF model(s).
## S3 method for class 'gvf.fit'
plot(x, which.more = 1:3, id.n = 3, labels.id = names(residuals(x)),
cex.id = 0.75, label.pos = c(4, 2), cex.caption = 1, Main = NULL, ...)
## S3 method for class 'gvf.fits'
plot(x, which.more = NULL, id.n = 3, labels.id = names(residuals(x)),
cex.id = 0.75, label.pos = c(4, 2), cex.caption = 1, Main = NULL, ...)
## S3 method for class 'gvf.fit.gr'
plot(x, which.more = 1:3, id.n = 3, labels.id = NULL,
cex.id = 0.75, label.pos = c(4, 2), cex.caption = 1, ...)
## S3 method for class 'gvf.fits.gr'
plot(x, which.more = NULL, id.n = 3, labels.id = NULL,
cex.id = 0.75, label.pos = c(4, 2), cex.caption = 1, ...)
x |
An object containing one or more fitted GVF models (see ‘Usage’ for the allowed classes). |
which.more |
Select additional plots beyond the default one (‘Observed vs Fitted’).
Can be any subset of vector |
id.n |
Number of points to be initially labelled in each plot, starting with the most extreme. |
labels.id |
Vector of labels, from which the labels for extreme points will be chosen. |
cex.id |
Magnification of point labels. |
label.pos |
Positioning of labels, for the left half and right half of the graph(s) respectively. |
cex.caption |
Controls the size of |
Main |
Optional string to be added to automatic plot titles. |
... |
Other parameters to be passed through to plotting functions. |
Diagnostic plots can be useful both for assessing the goodness of a GVF model fit qualitatively, and for selecting the “best” GVF model among different alternatives.
This function can provide any of the following 7
plots:
(0) 'Observed vs Fitted' (1) 'Residuals vs Fitted' (2) 'Normal Q-Q' (3) 'Scale-Location' (4) 'Cook's distance' (5) 'Residuals vs Leverage' (6) 'Cook's distances vs Leverage/(1-Leverage)'
The ‘Residuals vs Fitted’ plot is special in that it will be always provided: this explains its zero-th order in the list above. The rest of the list, namely plots 1:6
, exactly matches the numbering convention of function plot.lm
.
Additional plots - beyond ‘Residuals vs Fitted’ - can be requested through argument which.more
. Any subset of 1:6
is allowed, provided its length
does not exceed 3
. Therefore, at most 4
plots will be generated simultaneously.
Note that the default behaviour of this function do depend on whether input object x
stores one or more than one fitted GVF models. In the first case, plots 0:3
will be returned in a multiple plot with a 2x2 layout. In the second case, only the default plot number 0
will be returned, opening a new graphics frame for each different GVF model.
Argument id.n
specifies how many points have to be labelled, starting with the most extreme in terms of residuals: this applies to all plots.
Argument Main
is expected to be seldom (if ever) useful: its main purpose is programming consistency at a deeper level.
All the other arguments have the same meaning as in function plot.lm
.
Diego Zardetto
See plot.lm
and references therein.
GVF.db
to manage ReGenesees archive of registered GVF models, gvf.input
and svystat
to prepare the input for GVF model fitting, fit.gvf
to fit GVF models, drop.gvf.points
to drop alleged outliers from a fitted GVF model and simultaneously refit it, and predictCV
to predict CV values via fitted GVF models.
# Load example data:
data(AF.gvf)
# Inspect available estimates and errors of counts:
str(ee.AF)
# List available registered GVF models:
GVF.db
############################################
# Diagnostic plots for fitted GVF model(s) #
############################################
## (A) Plots of a *single* fitted GVF model ##
# Fit example data to registered GVF model number one:
m <- fit.gvf(ee.AF, 1)
## Default call yields 4 plots:
plot(m)
# Play with argument 'which.more':
## which.more = NULL yields the "Observed vs Fitted" plot only:
plot(m, which.more = NULL)
## which.more = 1 adds the "Residuals vs Fitted" plot:
plot(m, which.more = 1)
## subsets of 1:6 with length <= 3 are allowed:
plot(m, which.more = c(1:2,4))
# Just for illustration, play with other parameters:
plot(m, id.n = 6, col = "blue", pch = 20)
## (B) Plots of *many* fitted GVF models ##
# Fit example data to registered GVF models for frequencies (i.e. number 1:3):
mm <- fit.gvf(ee.AF, 1:3)
## Default call yields the "Observed vs Fitted" plot reported separately for
## each model in subsequent graphics frames:
plot(mm)
# Play with argument 'which.more':
## which.more = 1:3 yields subsequent 2x2 plots:
plot(mm, which.more = 1:3)
## again, subsets of 1:6 are allowed:
plot(mm, which.more = 1)
######################################################
# Diagnostic plots for "grouped" fitted GVF model(s) #
######################################################
# We have at our disposal the following survey design object on household data:
exdes
# Use function svystat to prepare "grouped" estimates and errors of counts
# to be fitted separately (here groups are regions):
ee <- svystat(exdes, y=~ind, by=~age5c:marstat:sex, combo=3, group=~regcod)
lapply(ee, head)
## (C) Plots of a *single* GVF model fitted to different groups ##
# Fit registered GVF model number one separately inside groups:
m.g <- fit.gvf(ee, 1)
## Default call yields 4 plots reported separately for each group
## in subsequent graphics frames:
plot(m.g)
## Play with argument 'which.more' to select different plots:
plot(m.g, which.more = c(1:2,4))
## (D) Plots of *many* GVF model fitted to different groups ##
# Fit all registered GVF models for frequencies separately inside groups:
mm.g <- fit.gvf(ee, 1:3)
## Default call yields the "Residuals vs Fitted" plot reported separately
## for each group in subsequent graphics frames:
plot(mm.g)
## Play with argument 'which.more' to add more plots:
plot(mm.g, which.more = 1:3, id.n = 6, col = "blue", pch = 20)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.