Skip to content

Commit

Permalink
include cumulative
Browse files Browse the repository at this point in the history
ref #2
  • Loading branch information
wibeasley committed Feb 29, 2020
1 parent 2b045f4 commit c540b47
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
Binary file modified analysis/month-performance-1/figure-png/scatterplots-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 27 additions & 6 deletions analysis/month-performance-1/month-performance-1.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ requireNamespace("dplyr")
# ---- declare-globals ---------------------------------------------------------
options(show.signif.stars=F) #Turn off the annotations on p-values
config <- config::get()
levels_metric <- c(
"stroke", "antithromb", "anticoag", "statin", "smoking", "cumulative"
)

palette_dark <- list( # http://colrd.com/image-dna/50489/
# "#141e1f", # black
Expand Down Expand Up @@ -62,20 +65,37 @@ ds_wide <- readr::read_csv(config$path_month_raw, col_types = col_types)
pattern <- "^(\\w+)_(numerator|denominator)$"
ds <-
ds_wide %>%
dplyr::mutate(
cumulative_numerator =
dplyr::coalesce(stroke_numerator , 0L) +
dplyr::coalesce(antithromb_numerator , 0L) +
dplyr::coalesce(anticoag_numerator , 0L) +
dplyr::coalesce(statin_numerator , 0L) +
dplyr::coalesce(smoking_numerator , 0L),
cumulative_denominator =
dplyr::coalesce(stroke_denominator , 0L) +
dplyr::coalesce(antithromb_denominator , 0L) +
dplyr::coalesce(anticoag_denominator , 0L) +
dplyr::coalesce(statin_denominator , 0L) +
dplyr::coalesce(smoking_denominator , 0L),
) %>%
tidyr::pivot_longer(
cols = tidyselect::matches(pattern),
names_to = c("metric", ".value"),
names_pattern = pattern
) %>%
dplyr::filter(metric != "cumulative") %>%
# dplyr::filter(metric != "cumulative") %>%
dplyr::mutate(
post = dplyr::recode(phase, "pre" = 0L, "post" = 1L),
phase = factor(phase, levels = c("pre", "post")),
metric = factor(metric, levels = levels_metric),
proportion = numerator / denominator,
label = dplyr::if_else(
denominator == 0L,
sprintf(" --%% (%2i of %2i)" , numerator, denominator),
sprintf("%4.0f%% (%2i of %2i)", proportion * 100, numerator, denominator)
sprintf(" --%% of %2i" , denominator),
sprintf("%4.0f%% of %2i", proportion * 100, denominator)
# sprintf(" --%% (%2i of %2i)" , numerator, denominator),
# sprintf("%4.0f%% (%2i of %2i)", proportion * 100, numerator, denominator)
),
)

Expand Down Expand Up @@ -116,8 +136,8 @@ g1 <-
# dplyr::filter(metric == "statin") %>%
# dplyr::filter(metric == "smoking") %>%
ggplot(aes(x=month, y=proportion, size=denominator, group=metric, label=label, color =phase)) +
geom_text(aes(y = -Inf, size=5), angle = 90, hjust = 0) +
geom_vline(xintercept = config$intervention_start, size = 4, color = "gray70", alpha = .6) +
geom_text(aes(y = -Inf, size=10), alpha = .6, angle = 90, hjust = 0, family = "mono") +
geom_vline(xintercept = config$intervention_start, size = 4, color = "gray80", alpha = .4) +
annotate("text", label = "intervention starts", x = config$intervention_start, y = .5, hjust = .5, angle = 90, alpha = .4) +
geom_line(data=ds[!is.na(ds$proportion), ], size=.5, color = "gray70", inherit.aes = TRUE) +
geom_point(aes(fill = phase), shape=21, alpha = .5, na.rm = T) +
Expand All @@ -135,13 +155,14 @@ g1


# ---- models ------------------------------------------------------------------
m1 <- lm(proportion ~ 1 + post, data = ds)#, subset = (metric == "statin"))
m1 <- lm(proportion ~ 1 + post, data = ds, subset = (metric != "cumulative"))
summary(m1)

m2 <- glm(
numerator / denominator ~ 1 + post,
family = quasipoisson,
# subset = (metric == "statin")
subset = (metric != "cumulative"),
data = ds,
)
summary(m2)
Expand Down
11 changes: 6 additions & 5 deletions analysis/month-performance-1/month-performance-1.html

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions analysis/month-performance-1/month-performance-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Summary {.tabset .tabset-fade .tabset-pills}
Notes
---------------------------------------------------------------------------

1. The current report covers 30 month, with 2 unique values for `month`.
1. The current report covers 36 month, with 2 unique values for `month`.


Unanswered Questions
Expand Down Expand Up @@ -80,7 +80,8 @@ Model Exploration
```
Call:
lm(formula = proportion ~ 1 + post, data = ds)
lm(formula = proportion ~ 1 + post, data = ds, subset = (metric !=
"cumulative"))
Residuals:
Min 1Q Median 3Q Max
Expand All @@ -101,7 +102,7 @@ F-statistic: 0.2565 on 1 and 23 DF, p-value: 0.6173
Call:
glm(formula = numerator/denominator ~ 1 + post, family = quasipoisson,
data = ds)
data = ds, subset = (metric != "cumulative"))
Deviance Residuals:
Min 1Q Median 3Q Max
Expand Down Expand Up @@ -226,4 +227,4 @@ For the sake of documentation and reproducibility, the current report was render



Report rendered by wibeasley at 2020-02-29, 11:45 -0600 in 5 seconds.
Report rendered by wibeasley at 2020-02-29, 12:07 -0600 in 7 seconds.

0 comments on commit c540b47

Please sign in to comment.