qol <- read_csv("C:/Users/burga/Downloads/QOLProgramDatabase-EquityExplorationCur_DATA_2021-08-30_0103.csv") #file
## 
## -- Column specification --------------------------------------------------------
## cols(
##   .default = col_double(),
##   gender_other = col_character(),
##   language_other = col_character(),
##   other_related = col_logical(),
##   guard_gender_other = col_logical(),
##   race = col_number(),
##   childrace = col_number(),
##   other_related_sp = col_logical(),
##   guard_gender_other_sp = col_logical(),
##   childrace_sp = col_number(),
##   fs2r_4_bl = col_logical(),
##   pq_gen_18plus_104_bl = col_logical(),
##   pq_gen_18plus_83_bl = col_logical(),
##   pq_gen_18plus_106_bl = col_logical(),
##   pq_gen_18plus_85_bl = col_logical(),
##   pq_gen_18plus_108_bl = col_logical(),
##   pq_gen_18plus_132_bl = col_logical(),
##   pq_gen_18plus_3_bl = col_logical(),
##   pq_gen_18plus_1_bl = col_logical(),
##   pq_gen_18plus_17_bl = col_logical(),
##   pq_gen_18plus_91_bl = col_logical()
##   # ... with 187 more columns
## )
## i Use `spec()` for the full column specifications.
fs2r <-read_excel("C:/Users/burga/Downloads/FS2R Scoring email.xlsx", sheet = "Calculations")
#clean the demographic data
# childgender
qol$childgender <- as.factor(qol$childgender)
levels (qol$childgender) <-gsub("0","Male",levels(qol$childgender))
levels (qol$childgender) <-gsub("1","Female",levels(qol$childgender))
levels (qol$childgender) <-gsub("2","Other",levels(qol$childgender))
levels (qol$childgender) <-gsub("3","Prefer not to answer",levels(qol$childgender))

#interviewlang_requested
qol$interviewlang <-qol$interviewlang
qol$interviewlang[qol$interviewlang > 3] <- 3
qol$interviewlang <- as.factor(qol$interviewlang)
levels (qol$interviewlang) <-gsub("1","English",levels(qol$interviewlang))
levels (qol$interviewlang) <-gsub("2","Spanish",levels(qol$interviewlang))
levels (qol$interviewlang) <-gsub("3","Other",levels(qol$interviewlang))

#interviewlang
#qol$interviewlang <- as.factor(qol$interviewlang)
#levels (qol$interviewlang) <-gsub("1","English",levels(qol$interviewlang))
#levels (qol$interviewlang) <-gsub("2","Spanish",levels(qol$interviewlang))
#levels (qol$interviewlang) <-gsub("3","Vietnamese",levels(qol$interviewlang))
#levels (qol$interviewlang) <-gsub("4","Russian",levels(qol$interviewlang))
#levels (qol$interviewlang) <-gsub("5","Chinese",levels(qol$interviewlang))
#levels (qol$interviewlang) <-gsub("6","Somali",levels(qol$interviewlang))

#interp_needed  
qol$interp_needed<- as.factor(qol$interp_needed)
levels (qol$interp_needed) <-gsub("0","No",levels(qol$interp_needed))
levels (qol$interp_needed) <-gsub("1","Yes",levels(qol$interp_needed))

#related    
qol$related <- ifelse(is.na(qol$related), qol$related_sp, qol$related)
qol$related<- as.factor(qol$related)
levels (qol$related) <-gsub("1","Mother",levels(qol$related))
levels (qol$related) <-gsub("2","Father",levels(qol$related))
levels (qol$related) <-gsub("3","Stepmother",levels(qol$related))
levels (qol$related) <-gsub("4","Stepfather",levels(qol$related))
levels (qol$related) <-gsub("5","Grandmother",levels(qol$related))
levels (qol$related) <-gsub("6","Grandfather",levels(qol$related))
levels (qol$related) <-gsub("8","Aunt or Uncle",levels(qol$related))
levels (qol$related) <-gsub("9","Older brother or sister",levels(qol$related))
levels (qol$related) <-gsub("10","Other relative",levels(qol$related))
levels (qol$related) <-gsub("7","Other relative",levels(qol$related))
levels (qol$related) <-gsub("Mother0","Mother",levels(qol$related))


