
Last chance! 50% off unlimited learning
Sale ends in
Rootograms of observed and fitted values.
# S3 method for default
rootogram(x, fitted, names = NULL, scale = c("sqrt", "raw"),
type = c("hanging", "standing", "deviation"),
shade = FALSE, legend = TRUE,
legend_args = list(x = 0, y = 0.2, height = 0.6), df = NULL,
rect_gp = NULL, rect_gp_args = list(),
lines_gp = gpar(col = "red", lwd = 2),
points_gp = gpar(col = "red"), pch = 19,
xlab = NULL, ylab = NULL, ylim = NULL,
main = NULL, sub = NULL,
margins = unit(0, "lines"),
title_margins = NULL, legend_width = NULL,
main_gp = gpar(fontsize = 20),
sub_gp = gpar(fontsize = 15),
name = "rootogram", prefix = "",
keep_aspect_ratio = FALSE,
newpage = TRUE, pop = TRUE,
return_grob = FALSE, …)
either a vector or a 1-way table of frequencies.
a vector of fitted frequencies.
a vector of names passed to grid_barplot
, if set
to NULL
the names of x
are used.
a character string indicating whether the values should be plotted on the raw or square root scale.
a character string indicating if the bars for the observed
frequencies should be hanging
or standing
or indicate the deviation
between observed and fitted frequencies.
logical specifying whether rect_gp
should be set
to colors corresponding to the pearson residuals, i.e., if a
residual-based shading should be applied to the bars.
either a legend-generating function, or a legend
function (see details and legends
), or a logical.
If legend
is NULL
or TRUE
and gp
is a
function, legend defaults to legend_resbased
.
list of arguments for the legend-generating function, if specified.
degrees of freedom passed to the shading functions used for inference.
a "gpar"
object controlling the grid graphical
parameters of the rectangles, shading function or a
corresponding generating function (see shadings
). If
unspecified and no shading is applied, defaults to light grey fill color for the bars.
list of arguments for the shading-generating
function, if specified for rect_gp
.
a "gpar"
object controlling the grid graphical
parameters of the lines.
a "gpar"
object controlling the grid graphical
parameters of the points.
plotting character for the points.
a label for the x axis.
a label for the y axis.
limits for the y axis.
either a logical, or a character string used for plotting
the main title. If main
is a logical and TRUE
, the
name of the object supplied as x
is used.
a character string used for plotting the subtitle.
If sub
is a logical and TRUE
and main
is unspecified, the
name of the object supplied as x
is used.
either an object of class "unit"
of length 4, or
a numeric vector of length 4. The elements are recycled as needed.
The four components specify the top, right,
bottom, and left margin of the plot, respectively.
When a numeric vector is supplied, the numbers are interpreted as
"lines"
units. In addition, the unit or numeric vector
may have named arguments
(top, right, bottom, and left), in which
case the non-named arguments specify the default values (recycled as
needed), overloaded by the named arguments.
either an object of class "unit"
of length 2, or
a numeric vector of length 2. The elements are recycled as needed.
The two components specify the top and bottom title margin
of the plot, respectively. The default for each
specified title are 2 lines (and 0 else), except when a
legend is plotted and keep_aspect_ratio
is TRUE
: in
this case, the default values of both margins are set as to align
the heights of legend and actual plot.
When a numeric vector is supplied, the numbers are interpreted as
"lines"
units. In addition, the unit or numeric vector
may have named arguments (top and bottom), in which
case the non-named argument specify the default value (recycled as
needed), overloaded by the named arguments.
An object of class "unit"
of length
1 specifying the width of the legend (if any). Default: 5 lines.
object of class "gpar"
containing the graphical parameters used for the main (sub) title, if specified.
name of the plotting viewport.
logical indicating whether the aspect ratio should be fixed or not.
optional character string used as a prefix for the generated viewport and grob names.
logical. Should grid.newpage
be called
before plotting?
logical. Should the viewport created be popped?
logical. Should a snapshot of the display be returned as a grid grob?
further arguments passed to grid_barplot
.
The observed frequencies are displayed as bars and the fitted frequencies as a line. By default a sqrt scale is used to make the smaller frequencies more visible.
J. W. Tukey (1977), Exploratory Data Analysis. Addison Wesley, Reading, MA.
M. Friendly (2000), Visualizing Categorical Data. SAS Institute, Cary, NC.
# NOT RUN {
## Simulated data examples:
dummy <- rnbinom(200, size = 1.5, prob = 0.8)
observed <- table(dummy)
fitted1 <- dnbinom(as.numeric(names(observed)),
size = 1.5, prob = 0.8) * sum(observed)
fitted2 <- dnbinom(as.numeric(names(observed)),
size = 2, prob = 0.6) * sum(observed)
rootogram(observed, fitted1)
rootogram(observed, fitted2)
## Real data examples:
data("HorseKicks")
HK.fit <- goodfit(HorseKicks)
summary(HK.fit)
plot(HK.fit)
## or equivalently
rootogram(HK.fit)
data("Federalist")
F.fit <- goodfit(Federalist, type = "nbinomial")
summary(F.fit)
plot(F.fit)
## (Pearson) residual-based shading
data("Federalist")
Fed_fit0 <- goodfit(Federalist, type = "poisson")
plot(Fed_fit0, shade = TRUE)
# }
Run the code above in your browser using DataLab