Skip to content

Instantly share code, notes, and snippets.

@pgstevenson
Last active March 5, 2021 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgstevenson/9cba21613db22434e58240d9ef0c60d2 to your computer and use it in GitHub Desktop.
Save pgstevenson/9cba21613db22434e58240d9ef0c60d2 to your computer and use it in GitHub Desktop.
fun <- function(d, est, se, p, expo = FALSE, dp = "%0.2f") {
mutate(d,
ci.lo = {{est}} - {{se}} * qnorm((1 + 0.95)/2),
ci.hi = {{est}} + {{se}} * qnorm((1 + 0.95)/2),
p.stars = case_when({{p}} < 0.001 ~ "***",
{{p}} < 0.01 ~ "**",
{{p}} < 0.05 ~ "*",
TRUE ~ ""),
across(c({{est}}, "ci.lo", "ci.hi"), ~case_when(expo ~ exp(.), TRUE ~ .)),
across(c({{est}}, "ci.lo", "ci.hi"), ~sprintf(dp, .)),
txt = paste0({{est}}, " (95% CI: ", ci.lo, " to ", ci.hi, ")", p.stars))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment