Returns a data frame with the columns 'mean', 'lower', and 'upper' reflecting the mean and lower and upper bounds of a confidence interval (quantiles) for every column in a data frame of draws

ci(df, level = 0.95)

Arguments

df

A data frame of draws with all numeric columns.

level

The sensitivity of the computed confidence interval (CI). Defaults to level = 0.95, reflecting a 95% CI.

Examples

library(logitr)

# Estimate a preference space model
mnl_pref <- logitr(
  data    = yogurt,
  outcome = "choice",
  obsID   = "obsID",
  pars    = c("price", "feat", "brand")
)
#> Running model...
#> Done!

# Obtain 10,000 draws of parameters from model
coefs <- coef(mnl_pref)
covariance <- vcov(mnl_pref)
coef_draws <- as.data.frame(MASS::mvrnorm(10^4, coefs, covariance))

# Compute a confidence interval
ci(coef_draws, level = 0.95)
#>                    mean      lower      upper
#> price        -0.3666291 -0.4142882 -0.3191139
#> feat          0.4927960  0.2562836  0.7325867
#> brandhiland  -3.7160380 -3.9957829 -3.4244018
#> brandweight  -0.6413447 -0.7478007 -0.5337463
#> brandyoplait  0.7350232  0.5760561  0.8904558