#other_related  
#guard_gender   
qol$guard_gender <- ifelse(is.na(qol$guard_gender), qol$guard_gender_sp, qol$guard_gender)
qol$guard_gender<- as.factor(qol$guard_gender)
levels (qol$guard_gender) <-gsub("0","Male",levels(qol$guard_gender))
levels (qol$guard_gender) <-gsub("1","Female",levels(qol$guard_gender))
levels (qol$guard_gender) <-gsub("2","Other",levels(qol$guard_gender))
levels (qol$guard_gender) <-gsub("3","Prefer not to answer",levels(qol$guard_gender))

#parentage  
#qol$parentage <- ifelse(is.na(qol$parentage), qol$parentage_sp, qol$parentage)
#qol$parentage<- as.factor(qol$parentage)
#levels (qol$parentage) <-gsub("1","18to24",levels(qol$parentage)) 
#levels (qol$parentage) <-gsub("2","25to34",levels(qol$parentage))
#levels (qol$parentage) <-gsub("3","35to44",levels(qol$parentage))
#levels (qol$parentage) <-gsub("4","45to54",levels(qol$parentage))
#levels (qol$parentage) <-gsub("5","55to64",levels(qol$parentage))
#levels (qol$parentage) <-gsub("6","65to74",levels(qol$parentage))
#levels (qol$parentage) <-gsub("7","75+",levels(qol$parentage))

#education
qol$education <- ifelse(is.na(qol$education), qol$education_sp, qol$education)
qol$education<- as.factor(qol$education)
levels (qol$education) <-gsub("1","8th grade or less",levels(qol$education))
levels (qol$education) <-gsub("2","Some high school, but did not graduate",levels(qol$education))
levels (qol$education) <-gsub("3","high school grad or GED",levels(qol$education))
levels (qol$education) <-gsub("4","Some college or 2 year degree (or trade or technical school)",levels(qol$education))
levels (qol$education) <-gsub("5","4-year college graduate",levels(qol$education))
levels (qol$education) <-gsub("6","More than 4-year college degree",levels(qol$education))

#race___1   race___2    race___3    race___4    race___5    race___6    race___7
qol$race <- ifelse(is.na(qol$race), qol$race_sp, qol$race)
qol$race[qol$race > 7] <- 7
qol$race<- as.factor(qol$race)
levels (qol$race) <-gsub("1","White",levels(qol$race)) 
levels (qol$race) <-gsub("2","Black or African American",levels(qol$race))
levels (qol$race) <-gsub("3","Latino or Hispanic",levels(qol$race))
levels (qol$race) <-gsub("4","Asian",levels(qol$race))
levels (qol$race) <-gsub("5","Native Hawaiian or other Pacific Islander",levels(qol$race))
levels (qol$race) <-gsub("6","Indigenous",levels(qol$race))
levels (qol$race) <-gsub("7","Other or multiracial",levels(qol$race))

qol$childrace <- ifelse(is.na(qol$childrace), qol$childrace_sp, qol$childrace)
qol$childrace[qol$childrace > 7] <- 7
qol$childrace<- as.factor(qol$childrace)
levels (qol$childrace) <-gsub("1","White",levels(qol$childrace)) 
levels (qol$childrace) <-gsub("2","Black or African American",levels(qol$childrace))
levels (qol$childrace) <-gsub("3","Latino or Hispanic",levels(qol$childrace))
levels (qol$childrace) <-gsub("4","Asian",levels(qol$childrace))
levels (qol$childrace) <-gsub("5","Native Hawaiian or other Pacific Islander",levels(qol$childrace))
levels (qol$childrace) <-gsub("6","Indigenous",levels(qol$childrace))
levels (qol$childrace) <-gsub("7","Other or multiracial",levels(qol$childrace))

qol_dem <-qol[ -c(5,8,13,18:25,26:1519) ]
fs2r.clean <- fs2r[-c(2:10,12)]
fs2r.final <- fs2r.clean %>% 
    mutate_all(~ifelse(. %in% c("N/A", "null", ""), NA, .)) %>% 
    na.omit()
#pedsql.final <- pedsql.clean %>% 
    #mutate_all(~ifelse(. %in% c("N/A", "null", ""), NA, .)) %>% 
    #na.omit()
