| stat_pithist | R Documentation |
geom_* and stat_* for Producing PIT Histograms with 'ggplot2'Various geom_* and stat_* used within
autoplot for producing PIT histograms.
stat_pithist(
mapping = NULL,
data = NULL,
geom = "pithist",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
freq = FALSE,
style = c("bar", "line"),
...
)
geom_pithist(
mapping = NULL,
data = NULL,
stat = "pithist",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
freq = FALSE,
style = c("bar", "line"),
...
)
stat_pithist_expected(
mapping = NULL,
data = NULL,
geom = "pithist_expected",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
scale = c("uniform", "normal"),
freq = FALSE,
...
)
geom_pithist_expected(
mapping = NULL,
data = NULL,
stat = "pithist_expected",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
scale = c("uniform", "normal"),
freq = FALSE,
...
)
stat_pithist_confint(
mapping = NULL,
data = NULL,
geom = "pithist_confint",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
scale = c("uniform", "normal"),
level = 0.95,
type = "approximation",
freq = FALSE,
style = c("polygon", "line"),
...
)
geom_pithist_confint(
mapping = NULL,
data = NULL,
stat = "pithist_confint",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
scale = c("uniform", "normal"),
level = 0.95,
type = "approximation",
freq = FALSE,
style = c("polygon", "line"),
...
)
stat_pithist_simint(
mapping = NULL,
data = NULL,
geom = "pithist_simint",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
freq = FALSE,
...
)
geom_pithist_simint(
mapping = NULL,
data = NULL,
stat = "pithist_simint",
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
freq = FALSE,
...
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
The geometric object to use display the data |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
freq |
logical. If |
style |
character specifying the style of pithist. For |
... |
Other arguments passed on to |
stat |
The statistical transformation to use on the data for this layer, as a string. |
scale |
On which scale should the PIT residuals be computed: on the probability scale
( |
level |
numeric. The confidence level required. |
type |
character. Which type of confidence interval should be plotted: '"exact"' or '"approximation"'. According to Agresti and Coull (1998), for interval estimation of binomial proportions an approximation can be better than exact. |
if (require("ggplot2")) {
## Fit model
data("CrabSatellites", package = "countreg")
m1_pois <- glm(satellites ~ width + color, data = CrabSatellites, family = poisson)
m2_pois <- glm(satellites ~ color, data = CrabSatellites, family = poisson)
## Compute pithist
p1 <- pithist(m1_pois, type = "random", plot = FALSE)
p2 <- pithist(m2_pois, type = "random", plot = FALSE)
d <- c(p1, p2)
## Create factor
main <- attr(d, "main")
main <- make.names(main, unique = TRUE)
d$group <- factor(d$group, labels = main)
## Plot bar style PIT histogram
gg1 <- ggplot(data = d) +
geom_pithist(aes(x = mid, y = observed, width = width, group = group), freq = TRUE) +
geom_pithist_simint(aes(x = mid, ymin = simint_lwr, ymax = simint_upr), freq = TRUE) +
geom_pithist_confint(aes(x = mid, y = observed, width = width), style = "line", freq = TRUE) +
geom_pithist_expected(aes(x = mid, y = observed, width = width), freq = TRUE) +
facet_grid(group ~ .) +
xlab("PIT") +
ylab("Frequency")
gg1
gg2 <- ggplot(data = d) +
geom_pithist(aes(x = mid, y = observed, width = width, group = group), freq = FALSE) +
geom_pithist_simint(aes(
x = mid, ymin = simint_lwr, ymax = simint_upr, y = observed,
width = width
), freq = FALSE) +
geom_pithist_confint(aes(x = mid, y = observed, width = width), style = "line", freq = FALSE) +
geom_pithist_expected(aes(x = mid, y = observed, width = width), freq = FALSE) +
facet_grid(group ~ .) +
xlab("PIT") +
ylab("Density")
gg2
## Plot line style PIT histogram
gg3 <- ggplot(data = d) +
geom_pithist(aes(x = mid, y = observed, width = width, group = group), style = "line") +
geom_pithist_confint(aes(x = mid, y = observed, width = width), style = "polygon") +
facet_grid(group ~ .) +
xlab("PIT") +
ylab("Density")
gg3
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.