## load data, use ordered factors as numeric, and grouped factor version of width
data("CrabSatellites", package = "vcdExtra")
CrabSatellites <- transform(CrabSatellites,
color = as.numeric(color),
spine = as.numeric(spine),
cwidth = cut(width, c(-Inf, seq(23.25, 29.25), Inf))
)
## Agresti, Table 4.4
aggregate(CrabSatellites$satellites,
list(CrabSatellites$cwidth), function(x)
round(c(Number = length(x), Sum = sum(x), Mean = mean(x), Var = var(x)), digits = 2))
## Agresti, Figure 4.4
plot(tapply(satellites, cwidth, mean) ~ tapply(width, cwidth, mean),
data = CrabSatellites,
ylim = c(0, 6), pch = 19, cex = 1.5,
xlab = "Mean carapace width (cm)",
ylab = "Mean number of satellites")
## More examples: ?countreg::CrabSatellites` has examples of other plots and count data models
Run the code above in your browser using DataLab