@@ -547,34 +547,9 @@ write_csv(df_status_issues_rep, here::here("output", "dataset_status_repeats.csv
547547# sample date distributions
548548df_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
579554summarise_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
628603df_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"))
640615write_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
646619med_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")
657628ggsave(here :: here(" output" , " sample_med_date_plot.png" ))
658629
659630rep_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 )
670638ggsave(here :: here(" output" , " sample_rep_date_plot.png" ))
671639
672640rep_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 )
683648ggsave(here :: here(" output" , " sample_rep_start_date_plot.png" ))
684649
685650rep_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 )
696658ggsave(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" ))
0 commit comments