Skip to content

Commit

Permalink
Update phenotype_sensitivity.R
Browse files Browse the repository at this point in the history
add totals
  • Loading branch information
emprestige committed Aug 30, 2024
1 parent 8930504 commit 2d91e0a
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions analysis/sensitivity_analyses/phenotype_sensitivity.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,125 @@ if (study_start_date >= covid_season_min) {
)
}

#calculate totals for 'specific' outcomes
if (study_start_date >= covid_season_min) {
specific_totals_mild_full <- df_input_specific %>%
mutate(
RSV_Mild_Total = sum(rsv_primary_inf),
Flu_Mild_Total = sum(flu_primary_inf),
COVID_Mild_Total = sum(covid_primary_inf)
)
specific_totals_severe_full <- df_input_specific %>%
mutate(
RSV_Severe_Total = sum(rsv_secondary_inf),
Flu_Severe_Total = sum(flu_secondary_inf),
COVID_Severe_Total = sum(covid_secondary_inf)
)
} else {
specific_totals_mild_full <- df_input_specific %>%
mutate(
RSV_Mild_Total = sum(rsv_primary_inf),
Flu_Mild_Total = sum(flu_primary_inf)
)
specific_totals_severe_full <- df_input_specific %>%
mutate(
RSV_Severe_Total = sum(rsv_secondary_inf),
Flu_Severe_Total = sum(flu_secondary_inf)
)
}

#calculate totals for 'sensitive' outcomes
if (study_start_date >= covid_season_min) {
sensitive_totals_mild_full <- df_input_sensitive %>%
mutate(
RSV_Mild_Total = sum(rsv_primary_inf),
Flu_Mild_Total = sum(flu_primary_inf),
COVID_Mild_Total = sum(covid_primary_inf),
Overall_Resp_Mild_Total = sum(overall_resp_primary_inf)
)
sensitive_totals_severe_full <- df_input_sensitive %>%
mutate(
RSV_Severe_Total = sum(rsv_secondary_inf),
Flu_Severe_Total = sum(flu_secondary_inf),
COVID_Severe_Total = sum(covid_secondary_inf),
Overall_Resp_Severe_Total = sum(overall_resp_secondary_inf)
)
} else {
sensitive_totals_mild_full <- df_input_sensitive %>%
mutate(
RSV_Mild_Total = sum(rsv_primary_inf),
Flu_Mild_Total = sum(flu_primary_inf),
Overall_Resp_Mild_Total = sum(overall_resp_primary_inf)
)
sensitive_totals_severe_full <- df_input_sensitive %>%
mutate(
RSV_Severe_Total = sum(rsv_secondary_inf),
Flu_Severe_Total = sum(flu_secondary_inf),
Overall_Resp_Severe_Total = sum(overall_resp_secondary_inf)
)
}

#reformat data
if (study_start_date >= covid_season_min) {
specific_totals_mild <- specific_totals_mild_full %>%
select(RSV_Mild_Total, Flu_Mild_Total, COVID_Mild_Total)
specific_totals_severe <- specific_totals_severe_full %>%
select(RSV_Severe_Total, Flu_Severe_Total, COVID_Severe_Total)
sensitive_totals_mild <- sensitive_totals_mild_full %>%
select(RSV_Mild_Total, Flu_Mild_Total, COVID_Mild_Total)
sensitive_totals_severe <- sensitive_totals_severe_full %>%
select(RSV_Severe_Total, Flu_Severe_Total, COVID_Severe_Total)
sensitive_overall_totals_mild <- sensitive_totals_mild_full %>%
select(RSV_Mild_Total, Flu_Mild_Total, COVID_Mild_Total,
Overall_Resp_Mild_Total)
sensitive_overall_totals_severe <- sensitive_totals_severe_full %>%
select(RSV_Severe_Total, Flu_Severe_Total, COVID_Severe_Total,
Overall_Resp_Severe_Total)
} else {
specific_totals_mild <- specific_totals_mild_full %>%
select(RSV_Mild_Total, Flu_Mild_Total)
specific_totals_severe <- specific_totals_severe_full %>%
select(RSV_Severe_Total, Flu_Severe_Total)
sensitive_totals_mild <- sensitive_totals_mild_full %>%
select(RSV_Mild_Total, Flu_Mild_Total)
sensitive_totals_severe <- sensitive_totals_severe_full %>%
select(RSV_Severe_Total, Flu_Severe_Total)
sensitive_overall_totals_mild <- sensitive_totals_mild_full %>%
select(RSV_Mild_Total, Flu_Mild_Total, Overall_Resp_Mild_Total)
sensitive_overall_totals_severe <- sensitive_totals_severe_full %>%
select(RSV_Severe_Total, Flu_Severe_Total, Overall_Resp_Severe_Total)
}

