Skip to content

Commit

Permalink
try different MLMs.
Browse files Browse the repository at this point in the history
due diligence.  still not sig

ref #2
  • Loading branch information
wibeasley committed Feb 29, 2020
1 parent c540b47 commit 48dd6f4
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 132 deletions.
45 changes: 41 additions & 4 deletions analysis/month-performance-1/month-performance-1.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ rm(list = ls(all.names = TRUE)) # Clear the memory of variables from previous ru
# source("SomethingSomething.R")

# ---- load-packages -----------------------------------------------------------
library(ggplot2) #For graphing
library(ggplot2) # For graphing
library(lme4) # For multilevel models
import::from("magrittr", "%>%")
requireNamespace("dplyr")
# requireNamespace("RColorBrewer")
Expand Down Expand Up @@ -90,6 +91,11 @@ ds <-
phase = factor(phase, levels = c("pre", "post")),
metric = factor(metric, levels = levels_metric),
proportion = numerator / denominator,
prior_lower = 1 / (denominator + 10),
prior_upper = 1 - 1 / (denominator + 10),
proportion_bounded = pmin(pmax(proportion, prior_lower), prior_upper),
# proportion_bounded = pmin(pmax(proportion, prior_upper), prior_lower),
logit = qlogis(proportion_bounded),
label = dplyr::if_else(
denominator == 0L,
sprintf(" --%% of %2i" , denominator),
Expand All @@ -98,6 +104,8 @@ ds <-
# sprintf("%4.0f%% (%2i of %2i)", proportion * 100, numerator, denominator)
),
)
# plot(ds$proportion, ds$proportion_bounded)
# ds$proportion_bounded


# dplyr::mutate(
Expand Down Expand Up @@ -155,18 +163,47 @@ g1


# ---- models ------------------------------------------------------------------
m1 <- lm(proportion ~ 1 + post, data = ds, subset = (metric != "cumulative"))
summary(m1)
ds_model <-
ds %>%
dplyr::filter(0L < denominator)

cat("\n\n Model proportion w/ Gaussian link")
m1a <- lm(proportion ~ 1 + post, data = ds_model, subset = (metric != "cumulative"))
summary(m1a)

cat("\n\n Model logit w/ Gaussian link")
m1b <- lm(logit ~ 1 + post, data = ds_model, subset = (metric != "cumulative"))
summary(m1b)


cat("\n\n Model numerator & denominator w/ Poisson link")
m2 <- glm(
numerator / denominator ~ 1 + post,
family = quasipoisson,
# subset = (metric == "statin")
subset = (metric != "cumulative"),
data = ds,
data = ds_model,
)
summary(m2)

# m4 <- glmer(
# numerator ~ 1 + post + (1 | metric) + offset(log(denominator)),
# # family="poisson",
# family=poisson(link="log"),
# data = ds[0L < ds$denominator, ]
# )
# summary(m4)
#
# # library(MCMCglmm)
# summary(MCMCglmm::MCMCglmm(
# numerator ~ 1 + post + offset(log(denominator)),
# family = "poisson",
# data = ds,
# verbose = FALSE
# ))




# ---- model-results-table -----------------------------------------------
summary(m2)$coef %>%
Expand Down
160 changes: 96 additions & 64 deletions analysis/month-performance-1/month-performance-1.html
Original file line number Diff line number Diff line change
Expand Up @@ -1572,9 +1572,12 @@ <h2 number="2.2"><span class="header-section-number">2.2</span> Scatterplots</h2
<h1 number="3"><span class="header-section-number">3</span> Models</h1>
<div id="model-exploration" class="section level2" number="3.1">
<h2 number="3.1"><span class="header-section-number">3.1</span> Model Exploration</h2>
<pre><code>

