The mental health status of a sample of 1,660 young New York residents in midtown Manhattan was classified by their parents’ socioeconomic status (A=High, F=Low).

Column 1: Subject ID
Column 2: SES, numerical code A=6, … , F=1
Column 3: SES, reference code for A
Column 4: SES, reference code for B
Column 5: SES, reference code for C
Column 6: SES, reference code for D
Column 7: SES, reference code for E
Column 9: Mental impairment, well=1, mild=2, moderate=3, impaired=4

1 load package

pacman::p_load(tidyverse, MASS, pscl)

2 Input data

dta3 <- read.table("C:/Users/USER/Desktop/homework/mentalSES.txt", h=T)

# first 6 lines
head(dta3)
##   Id ses A B C D E mental
## 1  1   6 1 0 0 0 0      1
## 2  2   6 1 0 0 0 0      1
## 3  3   6 1 0 0 0 0      1
## 4  4   6 1 0 0 0 0      1
## 5  5   6 1 0 0 0 0      1
## 6  6   6 1 0 0 0 0      1
# check data structure
str(dta3)
## 'data.frame':    1660 obs. of  8 variables:
##  $ Id    : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ ses   : int  6 6 6 6 6 6 6 6 6 6 ...
##  $ A     : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ B     : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ C     : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ D     : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ E     : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ mental: int  1 1 1 1 1 1 1 1 1 1 ...
dta3 <- dta3 %>% 
  mutate(Id = factor(Id),
         ses = factor(ses),
         mental = factor(mental))
with(dta3, ftable(ses, mental))
##     mental   1   2   3   4
## ses                       
## 1           21  71  54  71
## 2           36  97  54  78
## 3           72 141  77  94
## 4           57 105  65  60
## 5           57  94  54  40
## 6           64  94  58  46
HH::likert(t(with(dta3, table(ses, mental))), 
           main="", 
           ylab="Mental impairment", 
           as.percent=TRUE)

3 The end