Learn R Programming

touchard (version 2.0.1)

rgram: Tukey's (hanging, standing, suspended) Rootogram for Assessing a Touchard Model Fit

Description

The Hanging Rootogram is variation of the histogram with the vertical axis showing the square root of the frequencies hanging from (Touchard) fitted values so that the discrepancies are visualized against a straight line (the axis) rather than against a curve.

Usage

rgram(object, xlim = NULL, ylim = NULL, xlab = "Count", ylab = NULL, main = NULL, 
breaks = NULL, border = "black", fill = "lightgray", col = "blue", 
         lwd = 2, pch = 19, lty = 1,  axes = TRUE, width = NULL, plot = TRUE, 
         style = c("hanging", "standing", "suspended"), scale = c("sqrt", "raw"), 
         max = NULL, …)

Arguments

object

either a toufit or a toureg object.

breaks

numeric. Breaks for the bar intervals.

style

character. Style of rootogram (see below).

scale

character. Scale of vertical axis, raw frequencies or their square roots; style="standing" with scale="raw" results in the usual histogram with the fitted curve superimposed.

plot

logical. Should the plot be displayed?

width

numeric. Widths of the histogram bars.

main

character. Title for the plot.

xlab

character. Label for the x axis.

ylab

character. Label for the y axis.

xlim, ylim, border, fill, col, lwd, pch, lty, axes

graphical parameters.

max

the largest count value used when using the rgram with toureg objects. If NULL, it sets to max(1.5 * max(count), 20L).

further graphical parameters passed to the plotting function.

Value

Returns invisibly a data frame with quantities used in plotting.

Details

The rootogram is a visual tool for comparing the empirical distribution and fitted values (here from a Touchard model). The square-root scale de-emphasizes outlying values and right skewness (common for count data). The hanging (from the fitted values) style allows discrepancies to be visualized against a straight line (the axis).

The code has been largely based on more general rootogram functions: rootogram in package vcd and countreg::rootogram available through R-forge.

References

Friendly M, Meyer D (2015). Discrete Data Analysis with R. Chapman and Hall.

Kleiber C, Zeileis A (2016). Visualizing Count Data Regressions Using Rootograms. The American Statistician, 70(3), 296--303. 10.1080/00031305.2016.1173590.

Tukey JW (1977). Exploratory Data Analysis. Addison-Wesley, Reading.

See Also

rootogram, touplot

Examples

Run this code
# NOT RUN {
data(Epilepsy)
seiz <- seizures
fm <- toufit( seiz )
rgram(fm)

data(Accidents)
acc <- within(subset(Accidents, subset=Year==2013), {
FriSat <- ifelse(WeekDay > 5, 1, 0)
Spring <- ifelse(Season == "Spring", 1, 0)
})
fmTraff <- toureg( Y ~ FriSat + Spring, data = acc )
rgram(fmTraff)

# }

Run the code above in your browser using DataLab