Computes comprehensive summary statistics for the marginal distribution of \(K_J\) under a Gamma prior on \(\alpha\).
Usage
summary_K_marginal(
J,
a,
b,
logS,
M = .QUAD_NODES_DEFAULT,
probs = c(0.05, 0.25, 0.5, 0.75, 0.95)
)Arguments
- J
Integer; sample size (positive integer >= 1).
- a
Numeric; shape parameter of Gamma prior (> 0).
- b
Numeric; rate parameter of Gamma prior (> 0).
- logS
Matrix; pre-computed log-Stirling matrix.
- M
Integer; number of quadrature nodes (default: 80).
- probs
Numeric vector; probability levels for quantiles (default:
c(0.05, 0.25, 0.5, 0.75, 0.95)).
Value
A list with components:
JSample size
aGamma shape parameter
bGamma rate parameter
meanMean \(E[K_J \mid a, b]\)
varVariance \(Var(K_J \mid a, b)\)
sdStandard deviation
cvCoefficient of variation (sd/mean)
modeMode (most likely value)
medianMedian (50th percentile)
quantilesNamed integer vector of quantiles at
probspmfFull PMF vector
cdfFull CDF vector
Details
This function provides a complete summary of the marginal distribution,
combining PMF-based and CDF-based statistics. The mean and variance
computed from the PMF should match exact_K_moments() within
numerical tolerance.
The probs argument allows customization of which quantiles to
report, making it flexible for different reporting needs.
Examples
logS <- compute_log_stirling(50)
summary <- summary_K_marginal(50, 1.5, 0.5, logS)
# View main statistics
summary$mean
#> [1] 8.355487
summary$var
#> [1] 22.76895
summary$mode
#> [1] 6
summary$quantiles
#> q5 q25 q50 q75 q95
#> 2 5 8 11 17
# Custom quantiles
summary2 <- summary_K_marginal(50, 1.5, 0.5, logS,
probs = c(0.025, 0.5, 0.975))
summary2$quantiles
#> q2 q50 q98
#> 1 8 19
# Compare with exact moments
exact <- exact_K_moments(50, 1.5, 0.5)
c(summary$mean - exact$mean, summary$var - exact$var)
#> [1] -7.105427e-15 -4.263256e-14