Calculate DHM to EMH ratio

#calculate total volume for each individual day in the hospital

data <- data %>%
  mutate(total_volume_day = EHM_volume + DHM_volume)

#calculate percentage volume DHM for each individual day in the hospital

data <- data %>%
  mutate(Percent_DHM_day = DHM_volume/total_volume_day)


#calculate total volume (DHM + EHM) for all days of life in the hospital

data <- data %>%
  mutate(total_volume = total_volume_EHM + total_volume_DHM)

#calculate percentage volume DHM for all days of life in the hospital

data <- data %>%
  mutate(Percent_DHM = total_volume_DHM/total_volume)

#check calcs on one participant

data_check <- data %>%
  filter(CSN==329930120) %>%
  group_by (instance_dol, EHM_volume, DHM_volume, total_volume_day, Percent_DHM_day, total_volume_EHM, total_volume_DHM, total_volume, Percent_DHM) %>% 
  count() %>%
  ungroup() %>%
  mutate(percent = n/sum(n))

datatable(data_check)

Plot of mean volumes of DHM EHM over the hosptial stay (100 dol)

mean_volume_data <- data %>%
  filter(instance_dol >= 0 & instance_dol <= 100) %>%
  group_by(instance_dol) %>%
  summarize(
    mean_EHM_volume = mean(EHM_volume, na.rm = TRUE),
    mean_DHM_volume = mean(DHM_volume, na.rm = TRUE),
    mean_pump_volume = mean(Pump_volume, na.rm = TRUE),
    mean_DHM_percent = mean(Percent_DHM_day, na.rm = TRUE),
  )

# Create a plot of the mean volume for each day of life
ggplot(mean_volume_data, aes(x = instance_dol)) +
  geom_line(aes(y = mean_EHM_volume, color = "EHM Volume")) +
  geom_line(aes(y = mean_DHM_volume, color = "DHM Volume")) +
  labs(title = "Mean Volume for Each Day of Life",
       x = "Day of Life",
       y = "Mean Volume",
       color = "Volume Type") +
  theme_minimal()

Plot of mean volumes of pumping over the hosptial stay (100 dol)

ggplot(mean_volume_data, aes(x = instance_dol)) +
  geom_line(aes(y = mean_pump_volume, color = "Pump Volume")) +
  labs(title = "Mean Pump Volume for Each Day of Life",
       x = "Day of Life",
       y = "Mean Volume",
       color = "Volume Type") +
  theme_minimal()

Plot of percentage of DHM over the hosptial stay (100 dol)

ggplot(mean_volume_data, aes(x = instance_dol)) +
  geom_line(aes(y = mean_DHM_percent, color = "DHM percent")) +
  labs(title = "Percent of volume from DHM for each day of life",
       x = "Day of Life",
       y = "Percent",
       color = "DHM percent") +
  theme_minimal()

Calculate DHM to EMH ratio for the first 2 weeks of life

#Calculate total EHM for each infant during the first 14 days of life
data <- data %>%
  filter(instance_dol <= 14 & instance_dol >= 0) %>%
  group_by(CSN) %>%
  mutate(volume_EHM_14 = sum(EHM_volume, na.rm = TRUE))

#Calculate total DHM for each infant during the first 14 days of life
data <- data %>%
  filter(instance_dol <= 14 & instance_dol >= 0) %>%
  group_by(CSN) %>%
  mutate(volume_DHM_14 = sum(DHM_volume, na.rm = TRUE))

#Calculate total pump volume for each mother during the first 14 days of life
data <- data %>%
  filter(instance_dol <= 14 & instance_dol >= 0) %>%
  group_by(CSN) %>%
  mutate(volume_pump_14 = sum(Pump_volume, na.rm = TRUE))

#Calculate total milk volume for each infant during the first 14 days of life
data <- data %>%
  mutate(total_volume_14 =  volume_DHM_14 + volume_EHM_14)

#Calculate percentage of milk that is DHM in the first 14 days of life

data <- data %>%
  mutate(Percent_DHM_14 = volume_DHM_14/total_volume_14)


#check calcs on one participant
data_check <- data %>%
  filter(CSN==329930120) %>%
  group_by (instance_dol, EHM_volume, DHM_volume, volume_EHM_14, volume_DHM_14, total_volume_14, Percent_DHM_14) %>% 
  count() %>%
  ungroup() %>%
  mutate(percent = n/sum(n))

datatable(data_check)

Plot of mean volumes of DHM, EHM and pumping over the first 14 days

mean_volume_data_14 <- data %>%
  filter(instance_dol <= 14 & instance_dol >= 0) %>%
  group_by(instance_dol) %>%
  summarize(
    mean_EHM_volume = mean(EHM_volume, na.rm = TRUE),
    mean_DHM_volume = mean(DHM_volume, na.rm = TRUE),
    mean_pump_volume = mean(Pump_volume, na.rm = TRUE),
  )

# Create a plot of the mean volume for each day of life over the first 14 days
ggplot(mean_volume_data_14, aes(x = instance_dol)) +
  geom_line(aes(y = mean_EHM_volume, color = "EHM Volume")) +
  geom_line(aes(y = mean_DHM_volume, color = "DHM Volume")) +
  labs(title = "Mean Volume for Each Day of Life Over the First 14 Days",
       x = "Day of Life",
       y = "Mean Volume",
       color = "Volume Type") +
  theme_minimal()

ggplot(mean_volume_data_14, aes(x = instance_dol)) +
  geom_line(aes(y = mean_pump_volume, color = "Pump Volume")) +
  labs(title = "Mean Volume for Each Day of Life Over the First 14 Days",
       x = "Day of Life",
       y = "Mean Volume",
       color = "Volume Type") +
  theme_minimal()

We can see from these plots that on average there is an increase in pumping around day of life 5 which seems to correspond to an uptick in the amounts of mom milk that infants are getting

Inspect Percentage DHM

#limit to one slice

data_slice <- data %>%
  group_by(CSN)%>%
  slice(1)



descriptives(data_slice, vars = c('volume_pump_14', 'total_volume_pump', 'Percent_DHM_14', 'Percent_DHM'),hist  = TRUE, desc = "rows")
## 
##  DESCRIPTIVES
## 
##  Descriptives                                                                                                          
##  ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 
##                         N      Missing    Mean             Median          SD               Minimum     Maximum        
##  ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 
##    volume_pump_14       134          0     2864.9777612    1867.6500000     2944.1868483    0.000000    11889.680000   
##    total_volume_pump    122         12    11688.1739344    9512.1750000    11511.0789517    0.000000    77975.200000   
##    Percent_DHM_14       128          6        0.3488837       0.1910525        0.3510296    0.000000        1.000000   
##    Percent_DHM          130          4        0.3321199       0.1043970        0.3891418    0.000000        1.000000   
##  ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

boxplot(data_slice$Percent_DHM)

hist(data_slice$Percent_DHM)

Test SES differences in DHM Percent

Infants in the low SES group get significantly higher proportions of DHM compared to those in the high SES group