Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change names of interval columns in augment() for clarity #925

Merged
merged 10 commits into from Sep 18, 2020
6 changes: 5 additions & 1 deletion DESCRIPTION
Expand Up @@ -495,7 +495,11 @@ Authors@R:
person(given = "R. Willem",
family = "Vervoort",
role = "ctb",
email = "Willemvervoort@gmail.com"))
email = "Willemvervoort@gmail.com"),
person(given = "Brenton M.",
family = "Wiernik",
role = "ctb",
email = "brenton@wiernik.org"))
Description: Summarizes key information about statistical
objects in tidy tibbles. This makes it easy to report results, create
plots and consistently work with large numbers of models at once.
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Expand Up @@ -22,6 +22,7 @@ method also now takes a `type.residuals` argument and defaults to the same
* Fixed bug related to univariate zoo series in `tidy.zoo()` (#916 by @WillemVervoort)
* Fixed a bug related to `tidy.prcomp()` assigning the wrong PC labels from "loadings"
and "scores" matrices (#910 by @tavareshugo)
* Consistently label interval columns `.lower` and `.upper` in `augment()` methods (#925 by @bwiernik)

# broom 0.7.0

Expand Down
8 changes: 4 additions & 4 deletions R/drc-tidiers.R
Expand Up @@ -81,8 +81,8 @@ glance.drc <- function(x, ...) {
#' @template param_unused_dots
#'
#' @evalRd return_augment(
#' ".conf.low",
#' ".conf.high",
#' ".lower",
#' ".upper",
#' ".se.fit",
#' ".fitted",
#' ".resid",
Expand Down Expand Up @@ -123,8 +123,8 @@ augment.drc <- function(x, data = NULL, newdata = NULL,
newdata = newdata, interval = "confidence",
level = conf.level
))
ret[[".conf.low"]] <- preds[["Lower"]]
ret[[".conf.high"]] <- preds[["Upper"]]
ret[[".lower"]] <- preds[["Lower"]]
ret[[".upper"]] <- preds[["Upper"]]
}
if (se_fit) {
preds <- data.frame(predict(x, newdata = newdata, se.fit = TRUE))
Expand Down
4 changes: 2 additions & 2 deletions R/quantreg-rq-tidiers.R
Expand Up @@ -99,7 +99,7 @@ glance.rq <- function(x, ...) {
#'
#' @details Depending on the arguments passed on to `predict.rq` via `...`,
#' a confidence interval is also calculated on the fitted values resulting in
#' columns `.conf.low` and `.conf.high`. Does not provide confidence
#' columns `.lower` and `.upper`. Does not provide confidence
#' intervals when data is specified via the `newdata` argument.
#'
#' @export
Expand Down Expand Up @@ -129,7 +129,7 @@ augment.rq <- function(x, data = model.frame(x), newdata = NULL, ...) {
original[[".tau"]] <- x[["tau"]]
return(as_tibble(original))
} else {
colnames(pred) <- c(".fitted", ".conf.low", ".conf.high")
colnames(pred) <- c(".fitted", ".lower", ".upper")
original[[".tau"]] <- x[["tau"]]
return(as_tibble(cbind(original, pred)))
}
Expand Down
14 changes: 7 additions & 7 deletions R/rma-tidiers.R
Expand Up @@ -191,10 +191,10 @@ glance.rma <- function(x, ...) {
#' .observed = "The observed values for the individual studies",
#' ".fitted",
#' ".se.fit",
#' ".conf.low",
#' ".conf.high",
#' ".cred.low",
#' ".cred.high",
#' ".conf.lower",
#' ".conf.upper",
#' ".pred.lower",
#' ".pred.upper",
#' ".resid",
#' ".moderator",
#' ".moderator.level"
Expand Down Expand Up @@ -235,9 +235,9 @@ augment.rma <- function(x, ...) {
pred <- as.data.frame(pred)

# fix names
names(pred)[1:4] <- c(".fitted", ".se.fit", ".conf.low", ".conf.high")
credible_intervals <- names(pred) %in% c("cr.lb", "cr.ub")
names(pred)[credible_intervals] <- c(".cred.low", ".cred.high")
names(pred)[1:4] <- c(".fitted", ".se.fit", ".conf.lower", ".conf.upper")
simonpcouch marked this conversation as resolved.
Show resolved Hide resolved
credible_intervals <- names(pred) %in% c("cr.lb", "cr.ub", "pi.lb", "pi.ub")
names(pred)[credible_intervals] <- c(".pred.lower", ".pred.upper")
moderator <- names(pred) == "X"
names(pred)[moderator] <- ".moderator"
moderator_level <- names(pred) == "tau2.level"
Expand Down
6 changes: 3 additions & 3 deletions R/stats-lm-tidiers.R
Expand Up @@ -45,7 +45,7 @@
#' ggplot(au, aes(wt, mpg)) +
#' geom_point() +
#' geom_line(aes(y = .fitted)) +
#' geom_ribbon(aes(ymin = .conf.low, ymax = .conf.high), col = NA, alpha = 0.3)
#' geom_ribbon(aes(ymin = .lower, ymax = .upper), col = NA, alpha = 0.3)
#'
#' # predict on new data without outcome variable. Output does not include .resid
#' newdata <- newdata %>%
Expand Down Expand Up @@ -113,8 +113,8 @@ tidy.lm <- function(x, conf.int = FALSE, conf.level = 0.95, ...) {
#'
#' @evalRd return_augment(
#' ".hat",
#' ".conf.low",
#' ".conf.high",
#' ".lower",
#' ".upper",
#' ".sigma",
#' ".cooksd",
#' ".se.fit",
Expand Down
16 changes: 8 additions & 8 deletions R/utilities.R
Expand Up @@ -390,8 +390,8 @@ augment_newdata <- function(x, data, newdata, .se_fit, interval = NULL, ...) {
df$.fitted <- pred_obj$fit %>% unname()
} else {
df$.fitted <- pred_obj$fit[, "fit"]
df$.conf.low <- pred_obj$fit[, "lwr"]
df$.conf.high <- pred_obj$fit[, "upr"]
df$.lower <- pred_obj$fit[, "lwr"]
df$.upper <- pred_obj$fit[, "upr"]
}

# a couple possible names for the standard error element of the list
Expand All @@ -403,17 +403,17 @@ augment_newdata <- function(x, data, newdata, .se_fit, interval = NULL, ...) {
} else if (!is.null(interval) && interval!="none") {
pred_obj <- predict(x, newdata = newdata, na.action = na.pass, se.fit = FALSE, interval = interval, ...)
df$.fitted <- pred_obj[, "fit"]
df$.conf.low <- pred_obj[, "lwr"]
df$.conf.high <- pred_obj[, "upr"]
df$.lower <- pred_obj[, "lwr"]
df$.upper <- pred_obj[, "upr"]
} else if (passed_newdata) {
if (is.null(interval) || interval=="none") {
df$.fitted <- predict(x, newdata = newdata, na.action = na.pass, ...) %>%
unname()
} else {
pred_obj <- predict(x, newdata = newdata, na.action = na.pass, interval = interval, ...)
df$.fitted <- pred_obj$fit[, "fit"]
df$.conf.low <- pred_obj$fit[, "lwr"]
df$.conf.high <- pred_obj$fit[, "upr"]
df$.lower <- pred_obj$fit[, "lwr"]
df$.upper <- pred_obj$fit[, "upr"]
}
} else {
if (is.null(interval) || interval=="none") {
Expand All @@ -422,8 +422,8 @@ augment_newdata <- function(x, data, newdata, .se_fit, interval = NULL, ...) {
} else {
pred_obj <- predict(x, newdata = newdata, na.action = na.pass, interval = interval, ...)
df$.fitted <- pred_obj$fit[, "fit"]
df$.conf.low <- pred_obj$fit[, "lwr"]
df$.conf.high <- pred_obj$fit[, "upr"]
df$.lower <- pred_obj$fit[, "lwr"]
df$.upper <- pred_obj$fit[, "upr"]
}
}

Expand Down
4 changes: 2 additions & 2 deletions man/augment.clm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions man/augment.drc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions man/augment.felm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/augment.fixest.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/augment.lm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions man/augment.rma.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/augment.rq.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/augment.rqs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/augment.sarlm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/broom.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/glance.ergm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions man/glance.felm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/glance.lm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/glance.sarlm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/tidy.cld.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.