Model proportion w/ Gaussian link</code></pre>
<pre><code>
Call:
lm(formula = proportion ~ 1 + post, data = ds, subset = (metric !=
lm(formula = proportion ~ 1 + post, data = ds_model, subset = (metric !=
&quot;cumulative&quot;))

Residuals:
Expand All @@ -1587,13 +1590,35 @@ <h2 number="3.1"><span class="header-section-number">3.1</span> Model Exploratio
post -0.05315 0.10495 -0.506 0.617

Residual standard error: 0.2356 on 23 degrees of freedom
(5 observations deleted due to missingness)
Multiple R-squared: 0.01103, Adjusted R-squared: -0.03197
F-statistic: 0.2565 on 1 and 23 DF, p-value: 0.6173</code></pre>
<pre><code>

Model logit w/ Gaussian link</code></pre>
<pre><code>
Call:
lm(formula = logit ~ 1 + post, data = ds_model, subset = (metric !=
&quot;cumulative&quot;))

Residuals:
Min 1Q Median 3Q Max
-3.9261 -0.2373 0.4174 0.6790 1.0155

Coefficients:
Estimate Std. Error t value Pr(&gt;|t|)
(Intercept) 1.8852 0.2767 6.814 5.99e-07
post -0.2617 0.5228 -0.500 0.621

Residual standard error: 1.174 on 23 degrees of freedom
Multiple R-squared: 0.01077, Adjusted R-squared: -0.03224
F-statistic: 0.2505 on 1 and 23 DF, p-value: 0.6215</code></pre>
<pre><code>

Model numerator &amp; denominator w/ Poisson link</code></pre>
<pre><code>
Call:
glm(formula = numerator/denominator ~ 1 + post, family = quasipoisson,
data = ds, subset = (metric != &quot;cumulative&quot;))
data = ds_model, subset = (metric != &quot;cumulative&quot;))

Deviance Residuals:
Min 1Q Median 3Q Max
Expand All @@ -1608,7 +1633,6 @@ <h2 number="3.1"><span class="header-section-number">3.1</span> Model Exploratio

Null deviance: 2.3827 on 24 degrees of freedom
Residual deviance: 2.3661 on 23 degrees of freedom
(5 observations deleted due to missingness)
AIC: NA

Number of Fisher Scoring iterations: 4</code></pre>
Expand Down Expand Up @@ -1663,72 +1687,80 @@ <h1 number="4"><span class="header-section-number">4</span> Session Information<
date 2020-02-29

─ Packages ───────────────────────────────────────────────────────────────────
package * version date lib source
assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.1)
backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.1)
callr 3.4.2 2020-02-12 [1] CRAN (R 3.6.2)
cli 2.0.1 2020-01-08 [1] CRAN (R 3.6.1)
colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.6.1)
config 0.3 2018-03-27 [1] CRAN (R 3.6.1)
crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.1)
desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.1)
devtools 2.2.2 2020-02-17 [1] CRAN (R 3.6.2)
digest 0.6.24 2020-02-12 [1] CRAN (R 3.6.2)
dplyr 0.8.4 2020-01-31 [1] CRAN (R 3.6.2)
ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.1)
evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.1)
fansi 0.4.1 2020-01-08 [1] CRAN (R 3.6.1)
farver 2.0.3 2020-01-16 [1] CRAN (R 3.6.1)
fs 1.3.1 2019-05-06 [1] CRAN (R 3.6.1)
ggplot2 * 3.2.1 2019-08-10 [1] CRAN (R 3.6.1)
glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.1)
gtable 0.3.0 2019-03-25 [1] CRAN (R 3.6.1)
highr 0.8 2019-03-20 [1] CRAN (R 3.6.1)
hms 0.5.3 2020-01-08 [1] CRAN (R 3.6.1)
htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.1)
import 1.1.0 2015-06-22 [1] CRAN (R 3.6.1)
knitr * 1.28 2020-02-06 [1] CRAN (R 3.6.2)
labeling 0.3 2014-08-23 [1] CRAN (R 3.6.1)
lazyeval 0.2.2 2019-03-15 [1] CRAN (R 3.6.1)
lifecycle 0.1.0 2019-08-01 [1] CRAN (R 3.6.1)
magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.1)
memoise 1.1.0 2017-04-21 [1] CRAN (R 3.6.1)
munsell 0.5.0 2018-06-12 [1] CRAN (R 3.6.1)
pillar 1.4.3 2019-12-20 [1] CRAN (R 3.6.1)
pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.1)
pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.1)
pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.6.1)
prettyunits 1.1.1 2020-01-24 [1] CRAN (R 3.6.2)
processx 3.4.2 2020-02-09 [1] CRAN (R 3.6.2)
ps 1.3.2 2020-02-13 [1] CRAN (R 3.6.2)
purrr 0.3.3 2019-10-18 [1] CRAN (R 3.6.1)
R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.1)
Rcpp 1.0.3 2019-11-08 [1] CRAN (R 3.6.1)
readr 1.3.1 2018-12-21 [1] CRAN (R 3.6.1)
remotes 2.1.1 2020-02-15 [1] CRAN (R 3.6.2)
rlang 0.4.4 2020-01-28 [1] CRAN (R 3.6.2)
rmarkdown 2.1 2020-01-20 [1] CRAN (R 3.6.2)
rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.1)
scales 1.1.0 2019-11-18 [1] CRAN (R 3.6.1)
sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.1)
stringi 1.4.6 2020-02-17 [1] CRAN (R 3.6.2)
stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.1)
testthat 2.3.1 2019-12-01 [1] CRAN (R 3.6.1)
tibble 2.1.3 2019-06-06 [1] CRAN (R 3.6.1)
tidyr 1.0.2 2020-01-24 [1] CRAN (R 3.6.2)
tidyselect 1.0.0 2020-01-27 [1] CRAN (R 3.6.2)
usethis 1.5.1 2019-07-04 [1] CRAN (R 3.6.1)
vctrs 0.2.3 2020-02-20 [1] CRAN (R 3.6.2)
withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.1)
xfun 0.12 2020-01-13 [1] CRAN (R 3.6.1)
yaml 2.2.1 2020-02-01 [1] CRAN (R 3.6.2)
package * version date lib source
assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.1)
backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.1)
boot 1.3-24 2019-12-20 [4] CRAN (R 3.6.2)
callr 3.4.2 2020-02-12 [1] CRAN (R 3.6.2)
cli 2.0.1 2020-01-08 [1] CRAN (R 3.6.1)
colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.6.1)
config 0.3 2018-03-27 [1] CRAN (R 3.6.1)
crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.1)
desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.1)
devtools 2.2.2 2020-02-17 [1] CRAN (R 3.6.2)
digest 0.6.24 2020-02-12 [1] CRAN (R 3.6.2)
dplyr 0.8.4 2020-01-31 [1] CRAN (R 3.6.2)
ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.1)
evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.1)
fansi 0.4.1 2020-01-08 [1] CRAN (R 3.6.1)
farver 2.0.3 2020-01-16 [1] CRAN (R 3.6.1)
fs 1.3.1 2019-05-06 [1] CRAN (R 3.6.1)
ggplot2 * 3.2.1 2019-08-10 [1] CRAN (R 3.6.1)
glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.1)
gtable 0.3.0 2019-03-25 [1] CRAN (R 3.6.1)
highr 0.8 2019-03-20 [1] CRAN (R 3.6.1)
hms 0.5.3 2020-01-08 [1] CRAN (R 3.6.1)
htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.1)
import 1.1.0 2015-06-22 [1] CRAN (R 3.6.1)
knitr * 1.28 2020-02-06 [1] CRAN (R 3.6.2)
labeling 0.3 2014-08-23 [1] CRAN (R 3.6.1)
lattice 0.20-40 2020-02-19 [1] CRAN (R 3.6.2)
lazyeval 0.2.2 2019-03-15 [1] CRAN (R 3.6.1)
lifecycle 0.1.0 2019-08-01 [1] CRAN (R 3.6.1)
lme4 * 1.1-21 2019-03-05 [1] CRAN (R 3.6.1)
magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.1)
MASS 7.3-51.5 2019-12-20 [4] CRAN (R 3.6.2)
Matrix * 1.2-18 2019-11-27 [4] CRAN (R 3.6.1)
memoise 1.1.0 2017-04-21 [1] CRAN (R 3.6.1)
minqa 1.2.4 2014-10-09 [1] CRAN (R 3.6.1)
munsell 0.5.0 2018-06-12 [1] CRAN (R 3.6.1)
nlme 3.1-144 2020-02-06 [1] CRAN (R 3.6.2)
nloptr 1.2.1 2018-10-03 [1] CRAN (R 3.6.1)
pillar 1.4.3 2019-12-20 [1] CRAN (R 3.6.1)
pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.1)
pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.1)
pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.6.1)
prettyunits 1.1.1 2020-01-24 [1] CRAN (R 3.6.2)
processx 3.4.2 2020-02-09 [1] CRAN (R 3.6.2)
ps 1.3.2 2020-02-13 [1] CRAN (R 3.6.2)
purrr 0.3.3 2019-10-18 [1] CRAN (R 3.6.1)
R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.1)
Rcpp 1.0.3 2019-11-08 [1] CRAN (R 3.6.1)
readr 1.3.1 2018-12-21 [1] CRAN (R 3.6.1)
remotes 2.1.1 2020-02-15 [1] CRAN (R 3.6.2)
rlang 0.4.4 2020-01-28 [1] CRAN (R 3.6.2)
rmarkdown 2.1 2020-01-20 [1] CRAN (R 3.6.2)
rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.1)
scales 1.1.0 2019-11-18 [1] CRAN (R 3.6.1)
sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.1)
stringi 1.4.6 2020-02-17 [1] CRAN (R 3.6.2)
stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.1)
testthat 2.3.1 2019-12-01 [1] CRAN (R 3.6.1)
tibble 2.1.3 2019-06-06 [1] CRAN (R 3.6.1)
tidyr 1.0.2 2020-01-24 [1] CRAN (R 3.6.2)
tidyselect 1.0.0 2020-01-27 [1] CRAN (R 3.6.2)
usethis 1.5.1 2019-07-04 [1] CRAN (R 3.6.1)
vctrs 0.2.3 2020-02-20 [1] CRAN (R 3.6.2)
withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.1)
xfun 0.12 2020-01-13 [1] CRAN (R 3.6.1)
yaml 2.2.1 2020-02-01 [1] CRAN (R 3.6.2)

[1] /home/wibeasley/R/x86_64-pc-linux-gnu-library/3.6
[2] /usr/local/lib/R/site-library
[3] /usr/lib/R/site-library
[4] /usr/lib/R/library</code></pre>
</details>
<p>Report rendered by wibeasley at 2020-02-29, 12:07 -0600 in 7 seconds.</p>
<p>Report rendered by wibeasley at 2020-02-29, 13:44 -0600 in 10 seconds.</p>
</div>


Expand Down
Loading

0 comments on commit 48dd6f4

Please sign in to comment.