brms's pp_mixture() on a maximum-likelihood fit. For a mixture()
fit, including a mixture of ordinal families, and for a fit of
frmtmb.latent's mixture_mvn(), it gives the probability that each
observation came from each component, given its response, with the
parameters at their
estimates. Estimate is mixture_probs(). The quantile columns are
a Wald interval on the logit scale, so they stay inside (0, 1): the
logit of the estimate plus a normal quantile times its delta-method
standard error, taken over the estimated parameters and the
group-level effects. Est.Error is the standard deviation of that
same law, the probability plogis(Z) with Z normal around the
logit, integrated numerically (100-point Gauss-Hermite, and adaptive
quadrature where the law is wide). brms reports
the mean, the SD and the quantiles of the same probability over the
posterior draws; pp_mixture() on frmtmb.sample::frm_sample()
draws does that here.
Usage
pp_mixture(x, ...)
# S3 method for class 'frmtmb_fit'
pp_mixture(
x,
newdata = NULL,
re_formula = NULL,
resp = NULL,
ndraws = NULL,
draw_ids = NULL,
log = FALSE,
summary = TRUE,
robust = FALSE,
probs = c(0.025, 0.975),
...
)Arguments
- x
A
frmtmb_fitwith a mixture family.- ...
Refused: an argument the method does not have is an error naming it.
- newdata, re_formula
brms's arguments, in brms's positions.
newdatais refused: the probabilities classify the rows the model was fitted on.re_formula = NULL(the default) conditions on the group-level effects, which is what is computed; any other value is refused.- resp
The response, for brms's signature. A multivariate fit is refused.
- ndraws, draw_ids, summary, robust
brms's draws arguments. A maximum-likelihood fit has no draws, so a value other than the default is refused by name with the reason.
- log
If
TRUE, log probabilities: the estimate and the interval ends are logged, andEst.Erroris the standard deviation of the log under the same law.- probs
Probabilities of the quantile columns, as in brms.
Details
Why not the delta-method standard error of the probability itself: a
probability near 0 or 1 is far from linear in the parameters, and
that first-order error understates the spread there by orders of
magnitude. On a two-component gaussian mixture of 300 rows, against
brms 2.23.0's pp_mixture() on the same data (4 chains of 1500
draws, brms's default priors), the delta-method error was a median
0.36 of brms's posterior SD over all 300 rows, and 0.008 within 1e-4
of an edge. Est.Error as reported here was a median 1.11 of brms's
SD over all rows, and 0.84 to 1.27 (medians of bins by distance from
the edge) for probabilities between 0.001 and 0.999. Within 0.001 of
an edge it overstates: 2.4 and 4.8 times brms's SD (bin medians),
where brms's is a median 0.015 and 0.007. The interval's width was a
median 1.04 of brms's, and each of the 300 estimates was inside
brms's 95% interval.
The array has brms's shape and names: observations by statistics by
components, with the components named P(K = k | Y). For a
group-level mixture (mixture(groups = )) the rows are groups, as in
mixture_probs().
See also
mixture_probs() for the bare matrix.
Examples
set.seed(4)
dd <- data.frame(y = c(rnorm(60, -2), rnorm(60, 3)))
fit <- frm(bf(y ~ 1), family = mixture(gaussian(), gaussian()),
data = dd)
pm <- pp_mixture(fit)
dim(pm)
#> [1] 120 4 2
head(pm[, , "P(K = 1 | Y)"])
#> Estimate Est.Error Q2.5 Q97.5
#> 1 0.9999988 0.0006673988 0.9998003 1.0000000
#> 2 1.0000000 0.0005017832 0.9999854 1.0000000
#> 3 0.9999416 0.0020069243 0.9974393 0.9999987
#> 4 0.9999893 0.0011067662 0.9991832 0.9999999
#> 5 0.9957559 0.0181300376 0.9458534 0.9996828
#> 6 0.9999818 0.0013103284 0.9988331 0.9999997
all.equal(unname(pm[, "Estimate", ]), unname(mixture_probs(fit)))
#> [1] TRUE