Skip to content

Commit 55e5619

Browse files
committed
small changes
1 parent 039de8c commit 55e5619

2 files changed

Lines changed: 13 additions & 51 deletions

File tree

analysis/dataset_checks.R

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -547,34 +547,9 @@ write_csv(df_status_issues_rep, here::here("output", "dataset_status_repeats.csv
547547
# sample date distributions
548548
df_dates <- df %>%
549549
select(c(meds_sample_date, repeats_sample_date,
550-
repeats_sample_start_date, repeats_sample_end_date))
550+
repeats_sample_start_date, repeats_sample_end_date)) %>%
551551
# filter data to include only people with medicines data - done earlier
552-
553-
summarise_date_outliers <- function(df, cond) {
554-
date_cols <- names(df)
555-
n_total <- nrow(df)
556-
557-
outlier_rows <- df %>%
558-
mutate(outlier_row = if_any(all_of(date_cols), ~ cond(.x))) %>%
559-
filter(outlier_row)
560-
561-
tibble(
562-
n_rows = nrow(outlier_rows),
563-
pct_rows = 100 * nrow(outlier_rows) / n_total,
564-
!!!setNames(
565-
lapply(date_cols, function(col) {
566-
sum(cond(pull(df, !!sym(col))), na.rm = TRUE)
567-
}),
568-
paste0(date_cols, "_n")
569-
),
570-
!!!setNames(
571-
lapply(date_cols, function(col) {
572-
100 * sum(cond(pull(df, !!sym(col))), na.rm = TRUE) / n_total
573-
}),
574-
paste0(date_cols, "_pct")
575-
)
576-
)
577-
}
552+
mutate(across(everything(), ~ as.Date(.x)))
578553

579554
summarise_date_outlier_types <- function(df, outlier_conditions) {
580555
date_cols <- names(df)
@@ -626,7 +601,7 @@ write_csv(df_dates_outliers_check, here::here("output", "dataset_date_outliers_c
626601

627602
# get info about dates occuring on index
628603
df_dates_index <- df_dates %>%
629-
summarise_date_outliers(
604+
summarise_date_outlier_types(
630605
function(x) x == as.Date("2025-01-01")
631606
)
632607

@@ -640,59 +615,46 @@ write_csv(df_dates_index, here::here("output", "dataset_date_indexes.csv"))
640615
write_csv(df_dates_index_check, here::here("output", "dataset_date_indexes_check.csv"))
641616

642617
# plot the date distributions
643-
df_dates <- df_dates %>%
644-
mutate(across(everything(), ~ as.Date(.x)))
645618

646619
med_date_plot <- df_dates %>%
647620
filter(
648621
!is.na(meds_sample_date),
649622
meds_sample_date >= as.Date("2020-01-01"),
650-
meds_sample_date < as.Date("2030-01-01"),
651-
meds_sample_date != as.Date("2025-01-01")
623+
meds_sample_date < as.Date("2030-01-01")
652624
) %>%
653625
ggplot(aes(x = meds_sample_date)) +
654-
geom_histogram()
655-
# #binwidth = 365) #+
626+
geom_histogram(binwidth = 15) #+
656627
# #scale_x_date(date_breaks = "50 years", date_labels = "%Y-%m")
657628
ggsave(here::here("output", "sample_med_date_plot.png"))
658629

659630
rep_date_plot <- df_dates %>%
660631
filter(
661632
!is.na(repeats_sample_date),
662633
repeats_sample_date >= as.Date("2020-01-01"),
663-
repeats_sample_date < as.Date("2030-01-01"),
664-
repeats_sample_date != as.Date("2025-01-01")
634+
repeats_sample_date < as.Date("2030-01-01")
665635
) %>%
666636
ggplot(aes(x = repeats_sample_date)) +
667-
geom_histogram()
668-
# #binwidth = 365) #+
669-
# #scale_x_date(date_breaks = "50 years", date_labels = "%Y-%m")
637+
geom_histogram(binwidth = 15)
670638
ggsave(here::here("output", "sample_rep_date_plot.png"))
671639

672640
rep_start_date_plot <- df_dates %>%
673641
filter(
674642
!is.na(repeats_sample_start_date),
675643
repeats_sample_start_date >= as.Date("2020-01-01"),
676-
repeats_sample_start_date < as.Date("2030-01-01"),
677-
repeats_sample_start_date != as.Date("2025-01-01")
644+
repeats_sample_start_date < as.Date("2030-01-01")
678645
) %>%
679646
ggplot(aes(x = repeats_sample_start_date)) +
680-
geom_histogram()
681-
# #binwidth = 365) #+
682-
# #scale_x_date(date_breaks = "50 years", date_labels = "%Y-%m")
647+
geom_histogram(binwidth = 15)
683648
ggsave(here::here("output", "sample_rep_start_date_plot.png"))
684649

685650
rep_end_date_plot <- df_dates %>%
686651
filter(
687652
!is.na(repeats_sample_end_date),
688653
repeats_sample_end_date >= as.Date("2020-01-01"),
689-
repeats_sample_end_date < as.Date("2030-01-01"),
690-
repeats_sample_end_date != as.Date("2025-01-01")
654+
repeats_sample_end_date < as.Date("2030-01-01")
691655
) %>%
692656
ggplot(aes(x = repeats_sample_end_date)) +
693-
geom_histogram()
694-
# #binwidth = 365) #+
695-
# #scale_x_date(date_breaks = "50 years", date_labels = "%Y-%m")
657+
geom_histogram(binwidth = 15)
696658
ggsave(here::here("output", "sample_rep_end_date_plot.png"))
697659

698660
# looking at demographic breakdowns
@@ -862,4 +824,4 @@ visual_sum <- ggplot(
862824
theme_minimal()
863825

864826
# save
865-
ggsave(here::here("output", "dmd_summary_plot.png"))
827+
ggsave(here::here("output", "dmd_summary_plot.png"))

analysis/quantity_checks.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ df_long <- df_with_uom %>%
9595
filter(!is.na(code)) # optional: keep rows with a prescription
9696

9797
# check to see how often the uom appears in the quantity
98-
sum <- df_long %>%
98+
sums <- df_long %>%
9999
group_by(med, record) %>%
100100
summarise(
101101
n = n(),

0 commit comments

Comments
 (0)