| 1 |
#' @templateVar class nlrq |
| 2 |
#' @template title_desc_tidy |
| 3 |
#' |
| 4 |
#' @param x A `nlrq` object returned from [quantreg::nlrq()]. |
| 5 |
#' @template param_confint |
| 6 |
#' @template param_unused_dots |
| 7 |
#' |
| 8 |
#' @evalRd return_tidy(regression = TRUE) |
| 9 |
#' |
| 10 |
#' @aliases nlrq_tidiers |
| 11 |
#' @export |
| 12 |
#' @seealso [tidy()], [quantreg::nlrq()] |
| 13 |
#' @family quantreg tidiers |
| 14 |
#' @examplesIf rlang::is_installed("quantreg") |
| 15 |
#' |
| 16 |
#' # load modeling library |
| 17 |
#' library(quantreg) |
| 18 |
#' |
| 19 |
#' # build artificial data with multiplicative error |
| 20 |
#' set.seed(1) |
| 21 |
#' dat <- NULL |
| 22 |
#' dat$x <- rep(1:25, 20) |
| 23 |
#' dat$y <- SSlogis(dat$x, 10, 12, 2) * rnorm(500, 1, 0.1) |
| 24 |
#' |
| 25 |
#' # fit the median using nlrq |
| 26 |
#' mod <- nlrq(y ~ SSlogis(x, Asym, mid, scal), |
| 27 |
#' data = dat, tau = 0.5, trace = TRUE |
| 28 |
#' ) |
| 29 |
#' |
| 30 |
#' # summarize model fit with tidiers |
| 31 |
#' tidy(mod) |
| 32 |
#' glance(mod) |
| 33 |
#' augment(mod) |
| 34 |
#' |
| 35 |
tidy.nlrq <- function(x, conf.int = FALSE, conf.level = 0.95, ...) { |
| 36 |
check_ellipses("exponentiate", "tidy", "nlrq", ...) |
| 37 |
|
| 38 |
ret <- as_tidy_tibble( |
| 39 |
coef(summary(x)), |
| 40 |
new_names = c("estimate", "std.error", "statistic", "p.value") |
| 41 |
) |
| 42 |
|
| 43 |
if (conf.int) { |
| 44 |
x_summary <- summary(x) |
| 45 |
a <- (1 - conf.level) / 2 |
| 46 |
cv <- qt(c(a, 1 - a), df = x_summary[["rdf"]]) |
| 47 |
ret[["conf.low"]] <- ret[["estimate"]] + (cv[1] * ret[["std.error"]]) |
| 48 |
ret[["conf.high"]] <- ret[["estimate"]] + (cv[2] * ret[["std.error"]]) |
| 49 |
} |
| 50 |
as_tibble(ret) |
| 51 |
} |
| 52 |
|
| 53 |
#' @templateVar class nlrq |
| 54 |
#' @template title_desc_glance |
| 55 |
#' |
| 56 |
#' @inherit tidy.nlrq params examples |
| 57 |
#' |
| 58 |
#' @evalRd return_glance( |
| 59 |
#' "tau", |
| 60 |
#' "logLik", |
| 61 |
#' "AIC", |
| 62 |
#' "BIC", |
| 63 |
#' "df.residual" |
| 64 |
#' ) |
| 65 |
#' |
| 66 |
#' @export |
| 67 |
#' @seealso [glance()], [quantreg::nlrq()] |
| 68 |
#' @family quantreg tidiers |
| 69 |
#' @inherit tidy.nlrq examples |
| 70 |
glance.nlrq <- function(x, ...) { |
| 71 |
n <- length(x[["m"]]$fitted()) |
| 72 |
s <- summary(x) |
| 73 |
|
| 74 |
as_glance_tibble( |
| 75 |
tau = x[["m"]]$tau(), |
| 76 |
logLik = logLik(x), |
| 77 |
AIC = AIC(x), |
| 78 |
BIC = AIC(x, k = log(n)), |
| 79 |
df.residual = s[["rdf"]], |
| 80 |
na_types = "rrrri" |
| 81 |
) |
| 82 |
} |
| 83 |
|
| 84 |
#' @templateVar class nlrq |
| 85 |
#' @template title_desc_tidy |
| 86 |
#' |
| 87 |
#' @param x A `nlrq` object returned from [quantreg::nlrq()]. |
| 88 |
#' @inherit augment.nls params examples return |
| 89 |
#' |
| 90 |
#' @export |
| 91 |
#' @seealso [augment()], [quantreg::nlrq()] |
| 92 |
#' @family quantreg tidiers |
| 93 |
#' @include stats-nls.R |
| 94 |
#' |
| 95 |
augment.nlrq <- augment.nls |