I will be using a multinomial outcome variable about the time of emergency department visit. There are four times in the data: early morning (midnight-6 am), morning (6 am - noon), afternoon (noon - 6 pm), evening (6 pm - midnight). These are coded as early morning is assigned 1, morning assigned 2, afternoon assigned 3, and evening assigned 4. I will be using the variables age, sex, and race to see if the time of emergency department visit varies for these groups.

library(car)
## Loading required package: carData
library(stargazer)
## 
## Please cite as:
##  Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
##  R package version 5.2.2. https://CRAN.R-project.org/package=stargazer
library(survey)
## Loading required package: grid
## Loading required package: Matrix
## Loading required package: survival
## 
## Attaching package: 'survey'
## The following object is masked from 'package:graphics':
## 
##     dotchart
library(questionr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:car':
## 
##     recode
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.6     ✓ stringr 1.4.0
## ✓ tidyr   1.2.0     ✓ forcats 0.5.1
## ✓ readr   2.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x tidyr::expand() masks Matrix::expand()
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
## x tidyr::pack()   masks Matrix::pack()
## x dplyr::recode() masks car::recode()
## x purrr::some()   masks car::some()
## x tidyr::unpack() masks Matrix::unpack()
library(gtsummary)
library(VGAM)
## Loading required package: stats4
## Loading required package: splines
## 
## Attaching package: 'VGAM'
## The following object is masked from 'package:tidyr':
## 
##     fill
## The following object is masked from 'package:survey':
## 
##     calibrate
## The following object is masked from 'package:car':
## 
##     logit
library(svyVGAM)
load("~/Downloads/Stats2-Dem7283 /Stats2/ICPSR_34565-2/DS0001/34565-0001-Data.rda")
dawn2011 <- da34565.0001

#age
dawn2011$age <- Recode(dawn2011$AGECAT, recodes= "-8:NA")

dawn2011$race <- Recode(dawn2011$RACE, recodes= "-8:NA")

dawn2011$sex <- Recode(dawn2011$SEX, recodes= "-8:NA")


dawn2011 <- dawn2011 %>%
  filter(is.na(age)==F,
         is.na(race)==F,
         is.na(sex)==F)

modeldawn <- dawn2011 %>%
  select(age, race, sex, DAYPART)
library(srvyr)
## 
## Attaching package: 'srvyr'
## The following object is masked from 'package:stats':
## 
##     filter
options(scipen = 999)
options(survey.lonely.psu = "adjust")
des <- svydesign(ids = ~PSU,
                 strata = ~STRATA, 
                 weights = ~CASEWGT, 
                 nest = TRUE,
                 data=dawn2011)
library(svyVGAM)
mfit <- svy_vglm(DAYPART~age+race+sex,
                 family=multinomial(refLevel = 1),
                 design=des)



mfit %>%
  tbl_regression()
## ! `broom::tidy()` failed to tidy the model.
## x No tidy method for objects of class svy_vglm
## ✓ `tidy_parameters()` used instead.
## ℹ Add `tidy_fun = broom.helpers::tidy_parameters` to quiet these messages.
## x Unable to identify the list of variables.
## 
## This is usually due to an error calling `stats::model.frame(x)`or `stats::model.matrix(x)`.
## It could be the case if that type of model does not implement these methods.
## Rarely, this error may occur if the model object was created within
## a functional programming framework (e.g. using `lappy()`, `purrr::map()`, etc.).
Characteristic Beta 95% CI1 p-value
(Intercept):1 0.64 0.42, 0.86 <0.001
(Intercept):2 1.2 1.0, 1.3 <0.001
(Intercept):3 1.5 1.4, 1.7 <0.001
age(02) 6 TO 11:(2):1 -0.16 -0.64, 0.32 0.5
age(02) 6 TO 11:(2):2 -0.08 -0.53, 0.36 0.7
age(02) 6 TO 11:(2):3 -0.39 -0.85, 0.07 0.094
age(03) 12 TO 17:(3):1 -0.73 -1.0, -0.50 <0.001
age(03) 12 TO 17:(3):2 -0.76 -1.0, -0.52 <0.001
age(03) 12 TO 17:(3):3 -0.88 -1.1, -0.64 <0.001
age(04) 18 TO 20:(4):1 -1.3 -1.5, -1.0 <0.001
age(04) 18 TO 20:(4):2 -1.3 -1.5, -1.1 <0.001
age(04) 18 TO 20:(4):3 -1.4 -1.6, -1.2 <0.001
age(05) 21 TO 24:(5):1 -0.66 -0.91, -0.41 <0.001
age(05) 21 TO 24:(5):2 -0.57 -0.79, -0.35 <0.001
age(05) 21 TO 24:(5):3 -0.88 -1.1, -0.65 <0.001
age(06) 25 TO 29:(6):1 -0.54 -0.74, -0.34 <0.001
age(06) 25 TO 29:(6):2 -0.61 -0.83, -0.39 <0.001
age(06) 25 TO 29:(6):3 -0.90 -1.1, -0.73 <0.001
age(07) 30 TO 34:(7):1 -0.33 -0.66, -0.01 0.046
age(07) 30 TO 34:(7):2 -0.51 -0.69, -0.34 <0.001
age(07) 30 TO 34:(7):3 -0.63 -0.92, -0.33 <0.001
age(08) 35 TO 44:(8):1 -0.36 -0.61, -0.11 0.005
age(08) 35 TO 44:(8):2 -0.45 -0.71, -0.20 <0.001
age(08) 35 TO 44:(8):3 -0.79 -1.0, -0.56 <0.001
age(09) 45 TO 54:(9):1 -0.27 -0.43, -0.11 <0.001
age(09) 45 TO 54:(9):2 -0.43 -0.64, -0.21 <0.001
age(09) 45 TO 54:(9):3 -0.87 -1.0, -0.71 <0.001
age(10) 55 TO 64:(10):1 0.01 -0.16, 0.18 >0.9
age(10) 55 TO 64:(10):2 -0.27 -0.47, -0.07 0.008
age(10) 55 TO 64:(10):3 -0.74 -0.87, -0.62 <0.001
age(11) AGE 65 OR OLDER:(11):1 0.20 -0.08, 0.47 0.2
age(11) AGE 65 OR OLDER:(11):2 -0.10 -0.32, 0.12 0.4
age(11) AGE 65 OR OLDER:(11):3 -0.79 -1.0, -0.59 <0.001
race(2) BLACK OR AFRICAN AMERICAN ONLY:(2):1 -0.16 -0.23, -0.08 <0.001
race(2) BLACK OR AFRICAN AMERICAN ONLY:(2):2 -0.34 -0.41, -0.27 <0.001
race(2) BLACK OR AFRICAN AMERICAN ONLY:(2):3 -0.40 -0.49, -0.31 <0.001
race(3) ANY HISPANIC OR LATINO:(3):1 -0.17 -0.25, -0.09 <0.001
race(3) ANY HISPANIC OR LATINO:(3):2 -0.18 -0.30, -0.06 0.004
race(3) ANY HISPANIC OR LATINO:(3):3 -0.16 -0.27, -0.05 0.004
race(4) ALL OTHER RACES:(4):1 -0.26 -0.48, -0.05 0.017
race(4) ALL OTHER RACES:(4):2 -0.45 -0.78, -0.12 0.007
race(4) ALL OTHER RACES:(4):3 -0.38 -0.62, -0.14 0.002
sex(2) FEMALE:(2):1 0.11 0.04, 0.19 0.004
sex(2) FEMALE:(2):2 0.21 0.14, 0.28 <0.001
sex(2) FEMALE:(2):3 0.13 0.06, 0.20 <0.001

1 CI = Confidence Interval

-2*mfit$fit@criterion$loglikelihood + 2*length(mfit$coef)
## [1] 12543373

The reference level is early morning so all the results are compared to that time of day.

Females are more likely to have early morning visits than males.

Black/African Americans, Hispanics, and other races are more likely to have early morning visits than non-Hispanic whites.