Convert native binegbin/bipois dpars to (M, f, delta) coordinates
Source:R/mfd.R
binegbin_dpars_to_mfd.RdInverse of binegbin_mfd_to_dpars(). Reads the rate dpars mu,
lambdaone, lambdatwo back into the interpretable coordinates: the
midpoint M of the two expected counts, congruence f, and source bias
delta, optionally converting NB2 inverse dispersions to overdispersions.
As with the forward direction, the three rates are common to bipois(),
bipois_partialobs(), binegbin() and binegbin_partialobs(), so this
serves all four constructors; only the dispersion arguments differ.
This direction reads a stored fit, so it accepts shapex – the single
dispersion of both exclusive components, declared by every
binegbin fit made before 0.10.0 – as well as the current
shapexone/shapextwo. The forward direction writes only current names;
see its documentation for why the two directions differ.
Usage
binegbin_dpars_to_mfd(
mu,
lambdaone,
lambdatwo,
shapes = NULL,
shapex = NULL,
shapexone = NULL,
shapextwo = NULL
)Arguments
- mu
Shared-component rate.
- lambdaone, lambdatwo
The rates of the two source-exclusive components.
- shapes, shapex
Optional NB2 inverse dispersions. If supplied, the returned list gains
kappas/kappax(= 1/sqrt(shape), soshape = Infgives0).shapexis the single dispersion of both exclusive components, declared by abinegbinfit made before 0.10.0; no shipping family takes it now. A fit ofbipois()orbipois_partialobs()has no dispersion to pass: read its three rates alone.- shapexone, shapextwo
Optional NB2 inverse dispersions of the exclusive components, as taken by both negative-binomial constructors since 0.10.0. If supplied, the returned list gains
kappaxone/kappaxtwo. Mutually exclusive withshapex, which is the same quantity under its older name.
Value
A named list of M, f, delta, plus beta (the bounded bias
tanh(delta)), kappas/kappax when shapes/shapex are supplied, and
kappaxone/kappaxtwo when shapexone/shapextwo are supplied.
Details
Arguments are recycled to a common length, so this vectorises over posterior draws – e.g. to convert a whole posterior into interpretable coordinates.
Boundary behaviour, which the forward direction does not have:
lambdaone == lambdatwo == 0(perfect congruence,f = 1): the bias is genuinely unidentified – there are no exclusive events to be biased – anddeltais returned asNA, not0. Zero would assert an unbiased source, which the data at that point cannot support.M == 0(nothing anywhere):fis undefined and returned asNA.Exactly one exclusive rate
0:deltais+/-Inf, the well-defined limit where one source never records an unshared event.
Because of the first case, round-tripping is exact everywhere except at
f = 1, where delta cannot be recovered. Hold one coordinate system as the
source of truth rather than repeatedly converting back and forth.
Examples
binegbin_dpars_to_mfd(mu = 8.04, lambdaone = 4.75, lambdatwo = 3.17)
#> $M
#> [1] 12
#>
#> $f
#> [1] 0.67
#>
#> $delta
#> [1] 0.2022065
#>
#> $beta
#> [1] 0.1994949
#>
# Round trip
d <- binegbin_mfd_to_dpars(M = 12, f = 0.67, delta = 0.2)
binegbin_dpars_to_mfd(d$mu, d$lambdaone, d$lambdatwo)[c("M", "f", "delta")]
#> $M
#> [1] 12
#>
#> $f
#> [1] 0.67
#>
#> $delta
#> [1] 0.2
#>
# Perfect congruence: bias is unidentified, reported as NA
binegbin_dpars_to_mfd(mu = 12, lambdaone = 0, lambdatwo = 0)$delta
#> [1] NA