Plot the variability of an object of class "probability" as a histogram
Source:R/util_plotfunctions.R
hist.probability.RdThe posterior probabilities calculated with the Pr() function, and outputted as a probability object, have an associated variability that comes from the finite size of the data sample. This variability can be interpreted in two ways:
How the probabilities would change, if we could collect a very large (infinite) amount of additional data, and how likely would such change be;
The relative frequency of a particular variate value in the full (sampled and unsampled) population is unknown; we can quantify our uncertainty about this relative frequency with a probability distribution.
The hist() method for a probability object is a utility to visualize this kind of variability, in the form of a distribution.
Arguments
- x
Object of class "probability", obtained with
Pr().- subset
Named list or named vector: which variate values to display. For the variates corresponding to the names in this list, only the vector of values corresponding to that variate is displayed.
- breaks
NULLor as in functiongraphics::hist(). IfNULL(default), an optimal number of breaks for each probability distribution is computed.- legend
One of the values
"bottomright","bottom","bottomleft","left","topleft","top","topright","right","center"(seegraphics::legend()): plot a legend at that position. A valueFALSEor any other does not plot any legend. Default"top".- lty, lwd, col, alpha.f, xlab, ylab, xlim, ylim, main, grid, add
see analogous arguments in
graphics::matplot()- fill.alpha.f
Numeric, default 0.125: opacity of the histogram filling.
0means no filling.- showmean
Logical, default
TRUE: show the means of the probability distributions? The means correspond to the probabilities about the next observed unit.- ...
Other parameters to be passed to
flexiplot().
Value
Invisibly, an object of class "histogram".
See also
Pr() to calculate posterior probabilities and quantiles.
plot.probability() to plot the posterior probabilities.
flexiplot() (on which hist.probability() is based) for more general plots.
plotquantiles() to plot quantile ranges.
Examples
## Load the example `learnt` object calculated from the "penguins" dataset;
## variates: 'species' and 'bill_len'
learnt <- learntExample
## calculate the probability, and its variability,
## for the value 'Adelie' of the "species" variate
probs <- Pr(Y = data.frame(species = 'Adelie'), learnt = learnt, parallel = 1)
probs$values
#>
#> species [,1]
#> Adelie 0.440685
## show the variability of this probability; equivalently show
## the probability distribution for the relative frequency of
## 'Adelie' penguins in the full population
hist(probs, legend = 'topright')