specific_totals_m <- specific_totals_mild %>%
unique() %>%
gather(key = "combo", value = "n") %>%
mutate(outcome_type = "mild", codelist_type = "specific")
specific_totals_s <- specific_totals_severe %>%
unique() %>%
gather(key = "combo", value = "n") %>%
mutate(outcome_type = "severe", codelist_type = "specific")
specific_totals <- rbind(specific_totals_m, specific_totals_s)

sensitive_totals_m <- sensitive_totals_mild %>%
unique() %>%
gather(key = "combo", value = "n") %>%
mutate(outcome_type = "mild", codelist_type = "sensitive")
sensitive_totals_s <- sensitive_totals_severe %>%
unique() %>%
gather(key = "combo", value = "n") %>%
mutate(outcome_type = "severe", codelist_type = "sensitive")
sensitive_totals <- rbind(sensitive_totals_m, sensitive_totals_s)

sensitive_overall_totals_m <- sensitive_overall_totals_mild %>%
unique() %>%
gather(key = "combo", value = "n") %>%
mutate(outcome_type = "mild_overall", codelist_type = "sensitive")
sensitive_overall_totals_s <- sensitive_overall_totals_severe %>%
unique() %>%
gather(key = "combo", value = "n") %>%
mutate(outcome_type = "severe_overall", codelist_type = "sensitive")
sensitive_overall_totals <- rbind(sensitive_overall_totals_m, sensitive_overall_totals_s)

#count number of patients in each category for specific phenotypes - separately for mild and severe
patients_specific_mild <- rlang::duplicate(df_input_specific) %>%
group_by("combo" = mild_combined) %>%
Expand All @@ -180,6 +299,7 @@ patients_specific_severe <- rlang::duplicate(df_input_specific) %>%
ungroup() %>%
mutate(outcome_type = "severe", codelist_type = "specific")
patients_specific <- full_join(patients_specific_mild, patients_specific_severe)
patients_specific <- rbind(specific_totals, patients_specific)

#count number of patients in each category for sensitive phenotypes - separately for mild and severe
patients_sensitive_mild <- rlang::duplicate(df_input_sensitive) %>%
Expand All @@ -193,6 +313,7 @@ patients_sensitive_severe <- rlang::duplicate(df_input_sensitive) %>%
ungroup() %>%
mutate(outcome_type = "severe", codelist_type = "sensitive")
patients_sensitive <- full_join(patients_sensitive_mild, patients_sensitive_severe)
patients_sensitive <- rbind(sensitive_totals, patients_sensitive)

#count number of patients in each category for sensitive phenotypes now including overall resp - separately for mild and severe
patients_sensitive_mild_overall <- rlang::duplicate(df_input_sensitive) %>%
Expand All @@ -207,6 +328,7 @@ patients_sensitive_severe_overall <- rlang::duplicate(df_input_sensitive) %>%
mutate(outcome_type = "severe_overall", codelist_type = "sensitive")
patients_sensitive_overall <- full_join(patients_sensitive_mild_overall,
patients_sensitive_severe_overall)
patients_sensitive_overall <- rbind(sensitive_overall_totals, patients_sensitive_overall)

#combine as one tibble
patients_combined <- patients_specific %>%
Expand Down

0 comments on commit 2d91e0a

Please sign in to comment.