This function calculates the probability P(Y | X, data), where Y and X are two (non overlapping) sets of joint variates. The function also gives quantiles about the possible variability of the probability P(Y | X, newdata, data) that we could have if more learning data were provided, as well as a number of samples of the possible values of such probabilities. If several joint values are given for Y or X, the function will create a 2D grid of results for all possible compbinations of the given Y and X values. This function also allows for base-rate or other prior-probability corrections: If a prior (for instance, a base rate) for Y is given, the function will calculate the P(Y | X, data, prior) from P(X | Y, data) and the prior by means of Bayes's theorem.
Usage
Pr(
Y,
X = NULL,
learnt,
priorY = NULL,
nsamples = 100L,
quantiles = c(0.055, 0.25, 0.75, 0.945),
parallel = TRUE,
silent = TRUE,
usememory = TRUE,
keepYX = TRUE
)
Arguments
- Y
matrix or data.table: set of values of variates of which we want the joint probability of. One variate per column, one set of values per row.
- X
matrix or data.table or
NULL
: set of values of variates on which we want to condition the joint probability ofY
. IfNULL
(default), no conditioning is made (except for conditioning on the learning dataset and prior assumptions). One variate per column, one set of values per row.- learnt
Either a string with the name of a directory or full path for a 'learnt.rds' object, produced by the
learn
function, or such an object itself.- priorY
numeric vector with the same length as the rows of
Y
, orTRUE
, orNULL
(default): prior probabilities or base rates for theY
values. IfTRUE
, the prior probabilities are assumed to be all equal.- nsamples
integer or
NULL
or"all"
: desired number of samples of the variability of the probability forY
. IfNULL
, no samples are reported. If"all"
(orInf
), all samples obtained by thelearn
function are used. Default100
.- quantiles
numeric vector, between 0 and 1, or
NULL
: desired quantiles of the variability of the probability forY
. Defaultc(0.055, 0.25, 0.75, 0.945)
, that is, the 5.5%, 25%, 75%, 94.5% quantiles (these are typical quantile values in the Bayesian literature: they give 50% and 89% credibility intervals, which correspond to 1 shannons and 0.5 shannons of uncertainty). IfNULL
, no quantiles are calculated.- parallel
logical or integer: whether to use pre-existing parallel workers, or how many to create and use. Default
TRUE
.- silent
logical: give warnings or updates in the computation? Default
FALSE
.- usememory
logical: save partial results to disc, to avoid crashes? Default
TRUE
.- keepYX
logical, default
TRUE
: keep a copy of theY
andX
arguments in the output? This is used for the plot method.
Value
A list of class probability
, consisting of the elements values
, and possibly the elements quantiles
(if non-NULL
argument quantiles
), samples
(if non-NULL
argument nsample
), Y
, X
. Element values
: a matrix with the probabilities P(Y|X,data,assumptions), for all combinations of values of Y
(rows) and X
(columns). Element quantiles
: an array with the variability quantiles (3rd dimension of the array) for such probabilities. Element samples
: an array with the variability samples (3rd dimension of the array) for such probabilities. Elements Y
, X
: copies of the Y
and X
arguments.