## Liking score
liking.df <- survey.df %>%
select ("ID" , "FL-01_3" : "FL-60_3" ) %>%
mutate (veg.liking = rowMeans (select (., "FL-01_3" : "FL-06_3" ), na.rm = TRUE ),
fruit.liking = rowMeans (select (., "FL-07_3" : "FL-11_3" ), na.rm = TRUE ),
saltyfat.liking = rowMeans (select (., "FL-12_3" : "FL-15_3" ), na.rm = TRUE ),
hfprotein.liking = rowMeans (select (., "FL-16_3" : "FL-20_3" ), na.rm = TRUE ),
alcohol.liking = rowMeans (select (., "FL-22_3" : "FL-25_3" ), na.rm = TRUE ),
wg.liking = rowMeans (select (., "FL-26_3" : "FL-29_3" ), na.rm = TRUE ),
carbs.liking = rowMeans (select (., "FL-30_3" : "FL-34_3" ), na.rm = TRUE ),
healthyfat.liking = rowMeans (select (., "FL-35_3" : "FL-38_3" ), na.rm = TRUE ),
sweets.liking = rowMeans (select (., "FL-39_3" : "FL-43_3" ), na.rm = TRUE ),
ssb.liking = rowMeans (select (., "FL-44_3" : "FL-47_3" ), na.rm = TRUE ),
sfbl.liking = rowMeans (select (., "FL-39_3" : "FL-47_3" ), na.rm = TRUE ),
unhealthyfat.liking = rowMeans (select (., "FL-48_3" : "FL-52_3" ), na.rm = TRUE ),
protein.liking = rowMeans (select (., "FL-53_3" : "FL-57_3" ), na.rm = TRUE ),
spicy.liking = rowMeans (select (., "FL-58_3" : "FL-60_3" ), na.rm = TRUE )) %>%
select (c ("ID" , ends_with (".liking" )))
## Three factor questionnaire
TFQ.df <- survey.df %>%
select ("ID" , "TFQ-01" : "TFQ-21" ) %>%
mutate (uncontrolled = rowSums (select (., "TFQ-03" , "TFQ-06" , "TFQ-08" , "TFQ-09" , "TFQ-12" , "TFQ-13" , "TFQ-15" , "TFQ-19" , "TFQ-20" ), na.rm = TRUE )) %>%
mutate (restraint = rowSums (select (., "TFQ-01" , "TFQ-05" , "TFQ-11" , "TFQ-17" , "TFQ-18" , "TFQ-21" ), na.rm = TRUE )) %>%
mutate (emotional = rowSums (select (., "TFQ-02" , "TFQ-04" , "TFQ-07" , "TFQ-10" , "TFQ-14" , "TFQ-16" ), na.rm = TRUE )) %>%
select (c ("ID" , "uncontrolled" , "restraint" , "emotional" ))
## Adult eating behavior questionnaire
AEBQ.df <- survey.df %>%
select ("ID" , "AEBQ-01" : "AEBQ-35" ) %>%
mutate (EF = rowSums (select (., "AEBQ-01" , "AEBQ-03" , "AEBQ-04" ), na.rm = TRUE )) %>%
mutate (EOE = rowSums (select (., "AEBQ-05" , "AEBQ-08" , "AEBQ-10" , "AEBQ-16" ), na.rm = TRUE )) %>%
mutate (EUE = rowSums (select (., "AEBQ-15" , "AEBQ-20" , "AEBQ-27" , "AEBQ-35" ), na.rm = TRUE )) %>%
mutate (FF = rowSums (select (., "AEBQ-02" , "AEBQ-07" , "AEBQ-12" , "AEBQ-19" , "AEBQ-24" ), na.rm = TRUE )) %>%
mutate (FR = rowSums (select (., "AEBQ-13" , "AEBQ-22" , "AEBQ-33" ), na.rm = TRUE )) %>%
mutate (SE = rowSums (select (., "AEBQ-14" , "AEBQ-25" , "AEBQ-26" , "AEBQ-29" ), na.rm = TRUE )) %>%
mutate (H = rowSums (select (., "AEBQ-06" , "AEBQ-09" , "AEBQ-28" , "AEBQ-32" , "AEBQ-34" ), na.rm = TRUE )) %>%
mutate (SR = rowSums (select (., "AEBQ-11" , "AEBQ-23" , "AEBQ-30" , "AEBQ-31" ), na.rm = TRUE )) %>%
select (c ("ID" , "EF" : "SR" ))
## Body appreciation scale
BAS.df <- survey.df %>%
select ("ID" , starts_with ("BAS" )) %>%
mutate (BAS = rowSums (select (., 2 : 11 ), na.rm = TRUE ))%>%
select (c ("ID" , "BAS" ))
## Intuitive eating scale
IES.df <- survey.df %>%
select ("ID" , starts_with ("IES" )) %>%
mutate (IES = (rowSums (select (., 2 : 24 ), na.rm = TRUE ))/ 23 ) %>%
select (c ("ID" , "IES" ))
## sHEI score
HEI.df <- survey.df %>%
select ("ID" , "sex" , "Fruit" : "Water" ) %>%
mutate (fruit.1 = case_when (
Fruit == 1 ~ 0 ,
Fruit == 2 ~ 2 ,
Fruit == 3 ~ 3.5 ,
Fruit >= 4 ~ 5 )) %>%
mutate (fruit.2 = case_when (
Juice == 1 ~ 0 ,
Juice == 2 ~ 2 ,
Juice == 3 ~ 3.5 ,
Juice >= 4 ~ 5 )) %>%
mutate (tfruitHEI = case_when (
fruit.1 + fruit.2 < 5 ~ 0 ,
fruit.1 + fruit.2 >= 5 ~ 5 )) %>%
mutate (wfruitHEI = case_when (
Fruit == 1 ~ 0 ,
Fruit == 2 ~ 2.5 ,
Fruit >= 3 ~ 5 )) %>%
mutate (vegHEI = case_when (
` Green veg ` == 1 ~ 1.6 ,
` Green veg ` == 2 & ` Starchy veg ` >= 2 ~ 2.46 ,
` Green veg ` >= 2 & ` Starchy veg ` >= 2 ~ 3.24 ,
` Green veg ` >= 2 & ` Starchy veg ` == 1 ~ 3.56 )) %>%
mutate (bean.1 = case_when (
` Green veg ` == 1 ~ 0 ,
` Green veg ` >= 2 ~ 5 )) %>%
mutate (bean.2 = case_when (
Beans == 1 ~ 0 ,
Beans >= 2 ~ 5 )) %>%
mutate (beanHEI = case_when (
bean.1 + bean.2 < 5 ~ 0 ,
bean.1 + bean.2 >= 5 ~ 5 )) %>%
mutate (wgHEI = case_when (
` Whole grains.day ` == 1 ~ 0.51 ,
sex == 1 & ` Whole grains.day ` >= 2 ~ 2.97 ,
sex == 2 & ` Whole grains.day ` >= 2 & ` Whole grains.day ` <= 3 ~ 5.20 ,
sex == 2 & ` Whole grains.day ` >= 4 ~ 6.94 )) %>%
mutate (dairyHEI = case_when (
sex == 1 & ` Milk.day ` <= 3 ~ 3.22 ,
sex == 2 & ` Milk.day ` <= 3 & ` Low-fat milk.day ` == 1 ~ 3.32 ,
sex == 2 & ` Milk.day ` <= 3 & ` Low-fat milk.day ` >= 2 ~ 4.81 ,
` Milk.day ` >= 4 ~ 6.51 )) %>%
mutate (tproteinHEI = case_when (
sex == 1 & ` Seafood.freq ` <= 4 ~ 4.11 ,
sex == 1 & ` Seafood.freq ` >= 5 ~ 4.98 ,
sex == 1 & is.na (` Seafood.freq ` ) ~ 4.11 ,
sex == 2 ~ 4.97 )) %>%
mutate (sfpproteinHEI = case_when (
sex == 1 & Nuts <= 2 ~ 0.49 ,
sex == 2 & Nuts <= 2 ~ 1.50 ,
Nuts >= 3 ~ 4.20 )) %>%
mutate (fatHEI = case_when (
` Milk.day ` >= 4 ~ 2.56 ,
` Saturated fats ` >= 2 & ` Saturated fats ` <= 3 & ` Milk.freq ` >= 1 & ` Low-fat milk.freq ` <= 2 ~ 2.63 ,
` Saturated fats ` >= 2 & ` Saturated fats ` <= 3 & is.na (` Milk.freq ` ) | is.na (` Low-fat milk.freq ` ) ~ 2.63 ,
` Saturated fats ` >= 2 & ` Saturated fats ` <= 3 & ` Milk.freq ` >= 1 & ` Low-fat milk.freq ` >= 3 ~ 4.54 ,
` Saturated fats ` == 1 & ` Milk.freq ` >= 1 ~ 5.93 ,
` Saturated fats ` == 1 & is.na (` Milk.freq ` ) ~ 5.93 )) %>%
mutate (grainHEI = case_when (
` Green veg ` == 1 ~ 2.13 ,
` Grains.day ` >= 3 & ` Seafood.day ` >= 2 & ` Green veg ` >= 2 ~ 2.27 ,
` Grains.day ` >= 3 & Nuts >= 1 & Nuts <= 2 & ` Seafood.day ` == 1 & ` Green veg ` >= 2 ~ 4.73 ,
` Grains.day ` >= 3 & Nuts >= 3 & ` Seafood.day ` == 1 & ` Green veg ` >= 2 ~ 8.45 ,
` Grains.day ` >= 1 & ` Grains.day ` <= 2 & ` Green veg ` >= 2 ~ 9.25 )) %>%
mutate (sodiumHEI = case_when (
Fruit >= 1 & Fruit <= 2 & ` Grains.day ` >= 3 & Water == 3 ~ 0.70 ,
Fruit >= 3 & ` Grains.day ` >= 3 & Water == 3 ~ 2.30 ,
` Grains.day ` >= 3 & Water >= 1 & Water <= 2 ~ 4.94 ,
` Grains.day ` >= 1 & ` Grains.day ` <= 2 ~ 6.07 )) %>%
mutate (ssb.cal = case_when (
` SSB.day ` == 1 ~ 0 ,
` SSB.day ` == 2 ~ 156 ,
` SSB.day ` == 3 ~ 312 ,
` SSB.day ` == 4 ~ 468 ,
` SSB.day ` == 5 ~ 624 ,
` SSB.day ` == 6 ~ 780 ,
` SSB.day ` == 7 ~ 936 ),
sugar.cal = case_when (
` Added sugars ` == 1 ~ 130 ,
` Added sugars ` == 2 ~ 260 ,
` Added sugars ` == 3 ~ 520 )) %>%
mutate (sugar.intake = (ssb.cal + sugar.cal)) %>%
mutate (sugarHEI = case_when (
sugar.intake <= 130 ~ 10 ,
sugar.intake > 130 & sugar.cal < 520 ~ 5 ,
sugar.intake >= 520 ~ 0 )) %>%
mutate (sugar.tsp = case_when (
` SSB.freq ` <= 4 ~ 13.26 ,
` SSB.freq ` >= 5 & ` SSB.freq ` <= 6 ~ 16.00 ,
` SSB.day ` == 2 ~ 16.00 ,
` SSB.day ` >= 3 ~ 26.87 )) %>%
mutate (satfatHEI = case_when (
` SSB.day ` >= 3 ~ 1.82 ,
` SSB.day ` <= 2 & ` Grains.day ` <= 2 ~ 3.20 ,
` SSB.day ` <= 2 & ` Grains.day ` >= 3 & Nuts <= 2 ~ 4.64 ,
` SSB.day ` <= 2 & ` Grains.day ` >= 3 & Nuts >= 3 ~ 6.56 )) %>%
select ("ID" , "sugar.intake" , "sugar.tsp" , ends_with ("HEI" )) %>%
mutate (sHEI = rowSums (select (., "tfruitHEI" : "satfatHEI" ), na.rm = TRUE )) %>%
mutate (SuFatHEI = rowSums (select (., c ("sugarHEI" , "satfatHEI" ))))
## Putting scores together
survey.df$ ID <- as.character (survey.df$ ID)
anthro.df$ ID <- as.character (anthro.df$ ID)
SST.df$ ID <- as.character (SST.df$ ID)
redjade.df$ ID <- as.character (redjade.df$ ID)
liking.df$ ID <- as.character (liking.df$ ID)
HEI.df$ ID <- as.character (HEI.df$ ID)
TFQ.df$ ID <- as.character (TFQ.df$ ID)
BAS.df$ ID <- as.character (BAS.df$ ID)
IES.df$ ID <- as.character (IES.df$ ID)
AEBQ.df$ ID <- as.character (AEBQ.df$ ID)
full.df <- survey.df %>%
select (c ("ID" , "sex" , "age" , "race" , "usb" , "education" , "hinc" , "exec" , "ageCat" )) %>%
filter (race %in% c ("African" , "Asian" )) %>%
left_join (anthro.df, by = "ID" ) %>%
left_join (SST.df, by = "ID" ) %>%
left_join (redjade.df, by = "ID" ) %>%
left_join (liking.df, by = "ID" ) %>%
left_join (HEI.df, by = "ID" ) %>%
left_join (TFQ.df, by = "ID" ) %>%
left_join (BAS.df, by = "ID" ) %>%
left_join (IES.df, by = "ID" ) %>%
left_join (AEBQ.df, by = "ID" ) %>%
mutate (BMIcat = case_when (
BMI < 18.5 ~ "0" ,
BMI >= 18.5 & BMI < 25 & race != "Asian" ~ "1" ,
BMI >= 25 & BMI < 30 & race != "Asian" ~ "2" ,
BMI > 30 & race != "Asian" ~ "3" ,
BMI >= 18.5 & BMI < 23 & race == "Asian" ~ "1" ,
BMI >= 23 & BMI < 25 & race == "Asian" ~ "2" ,
BMI > 25 & race == "Asian" ~ "3" )) %>%
mutate (BAScat = ntile (BAS, 2 )) %>%
mutate (UEcat = ntile (uncontrolled, 3 )) %>%
mutate (CRcat = ntile (restraint, 3 )) %>%
mutate (EMcat = ntile (emotional, 3 )) %>%
mutate (SFBLcat = ntile (sfbl.liking, 3 )) %>%
mutate (UHFcat = ntile (unhealthyfat.liking, 3 )) %>%
mutate (SugarCat = ntile (sugar.intake, 3 )) %>%
mutate (DQ = ntile (sHEI, 2 ))
full.df$ group <- paste (full.df$ race, full.df$ usb)
African.df <- full.df %>%
filter (race == "African" )
Asian.df <- full.df %>%
filter (race == "Asian" )
USB.df <- full.df %>%
filter (race == "U.S. Born" )
Immigrant.df <- full.df %>%
filter (race == "Immigrant" )