Learn R Programming

ci (version 0.0.1)

ci_multinom: Proportion CI: Multinomial Variable (3 or more groups)

Description

Calculates simultaneous confidence intervals (CI) for proportions in multinomial variables (k >= 3). This enhanced version of DescTools::MultinomCI() returns a data frame.

Usage

ci_multinom(
  x,
  method = "goodman",
  conf.level = 0.95,
  gr_colname = "group",
  ...
)

Value

A data frame with columns:

  • group or user-specified name (<fct>) -- group names;

  • est (<dbl>) -- proportion estimate;

  • lwr.ci, upr.ci (<dbl>) -- lower and upper CI bounds;

  • x (<int>) -- group size;

  • n (<int>) -- total number of events.

Arguments

x

Vector of group sizes. Best if elements have meaningful names (see examples).

method

Calculation method: "goodman", "sisonglaz", "cplus1", and others. See DescTools::MultinomCI() documentation.

conf.level

Confidence level. Default: 0.95.

gr_colname

Column name (quoted) for group names. Default: "group".

...

Additional parameters for DescTools::MultinomCI().

Details

Similar to DescTools::MultinomCI(), but uses the Goodman method by default and returns a data frame, enabling convenient plotting with ggplot2.

Examples

Run this code
# Example 1: Student grade distribution
# A: 20 students, B: 35 students, C: 25 students, D/F: 15 students
grades <- c("A" = 20, "B" = 35, "C" = 25, "D/F" = 15)
ci_multinom(grades)
# Each row shows the CI for that grade's proportion

# Example 2: Transportation preferences
transport <- c("Car" = 45, "Bus" = 30, "Bike" = 15, "Walk" = 20)
ci_multinom(transport)

# Example 3: Blood type distribution
blood_types <- c("O" = 156, "A" = 134, "B" = 38, "AB" = 22)
ci_multinom(blood_types)

# Example 4: Political party preference
parties <- c("Party A" = 380, "Party B" = 420, "Party C" = 200)
ci_multinom(parties)

# Unnamed frequencies (groups will be numbered)
ci_multinom(c(20, 35, 54))

# Using pipe operator
c("Small" = 20, "Medium" = 35, "Large" = 54) |>
  ci_multinom()

# Different method for simultaneous intervals
c("Small" = 33, "Medium" = 35, "Large" = 30) |>
  ci_multinom(method = "sisonglaz")

# Custom column name for groups
c("Dog" = 65, "Cat" = 48, "Bird" = 22, "Other" = 15) |>
  ci_multinom(gr_colname = "pet_type")

# Example 5: Teaching method effectiveness
# Outcome categories: Poor, Fair, Good, Excellent
outcomes <- c("Poor" = 8, "Fair" = 22, "Good" = 45, "Excellent" = 35)
ci_multinom(outcomes)
# Look for non-overlapping CIs to identify categories that differ significantly

Run the code above in your browser using DataLab