Lab 10: Inference for multinomial data

With solutions

Author

Your Name Here

ImportantBefore you begin

Fill in the author and calpoly-id fields at the very top of this file. Replace "Your Name Here" with your full name and "yourpolynetid" with your Cal Poly username (the part of your email before @calpoly.edu, e.g. jdoe01). Your submission cannot be matched to your record without this.

Where a “Your turn” asks you to save a result by a specific name (shown in bold), use the exact name given — your work is checked automatically.

This lab covers inference for population proportions from multinomial (more than two categories) data. Examples use the NHANES survey data.

library(DescTools)
load('data/nhanes500.RData')

Point estimation

How do U.S. adults perceive their own health?

Point estimation works the same way as for binomial data — tabulate and normalize:

# tabulate counts
health.tbl <- table(nhanes$healthgen)
health.tbl

Excellent     Vgood      Good      Fair      Poor 
       47       162       177        53        11 
# compute sample proportions
health.tbl |> prop.table()

 Excellent      Vgood       Good       Fair       Poor 
0.10444444 0.36000000 0.39333333 0.11777778 0.02444444 

Note that table(...) automatically excludes missing values (50 of 500 responses are missing for this variable).

An estimated 10.44% of U.S. adults report being in excellent health.


How common are homeownership, renting, and other living arrangements?

CautionYour turn 1 [L10]

The homeown variable records whether the participant owns a home, rents a home, or has another living arrangement. Tabulate the counts and store the table as homeown.tbl. Then compute sample proportions and estimate the prevalence of each category. (This data was collected from 2009–2012.)

# tabulate and store
homeown.tbl <- table(nhanes$homeown)
homeown.tbl

  Own  Rent Other 
  345   138    10 
# compute sample proportions
homeown.tbl |> prop.table()

       Own       Rent      Other 
0.69979716 0.27991886 0.02028398 

An estimated 70.0% of U.S. adults own a home; an estimated 28.0% rent; and an estimated 2.0% neither own nor rent. (7 responses are missing and are excluded.)

Testing multinomial proportions

Do health perceptions match a baseline distribution?

To test whether a set of population proportions matches a hypothesized distribution, use chisq.test(...). Supply a table of counts and the hypothesized proportions p:

# chi-square goodness-of-fit test
health.tbl |>
  chisq.test(p = c(0.13, 0.32, 0.35, 0.13, 0.06),
             rescale.p = TRUE)

    Chi-squared test for given probabilities

data:  health.tbl
X-squared = 16.709, df = 4, p-value = 0.002201

The rescale.p = TRUE argument ensures the hypothesized proportions sum to 1 (correcting for rounding).

The data provide evidence that health perceptions differ from the hypothesized baseline (\(\chi^2\) = 16.71 on 4 degrees of freedom, p = 0.0022).


Does homeownership match the asserted 70-25 split?

CautionYour turn 2 [L10]

Suppose that someone asserts 70% of U.S. adults own a home, a quarter rent, and 5% do neither. Test whether the NHANES data support or contradict this hypothesis. Store the full test result as homeown.rslt. Report the result in context following conventional style.

# chi-square goodness-of-fit test
homeown.rslt <- homeown.tbl |>
  chisq.test(p = c(0.7, 0.25, 0.05))
homeown.rslt

    Chi-squared test for given probabilities

data:  homeown.tbl
X-squared = 10.472, df = 2, p-value = 0.005321

The data provide evidence that the shares of homeowners and renters differ from the asserted figures (\(\chi^2\) = 10.47 on 2 degrees of freedom, p = 0.0053).

Residual analysis

# store test output
health.rslt <- health.tbl |>
  chisq.test(p = c(0.13, 0.32, 0.35, 0.13, 0.06),
             rescale.p = TRUE)

# inspect residuals
health.rslt$residuals

 Excellent      Vgood       Good       Fair       Poor 
-1.5728910  1.3718766  1.4198774 -0.7923586 -3.1159900 

The difference from baseline is due to far fewer than expected respondents reporting being in poor health.


Which proportions explain the significant chi-square test for homeownership?

CautionYour turn 3 [L10]

Inspect the residuals from the \(\chi^2\) test you performed for the previous exercise. Explain which (if any) proportions differ from the asserted figures.

# inspect residuals
homeown.rslt$residuals

         Own         Rent        Other 
-0.005383039  1.328613180 -2.950727899 

Significantly fewer respondents than expected neither own nor rent.

Confidence intervals for multinomial proportions

# confidence intervals with bonferroni correction (5 categories)
health.tbl |>
  MultinomCI(method = 'wald', conf.level = 1 - 0.05/5)
                 est      lwr.ci     upr.ci
Excellent 0.10444444 0.067308048 0.14158084
Vgood     0.36000000 0.301715636 0.41828436
Good      0.39333333 0.334018097 0.45264857
Fair      0.11777778 0.078636816 0.15691874
Poor      0.02444444 0.005693337 0.04319555

With 95% confidence, the share of U.S. adults who perceive themselves to be in excellent health is estimated to be between 6.73% and 14.16%.


What are the simultaneous CIs for homeownership?

CautionYour turn 4 [L10]

Construct simultaneous 95% confidence intervals for the share of U.S. adults that own, rent, and do neither. Interpret the interval for the share of homeowners in context following conventional style.

# confidence intervals with bonferroni correction (3 categories)
homeown.tbl |>
  MultinomCI(method = 'wald', conf.level = 1 - 0.05/3)
             est      lwr.ci     upr.ci
Own   0.69979716 0.650378552 0.74921577
Rent  0.27991886 0.231512348 0.32832538
Other 0.02028398 0.005084673 0.03548328

With 95% confidence, the share of U.S. adults who own a home is estimated to be between 65.04% and 74.92%.


NoteSubmitting this assignment
  1. Save the file (Ctrl+S / Cmd+S).
  2. Render to PDF: click Render or press Ctrl+Shift+K / Cmd+Shift+K.
  3. Download both files: in the Files panel, check the .qmd and PDF, then click More ▾ → Export….
  4. Upload the PDF to the Gradescope assignment for this lab.
  5. Upload the .qmd file to the course submission link.