Skip to contents

Compute point estimates (median, mean) and credible intervals for parameters, returning a tidy data frame.

Usage

point_interval(
  object,
  ...,
  .width = 0.95,
  .point = c("median", "mean"),
  .interval = c("qi", "hdi")
)

# S3 method for class 'ratiod_fit'
point_interval(
  object,
  ...,
  .width = 0.95,
  .point = c("median", "mean"),
  .interval = c("qi", "hdi")
)

Arguments

object

A ratiod_fit object

...

Parameter names to summarize (unquoted).

.width

Width(s) of credible intervals. Default 0.95.

.point

Point estimate function: "median" (default) or "mean".

.interval

Interval type: "qi" for quantile interval (default), "hdi" for highest density interval.

Value

A data frame with columns for the variable name, point estimate, and interval bounds.

Examples

# \donttest{
# Generate synthetic data
set.seed(444)
n <- 40
df <- data.frame(
  count = rpois(n, lambda = 18),
  effort = rgamma(n, shape = 9, rate = 1),
  depth = rnorm(n),
  site = sample(letters[1:3], n, replace = TRUE)
)

# Fit model
fit <- tratio(
  count | effort ~ depth + (1 | site),
  data = df,
  family = ratiod_poisson_gamma(),
  mode = "hmc",
  control = list(iter = 200, warmup = 100, chains = 1)
)
#> Inference: Exact (Tier 1)
#>   Backend: hmc
#> Fitting ratio model...
#>   Family: poisson_gamma
#>   Observations: 40
#>   Iterations: 200 (warmup: 100)
#> Running NUTS sampler...
#>   Parameters: 9
#>   Iterations: 200 (warmup: 100)
#>   Chains: 1 (cores: 1)

# Get point estimates and 95% intervals
point_interval(fit, beta_num, beta_denom)
#>       .variable      .value     .lower    .upper .width .point .interval
#> 1   beta_num.1.  2.80316650  2.6567789 2.9378082   0.95 median        qi
#> 2   beta_num.2.  0.04961788 -0.0405278 0.1465019   0.95 median        qi
#> 3 beta_denom.1.  2.21952288  2.0513714 2.4173175   0.95 median        qi
#> 4 beta_denom.2. -0.01516783 -0.1359848 0.1001965   0.95 median        qi

# Multiple interval widths
point_interval(fit, beta_num, .width = c(0.5, 0.9, 0.95))
#>     .variable     .value      .lower    .upper .width .point .interval
#> 1 beta_num.1. 2.80316650  2.75420257 2.8520953   0.50 median        qi
#> 2 beta_num.1. 2.80316650  2.67412586 2.9221949   0.90 median        qi
#> 3 beta_num.1. 2.80316650  2.65677887 2.9378082   0.95 median        qi
#> 4 beta_num.2. 0.04961788  0.01675327 0.0790559   0.50 median        qi
#> 5 beta_num.2. 0.04961788 -0.03708209 0.1167516   0.90 median        qi
#> 6 beta_num.2. 0.04961788 -0.04052780 0.1465019   0.95 median        qi
# }