-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#8 added functions and excel_ref data
- Loading branch information
1 parent
5347fb8
commit 5f67531
Showing
13 changed files
with
194 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,4 +40,4 @@ Imports: | |
Suggests: | ||
rmarkdown | ||
VignetteBuilder: knitr | ||
RoxygenNote: 6.1.0 | ||
RoxygenNote: 6.1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#' Format a model for quick in-text referencing | ||
#' | ||
#' This function builds on `broom::tidy()` by adding formatted strings ready for use in text. | ||
#' | ||
#' @param x a model object | ||
#' @param effects (default NULL) a tidy effects option e.g. "fixed", "random" | ||
#' @param conf.level (default 0.95) the reported confidence interval of model estimates | ||
#' @param dp (default 2) the number of decimal points reported in returned strings | ||
#' | ||
#' @return a tibble with default `tidy()` parameters plus `conf.low`, `conf.high`, `text1`, and `text2` | ||
#' | ||
#' @importFrom broom tidy | ||
#' @importFrom dplyr mutate select left_join | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' data(iris) | ||
#' m1 <- lm(Sepal.Length ~ Sepal.Width, data = iris) | ||
#' | ||
#' format_model(m1) %>% select(term, estimate, conf.low, conf.high) | ||
#' | ||
#' format_model(m1)$text1 | ||
#' format_model(m1)$text2 | ||
#' } | ||
#' | ||
#' @export | ||
format_model <- function(x, effects = NULL, conf.level = 0.95, dp = 2) { | ||
a <- broom::tidy(x, effects = effects, conf.int = T, conf.level = conf.level) | ||
b <- a %>% | ||
round_df(dp) %>% | ||
dplyr::mutate(text1 = paste0(estimate, " (", 100 * conf.level, "% CI: ", conf.low, " to ", conf.high, ")"), | ||
text2 = paste0("(", estimate, "; , ", 100 * conf.level, "% CI: ", conf.low, " to ", conf.high, ")")) %>% | ||
dplyr::select(term, text1, text2) | ||
dplyr::left_join(a, b, by = "term") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#' Round data frame decimal points | ||
#' | ||
#' Round the numeric columns of a data frame to the specified number of decimal | ||
#' points using the `sprintf` function. | ||
#' | ||
#' @param df the data frame to be rounded | ||
#' @param dp (default 2) the desired number of decimal points | ||
#' | ||
#' @return a data frame, the rounded columns are convertd to character objects. | ||
#' | ||
#' @importFrom dplyr mutate_at | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' data(mtcars) | ||
#' | ||
#' head( round_df(mtcars, 1) ) | ||
#' } | ||
#' | ||
#' @export | ||
round_df <- function(df, dp = 2) { | ||
mutate_at(df, | ||
names(df)[vapply(df, is.numeric, FUN.VALUE = logical(1), USE.NAMES = F)], | ||
.funs = list(~sprintf(paste0("%0.", dp, "f"), .))) | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.