#join1 <- rbind(pedsql.final,fs2r.final) #join the scores of both data sets
join2 <- inner_join(fs2r.final,qol_dem, by= "record_id") #join the scores and demographic data
QOL.Equity.Exploraton <- select(join2,-c()) #deleate any  possible doubles
qol_final <- QOL.Equity.Exploraton

Tables as instructed

Language

table.lan <-qol_final %>%
  tabyl(interviewlang, `Back to Baseline`) %>%
  adorn_totals(c("row", "col")) %>%
  adorn_percentages("row") %>% 
  adorn_pct_formatting(rounding = "half up", digits = 0) %>%
  adorn_ns()

knitr::kable(table.lan,col.names = c("Language","No return to baseline","Return to baseline","Totals"), caption = " Table 1:Language and Baseline")%>%
  kableExtra::kable_styling(latex_options = c("striped", "scale_down"))
Table 1:Language and Baseline
Language No return to baseline Return to baseline Totals
English 31% (11) 69% (24) 100% (35)
Spanish 0% (0) 100% (2) 100% (2)
Other 0% (0) 100% (3) 100% (3)
Total 28% (11) 73% (29) 100% (40)

Interpretor used

table.int <-qol_final %>%
  tabyl(interp_needed, `Back to Baseline`) %>%
  adorn_totals(c("row", "col")) %>%
  adorn_percentages("row") %>% 
  adorn_pct_formatting(rounding = "half up", digits = 0) %>%
  adorn_ns()

knitr::kable(table.int,col.names = c("Interpreter","No return to baseline","Return to baseline","Totals"), caption = " Table 2:Interpreter need and Baseline")%>%
  kableExtra::kable_styling(latex_options = c("striped", "scale_down"))
Table 2:Interpreter need and Baseline
Interpreter No return to baseline Return to baseline Totals
No 30% (11) 70% (26) 100% (37)
Yes 0% (0) 100% (3) 100% (3)
Total 28% (11) 73% (29) 100% (40)

Parent Education

table.edu <-qol_final %>%
  tabyl(education, `Back to Baseline`) %>%
  adorn_totals(c("row", "col")) %>%
  adorn_percentages("row") %>% 
  adorn_pct_formatting(rounding = "half up", digits = 0) %>%
  adorn_ns()

knitr::kable(table.edu,col.names = c("Education level","No return to baseline","Return to baseline","Totals"), caption = " Table 3: Education and Baseline")%>%
  kableExtra::kable_styling(latex_options = c("striped", "scale_down"))
Table 3: Education and Baseline
Education level No return to baseline Return to baseline Totals
8th grade or less 33% (1) 67% (2) 100% (3)
Some high school, but did not graduate 100% (1) 0% (0) 100% (1)
high school grad or GED 20% (1) 80% (4) 100% (5)
Some college or 2 year degree (or trade or technical school) 27% (3) 73% (8) 100% (11)
4-year college graduate 33% (3) 67% (6) 100% (9)
More than 4-year college degree 18% (2) 82% (9) 100% (11)
Total 28% (11) 73% (29) 100% (40)

Parent R&E

table.pre <-qol_final %>%
  tabyl(race, `Back to Baseline`) %>%
  adorn_totals(c("row", "col")) %>%
  adorn_percentages("row") %>% 
  adorn_pct_formatting(rounding = "half up", digits = 0) %>%
  adorn_ns()

knitr::kable(table.pre,col.names = c("Race and or Ethnicity","No return to baseline","Return to baseline","Totals"), caption = " Table 4:Parent Race and or Ethnicity and Baseline")%>%
  kableExtra::kable_styling(latex_options = c("striped", "scale_down"))
Table 4:Parent Race and or Ethnicity and Baseline
Race and or Ethnicity No return to baseline Return to baseline Totals
White 36% (5) 64% (9) 100% (14)
Black or African American 20% (1) 80% (4) 100% (5)
Latino or Hispanic 33% (1) 67% (2) 100% (3)
Asian 13% (1) 88% (7) 100% (8)
Native Hawaiian or other Pacific Islander
100% (0)
Indigenous
100% (0)
Other or multiracial 30% (3) 70% (7) 100% (10)
Total 28% (11) 73% (29) 100% (40)
Child R&E
table.cre <-qol_final %>%
  tabyl(childrace, `Back to Baseline`) %>%
  adorn_totals(c("row", "col")) %>%
  adorn_percentages("row") %>% 
  adorn_pct_formatting(rounding = "half up", digits = 0) %>%
  adorn_ns()

