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

Soft-deprecate quantreg tidiers #1203

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,6 @@ Suggests:
plm,
poLCA,
psych,
quantreg,
rmarkdown,
robust,
robustbase,
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# broom (development version)

* Soft-deprecated tidiers for margins, lsmeans, and emmeans. Each package has been removed from Suggests and is no longer tested---their tidiers will raise a deprecation warning but return the same results as before.
* Soft-deprecated tidiers for margins, lsmeans, emmeans, and quantreg (rq, rqs, nlrq) objects. Each package has been removed from Suggests and is no longer tested---their tidiers will raise a deprecation warning but return the same results as before.
- margins was archived from CRAN. In the case that the package is back on CRAN before the next package release, broom will once again Suggest and test support for the package (#1200).
- lsmeans and emmeans have a dependency requiring R 4.3.0 or higher. To maintain compatibility with at least 4 previous minor versions of R, broom won't test support for these packages until the release of R 4.7.x (or until lsmeans and emmeans are compatible with the R version 4 minor releases previous, #1193).
- Through its dependency on MatrixModels, and due to CRAN not hosting metadata for Matrix 1.6-x on R 4.1, quantreg requires R 4.4.0 or higher. broom will reintroduce testing (and un-deprecate) for these tidiers when they're once again compatible with R versions through 4 previous minor releases (#1201).

* While this broom release contains no changes to the `tidy.survfit()` method for objects from the survival package, the package has bumped the minimum required version for survival. Before survival 3.6-4, `tidy.survfit()` propagated "inconsistent" `n.censor` values from survival for multi-state models (#1195).

Expand Down
73 changes: 47 additions & 26 deletions R/quantreg-nlrq-tidiers.R
Original file line number Diff line number Diff line change
@@ -1,38 +1,49 @@
#' @templateVar class nlrq
#' @template title_desc_tidy
#'
#' @param x A `nlrq` object returned from [quantreg::nlrq()].
#' @param x A `nlrq` object returned from `quantreg::nlrq()`.
#' @template param_confint
#' @template param_unused_dots
#'
#' @evalRd return_tidy(regression = TRUE)
#'
#' @aliases nlrq_tidiers
#' @export
#' @seealso [tidy()], [quantreg::nlrq()]
#' @seealso [tidy()], `quantreg::nlrq()`
#' @family quantreg tidiers
#' @examplesIf rlang::is_installed("quantreg")
#'
#' # load modeling library
#' library(quantreg)
#'
#' # build artificial data with multiplicative error
#' set.seed(1)
#' dat <- NULL
#' dat$x <- rep(1:25, 20)
#' dat$y <- SSlogis(dat$x, 10, 12, 2) * rnorm(500, 1, 0.1)
#'
#' # fit the median using nlrq
#' mod <- nlrq(y ~ SSlogis(x, Asym, mid, scal),
#' data = dat, tau = 0.5, trace = TRUE
#' )
#'
#' # summarize model fit with tidiers
#' tidy(mod)
#' glance(mod)
#' augment(mod)
#'
# qunatreg not available (#1201)
# @examplesIf rlang::is_installed("quantreg")
#
# # load modeling library
# library(quantreg)
#
# # build artificial data with multiplicative error
# set.seed(1)
# dat <- NULL
# dat$x <- rep(1:25, 20)
# dat$y <- SSlogis(dat$x, 10, 12, 2) * rnorm(500, 1, 0.1)
#
# # fit the median using nlrq
# mod <- nlrq(y ~ SSlogis(x, Asym, mid, scal),
# data = dat, tau = 0.5, trace = TRUE
# )
#
# # summarize model fit with tidiers
# tidy(mod)
# glance(mod)
# augment(mod)
#
tidy.nlrq <- function(x, conf.int = FALSE, conf.level = 0.95, ...) {
lifecycle::deprecate_soft(
"1.0.6",
I("tidying an `nlrq` object"),
details = c(
"i" = "broom no longer tests support for quantreg output as the package
requires an incompatibly recent R version.",
"!" = "Please interpret output with caution."
)
)

check_ellipses("exponentiate", "tidy", "nlrq", ...)

ret <- as_tidy_tibble(
Expand Down Expand Up @@ -64,10 +75,20 @@ tidy.nlrq <- function(x, conf.int = FALSE, conf.level = 0.95, ...) {
#' )
#'
#' @export
#' @seealso [glance()], [quantreg::nlrq()]
#' @seealso [glance()], `quantreg::nlrq()`
#' @family quantreg tidiers
#' @inherit tidy.nlrq examples
glance.nlrq <- function(x, ...) {
lifecycle::deprecate_soft(
"1.0.6",
I("tidying an `nlrq` object"),
details = c(
"i" = "broom no longer tests support for quantreg output as the package
requires an incompatibly recent R version.",
"!" = "Please interpret output with caution."
)
)

n <- length(x[["m"]]$fitted())
s <- summary(x)

Expand All @@ -84,11 +105,11 @@ glance.nlrq <- function(x, ...) {
#' @templateVar class nlrq
#' @template title_desc_tidy
#'
#' @param x A `nlrq` object returned from [quantreg::nlrq()].
#' @param x A `nlrq` object returned from `quantreg::nlrq()`.
#' @inherit augment.nls params examples return
#'
#' @export
#' @seealso [augment()], [quantreg::nlrq()]
#' @seealso [augment()], `quantreg::nlrq()`
#' @family quantreg tidiers
#' @include stats-nls-tidiers.R
#'
Expand Down
107 changes: 69 additions & 38 deletions R/quantreg-rq-tidiers.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#' @templateVar class rq
#' @template title_desc_tidy
#'
#' @param x An `rq` object returned from [quantreg::rq()].
#' @param x An `rq` object returned from `quantreg::rq()`.
#' @param se.type Character specifying the method to use to calculate
#' standard errors. Passed to [quantreg::summary.rq()] `se` argument.
#' standard errors. Passed to `quantreg::summary.rq()` `se` argument.
#' Defaults to `"rank"` if the sample size is less than 1000,
#' otherwise defaults to `"nid"`.
#' @template param_confint
#' @param ... Additional arguments passed to [quantreg::summary.rq()].
#' @param ... Additional arguments passed to `quantreg::summary.rq()`.
#'
#' @details If `se.type = "rank"` confidence intervals are calculated by
#' `summary.rq` and `statistic` and `p.value` values are not returned.
Expand All @@ -19,42 +19,53 @@
#'
#' @aliases rq_tidiers quantreg_tidiers
#' @export
#' @seealso [tidy()], [quantreg::rq()]
#' @seealso [tidy()], `quantreg::rq()`
#' @family quantreg tidiers
#'
#' @examplesIf rlang::is_installed("quantreg")
#'
#' # load modeling library and data
#' library(quantreg)
#'
#' data(stackloss)
#'
#' # median (l1) regression fit for the stackloss data.
#' mod1 <- rq(stack.loss ~ stack.x, .5)
#'
#' # weighted sample median
#' mod2 <- rq(rnorm(50) ~ 1, weights = runif(50))
#'
#' # summarize model fit with tidiers
#' tidy(mod1)
#' glance(mod1)
#' augment(mod1)
#'
#' tidy(mod2)
#' glance(mod2)
#' augment(mod2)
#'
#' # varying tau to generate an rqs object
#' mod3 <- rq(stack.loss ~ stack.x, tau = c(.25, .5))
#'
#' tidy(mod3)
#' augment(mod3)
#'
#' # glance cannot handle rqs objects like `mod3`--use a purrr
#' # `map`-based workflow instead
#'
# quantreg not available (#1201)
# @examplesIf rlang::is_installed("quantreg")
#
# # load modeling library and data
# library(quantreg)
#
# data(stackloss)
#
# # median (l1) regression fit for the stackloss data.
# mod1 <- rq(stack.loss ~ stack.x, .5)
#
# # weighted sample median
# mod2 <- rq(rnorm(50) ~ 1, weights = runif(50))
#
# # summarize model fit with tidiers
# tidy(mod1)
# glance(mod1)
# augment(mod1)
#
# tidy(mod2)
# glance(mod2)
# augment(mod2)
#
# # varying tau to generate an rqs object
# mod3 <- rq(stack.loss ~ stack.x, tau = c(.25, .5))
#
# tidy(mod3)
# augment(mod3)
#
# # glance cannot handle rqs objects like `mod3`--use a purrr
# # `map`-based workflow instead
#
tidy.rq <- function(x, se.type = NULL, conf.int = FALSE,
conf.level = 0.95, ...) {
lifecycle::deprecate_soft(
"1.0.6",
I("tidying an `rq` object"),
details = c(
"i" = "broom no longer tests support for quantreg output as the package
requires an incompatibly recent R version.",
"!" = "Please interpret output with caution."
)
)

check_ellipses("exponentiate", "tidy", "rq", ...)

# specification for confidence level inverted for summary.rq
Expand All @@ -68,7 +79,7 @@ tidy.rq <- function(x, se.type = NULL, conf.int = FALSE,

# summary.rq often issues warnings when computing standard error
rq_summary <- suppressWarnings(
quantreg::summary.rq(x, se = se.type, alpha = alpha, ...)
summary(x, se = se.type, alpha = alpha, ...)
)

process_rq(
Expand Down Expand Up @@ -105,6 +116,16 @@ tidy.rq <- function(x, se.type = NULL, conf.int = FALSE,
#' @seealso [glance()], [quantreg::rq()]
#' @family quantreg tidiers
glance.rq <- function(x, ...) {
lifecycle::deprecate_soft(
"1.0.6",
I("tidying an `rq` object"),
details = c(
"i" = "broom no longer tests support for quantreg output as the package
requires an incompatibly recent R version.",
"!" = "Please interpret output with caution."
)
)

n <- length(fitted(x))
s <- summary(x)

Expand All @@ -121,7 +142,7 @@ glance.rq <- function(x, ...) {
#' @templateVar class rq
#' @template title_desc_augment
#'
#' @param x An `rq` object returned from [quantreg::rq()].
#' @param x An `rq` object returned from `quantreg::rq()`.
#' @template param_data
#' @template param_newdata
#' @inheritDotParams quantreg::predict.rq
Expand All @@ -136,9 +157,19 @@ glance.rq <- function(x, ...) {
#' intervals when data is specified via the `newdata` argument.
#'
#' @export
#' @seealso [augment], [quantreg::rq()], [quantreg::predict.rq()]
#' @seealso [augment], `quantreg::rq()`, `quantreg::predict.rq()`
#' @family quantreg tidiers
augment.rq <- function(x, data = model.frame(x), newdata = NULL, ...) {
lifecycle::deprecate_soft(
"1.0.6",
I("tidying an `rq` object"),
details = c(
"i" = "broom no longer tests support for quantreg output as the package
requires an incompatibly recent R version.",
"!" = "Please interpret output with caution."
)
)

args <- list(...)
force_newdata <- FALSE
if ("interval" %in% names(args) && args[["interval"]] != "none") {
Expand Down
34 changes: 27 additions & 7 deletions R/quantreg-rqs-tidiers.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#' @templateVar class rqs
#' @template title_desc_tidy
#'
#' @param x An `rqs` object returned from [quantreg::rq()].
#' @param x An `rqs` object returned from `quantreg::rq()`.
#' @param se.type Character specifying the method to use to calculate
#' standard errors. Passed to [quantreg::summary.rq()] `se` argument.
#' standard errors. Passed to `quantreg::summary.rq()` `se` argument.
#' Defaults to `"rank"`.
#' @template param_confint
#' @param ... Additional arguments passed to [quantreg::summary.rqs()]
#' @param ... Additional arguments passed to `quantreg::summary.rqs()`
#'
#' @evalRd return_tidy(regression = TRUE,
#' quantile = "Linear conditional quantile.")
Expand All @@ -18,16 +18,26 @@
#'
#' @aliases rqs_tidiers
#' @export
#' @seealso [tidy()], [quantreg::rq()]
#' @seealso [tidy()], `quantreg::rq()`
#' @family quantreg tidiers
#' @inherit tidy.rq examples
#'
tidy.rqs <- function(x, se.type = "rank", conf.int = FALSE,
conf.level = 0.95, ...) {
lifecycle::deprecate_soft(
"1.0.6",
I("tidying an `rqs` object"),
details = c(
"i" = "broom no longer tests support for quantreg output as the package
requires an incompatibly recent R version.",
"!" = "Please interpret output with caution."
)
)

check_ellipses("exponentiate", "tidy", "rqs", ...)

rq_summary <- suppressWarnings(
quantreg::summary.rqs(x, se = se.type, alpha = 1 - conf.level, ...)
summary(x, se = se.type, alpha = 1 - conf.level, ...)
)

purrr::map_df(
Expand All @@ -54,16 +64,26 @@ glance.rqs <- function(x, ...) {
#' @inherit tidy.rqs examples
#' @inherit augment.rq return details
#'
#' @param x An `rqs` object returned from [quantreg::rq()].
#' @param x An `rqs` object returned from `quantreg::rq()`.
#' @template param_data
#' @template param_newdata
#' @inheritDotParams quantreg::predict.rq
#'
#' @export
#' @seealso [augment], [quantreg::rq()], [quantreg::predict.rqs()]
#' @seealso [augment], `quantreg::rq()`, `quantreg::predict.rqs()`
#' @family quantreg tidiers
#' @inherit tidy.rq examples
augment.rqs <- function(x, data = model.frame(x), newdata, ...) {
lifecycle::deprecate_soft(
"1.0.6",
I("tidying an `rqs` object"),
details = c(
"i" = "broom no longer tests support for quantreg output as the package
requires an incompatibly recent R version.",
"!" = "Please interpret output with caution."
)
)

n_tau <- length(x[["tau"]])
if (missing(newdata) || is.null(newdata)) {
original <- data[rep(seq_len(nrow(data)), each = n_tau), , drop = FALSE]
Expand Down
4 changes: 2 additions & 2 deletions man/augment.nlrq.Rd

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