rootogram | R Documentation |
Rootograms of observed and fitted values.
## Default S3 method:
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, ...)
x |
either a vector or a 1-way table of frequencies. |
fitted |
a vector of fitted frequencies. |
names |
a vector of names passed to |
scale |
a character string indicating whether the values should be plotted on the raw or square root scale. |
type |
a character string indicating if the bars for the observed
frequencies should be |
shade |
logical specifying whether |
legend |
either a legend-generating function, or a legend
function (see details and |
legend_args |
list of arguments for the legend-generating function, if specified. |
df |
degrees of freedom passed to the shading functions used for inference. |
rect_gp |
a |
rect_gp_args |
list of arguments for the shading-generating
function, if specified for |
lines_gp |
a |
points_gp |
a |
pch |
plotting character for the points. |
xlab |
a label for the x axis. |
ylab |
a label for the y axis. |
ylim |
limits for the y axis. |
main |
either a logical, or a character string used for plotting
the main title. If |
sub |
a character string used for plotting the subtitle.
If |
margins |
either an object of class |
title_margins |
either an object of class |
legend_width |
An object of class |
main_gp , sub_gp |
object of class |
name |
name of the plotting viewport. |
keep_aspect_ratio |
logical indicating whether the aspect ratio should be fixed or not. |
prefix |
optional character string used as a prefix for the generated viewport and grob names. |
newpage |
logical. Should |
pop |
logical. Should the viewport created be popped? |
return_grob |
logical. Should a snapshot of the display be returned as a grid grob? |
... |
further arguments passed to |
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.
Achim Zeileis Achim.Zeileis@R-project.org, David Meyer David.Meyer@R-project.org
J. W. Tukey (1977), Exploratory Data Analysis. Addison Wesley, Reading, MA.
M. Friendly (2000), Visualizing Categorical Data. SAS Institute, Cary, NC.
grid_barplot
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.