knitr::kable(table.cre,col.names = c("Race and or Ethnicity","No return to baseline","Return to baseline","Totals"), caption = " Table 5:Child Race and or Ethnicity and Baseline")%>%
  kableExtra::kable_styling(latex_options = c("striped", "scale_down"))
Table 5:Child Race and or Ethnicity and Baseline
Race and or Ethnicity No return to baseline Return to baseline Totals
White 36% (4) 64% (7) 100% (11)
Black or African American 40% (2) 60% (3) 100% (5)
Latino or Hispanic 50% (1) 50% (1) 100% (2)
Asian 25% (1) 75% (3) 100% (4)
Native Hawaiian or other Pacific Islander
100% (0)
Indigenous
100% (0)
Other or multiracial 17% (3) 83% (15) 100% (18)
Total 28% (11) 73% (29) 100% (40)
Child Gender
table.cge<-qol_final %>%
  tabyl(childgender, `Back to Baseline`) %>%
  adorn_totals(c("row", "col")) %>%
  adorn_percentages("row") %>% 
  adorn_pct_formatting(rounding = "half up", digits = 0) %>%
  adorn_ns()

knitr::kable(table.cge,col.names = c("Gender Identity","No return to baseline","Return to baseline","Totals"), caption = " Table 6: Child Gender Identity and Baseline")%>%
  kableExtra::kable_styling(latex_options = c("striped", "scale_down"))
Table 6: Child Gender Identity and Baseline
Gender Identity No return to baseline Return to baseline Totals
Male 32% (6) 68% (13) 100% (19)
Female 25% (5) 75% (15) 100% (20)
Other 0% (0) 100% (1) 100% (1)
Total 28% (11) 73% (29) 100% (40)

Back to baseline numbers report

Univariable analysis

Summary Statistics For baseline actual number

x<-QOL.Equity.Exploraton$`Back to baseline.Parent.Actual`
#find mean
mean(x)
## [1] 10.98277
#find median
median(x)
## [1] 8.928571
#find range
max(x) - min(x)
## [1] 125
#find interquartile range (spread of middle 50% of values)
IQR(x)
## [1] 25.89286
#find standard deviation
sd(x)
## [1] 24.82186

Charts

#frequency table
table(x)
## x
## -53.5714285714286 -35.7142857142857               -25 -7.14285714285715 
##                 1                 1                 2                 1 
## -7.14285714285714 -3.57142857142857                 0  3.57142857142857 
##                 3                 3                 2                 3 
##  7.14285714285714  7.14285714285715  10.7142857142857  14.2857142857143 
##                 3                 1                 4                 3 
##  20.3296703296703  21.4285714285714                25  28.5714285714286 
##                 1                 2                 1                 2 
##  35.7142857142857  38.4615384615385  39.2857142857143  46.4285714285714 
##                 1                 1                 1                 1 
##  57.1428571428571  59.0909090909091  71.4285714285714 
##                 1                 1                 1
#boxplot
boxplot(x)

#histogram
hist(x)

#density curve
plot(density(x))

Chi-Square Test of Independence Null hypothesis (H0): the row and the column variables of the contingency table are independent. Alternative hypothesis (H1): row and column variables are dependent

#chi^2 test wont work on negative numbers so a transformation had to be done 
abs.data <- QOL.Equity.Exploraton %>% 
  dplyr::select(where(is.numeric)) %>%
  abs()
y<-inner_join(abs.data,qol_dem, by= "record_id")
z<- y[-c(3,8,10,14,16)]
w<-lapply(z, as.numeric)
a<-as.data.frame(do.call(rbind, w))
qol.chi<-t(a)
chisq <- chisq.test(qol.chi)
## Warning in stats::chisq.test(x, y, ...): Chi-squared approximation may be
## incorrect
chisq
## 
##  Pearson's Chi-squared test
## 
## data:  qol.chi
## X-squared = 3539.8, df = 507, p-value < 2.2e-16