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

Reduce methods appearing in docs, to make docs clearer #961

Merged
merged 10 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions R/find_parameter_zi.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@
#' - `conditional`, the "fixed effects" part from the model.
#' - `zero_inflated`, the "fixed effects" part from the zero-inflation
#' component of the model.
#' - Special models are `mhurdle`, which also can have the components
#' `infrequent_purchase`, `ip`, and `auxiliary`.
#'
#' @examples
#' data(mtcars)
#' m <- lm(mpg ~ wt + cyl + vs, data = mtcars)
#' find_parameters(m)
#' @export
find_parameters.zeroinfl <- function(x,
component = c("all", "conditional", "zi", "zero_inflated"),
flatten = FALSE,
...) {
find_parameters.zeroinfl <- function(x, component = "all", flatten = FALSE, ...) {
cf <- names(stats::coef(x))
component <- match.arg(component)
component <- validate_argument(component, c("all", "conditional", "zi", "zero_inflated"))

l <- compact_list(list(
conditional = cf[startsWith(cf, "count_")],
Expand All @@ -50,12 +49,9 @@ find_parameters.zerotrunc <- find_parameters.zeroinfl


#' @export
find_parameters.zcpglm <- function(x,
component = c("all", "conditional", "zi", "zero_inflated"),
flatten = FALSE,
...) {
find_parameters.zcpglm <- function(x, component = "all", flatten = FALSE, ...) {
cf <- stats::coef(x)
component <- match.arg(component)
component <- validate_argument(component, c("all", "conditional", "zi", "zero_inflated"))

l <- compact_list(list(
conditional = names(cf$tweedie),
Expand All @@ -72,15 +68,19 @@ find_parameters.zcpglm <- function(x,
}


#' @rdname find_parameters.zeroinfl
#' @export
find_parameters.mhurdle <- function(x,
component = c("all", "conditional", "zi", "zero_inflated", "infrequent_purchase", "ip", "auxiliary"),
flatten = FALSE,
...) {
component <- match.arg(component)
find_parameters.mhurdle <- function(x, component = "all", flatten = FALSE, ...) {
component <- validate_argument(
component,
c("all", "conditional", "zi", "zero_inflated", "infrequent_purchase", "ip", "auxiliary", "distributional")
)
cf <- stats::coef(x)

# handle alias
if (component == "distributional") {
component <- "auxiliary"
}

cond_pars <- which(startsWith(names(cf), "h2."))
zi_pars <- which(startsWith(names(cf), "h1."))
ip_pars <- which(startsWith(names(cf), "h3."))
Expand Down
16 changes: 4 additions & 12 deletions R/find_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,9 @@

# Panel models ----------------------------------------

#' @rdname find_parameters
#' @export
find_parameters.pgmm <- function(x,
component = c("conditional", "all"),
flatten = FALSE,
...) {
component <- match.arg(component)
find_parameters.pgmm <- function(x, component = "conditional", flatten = FALSE, ...) {
component <- validate_argument(component, c("conditional", "all"))
s <- summary(x, robust = FALSE)

l <- list(
Expand Down Expand Up @@ -807,13 +803,9 @@


## For questions or problems with this ask Fernando Miguez (femiguez@iastate.edu)
#' @rdname find_parameters
#' @export
find_parameters.nls <- function(x,
component = c("all", "conditional", "nonlinear"),
flatten = FALSE,
...) {
component <- match.arg(component)
find_parameters.nls <- function(x, component = "all", flatten = FALSE, ...) {
component <- validate_argument(component, c("all", "conditional", "nonlinear"))
f <- find_formula(x)
elements <- .get_elements(effects = "fixed", component = component)
f <- .prepare_predictors(x, f, elements)
Expand All @@ -830,7 +822,7 @@

# helper ----------------------------

.filter_parameters <- function(l, effects, component = "all", flatten, recursive = TRUE) {

Check warning on line 825 in R/find_parameters.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/find_parameters.R,line=825,col=63,[function_argument_linter] Arguments without defaults should come before arguments with defaults.
if (isTRUE(recursive)) {
# recursively remove back-ticks from all list-elements parameters
l <- rapply(l, text_remove_backticks, how = "list")
Expand Down
21 changes: 12 additions & 9 deletions R/find_parameters_bayesian.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@
#' - `mix`, mixture parameters (**brms** only)
#' - `shiftprop`, shifted proportion parameters (**brms** only)
#'
#' Models of class **BGGM** additionally can return the elements `correlation`
#' and `intercept`.
#'
#' Models of class **BFBayesFactor** additionally can return the element
#' `extra`.
#'
#' @examples
#' data(mtcars)
#' m <- lm(mpg ~ wt + cyl + vs, data = mtcars)
#' find_parameters(m)
#' @export
find_parameters.BGGM <- function(x,
component = c("correlation", "conditional", "intercept", "all"),
flatten = FALSE,
...) {
component <- match.arg(component)
find_parameters.BGGM <- function(x, component = "correlation", flatten = FALSE, ...) {
component <- validate_argument(component, c("correlation", "conditional", "intercept", "all"))
l <- switch(component,
correlation = list(correlation = colnames(get_parameters(x, component = "correlation"))),
conditional = list(conditional = colnames(get_parameters(x, component = "conditional"))),
Expand All @@ -71,16 +74,16 @@
#' @rdname find_parameters.BGGM
#' @export
find_parameters.BFBayesFactor <- function(x,
effects = c("all", "fixed", "random"),
component = c("all", "extra"),
effects = "all",
component = "all",
flatten = FALSE,
...) {
conditional <- NULL
random <- NULL
extra <- NULL

effects <- match.arg(effects)
component <- match.arg(component)
effects <- validate_argument(effects, c("all", "fixed", "random"))
component <- validate_argument(component, c("all", "extra"))

if (.classify_BFBayesFactor(x) == "correlation") {
conditional <- "rho"
Expand Down Expand Up @@ -429,7 +432,7 @@
#' @export
find_parameters.stanreg <- function(x,
effects = c("all", "fixed", "random"),
component = c("location", "all", "conditional", "smooth_terms", "sigma", "distributional", "auxiliary"),

Check warning on line 435 in R/find_parameters_bayesian.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/find_parameters_bayesian.R,line=435,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 140 characters.
flatten = FALSE,
parameters = NULL,
...) {
Expand Down Expand Up @@ -488,7 +491,7 @@
#' @export
find_parameters.stanmvreg <- function(x,
effects = c("all", "fixed", "random"),
component = c("location", "all", "conditional", "smooth_terms", "sigma", "distributional", "auxiliary"),

Check warning on line 494 in R/find_parameters_bayesian.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/find_parameters_bayesian.R,line=494,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 142 characters.
flatten = FALSE,
parameters = NULL,
...) {
Expand Down
36 changes: 10 additions & 26 deletions R/find_parameters_gam.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ find_parameters.gamlss <- function(x, flatten = FALSE, ...) {
}


#' @rdname find_parameters.gamlss
#' @export
find_parameters.gam <- function(x,
component = c("all", "conditional", "smooth_terms", "location"),
flatten = FALSE,
...) {
find_parameters.gam <- function(x, component = "all", flatten = FALSE, ...) {
pars <- list(conditional = names(stats::coef(x)))
pars$conditional <- text_remove_backticks(pars$conditional)

Expand All @@ -54,7 +50,7 @@ find_parameters.gam <- function(x,

pars <- compact_list(pars)

component <- match.arg(component)
component <- validate_argument(component, c("all", "conditional", "smooth_terms", "location"))
elements <- .get_elements(effects = "all", component = component)
pars <- compact_list(pars[elements])

Expand All @@ -70,12 +66,9 @@ find_parameters.scam <- find_parameters.gam


#' @export
find_parameters.Gam <- function(x,
component = c("all", "conditional", "smooth_terms", "location"),
flatten = FALSE,
...) {
find_parameters.Gam <- function(x, component = "all", flatten = FALSE, ...) {
pars <- names(stats::coef(x))
component <- match.arg(component)
component <- validate_argument(component, c("all", "conditional", "smooth_terms", "location"))

l <- compact_list(list(
conditional = pars[.grep_non_smoothers(pars)],
Expand All @@ -96,13 +89,10 @@ find_parameters.vgam <- find_parameters.Gam


#' @export
find_parameters.gamm <- function(x,
component = c("all", "conditional", "smooth_terms", "location"),
flatten = FALSE,
...) {
find_parameters.gamm <- function(x, component = "all", flatten = FALSE, ...) {
x <- x$gam
class(x) <- c(class(x), c("glm", "lm"))
component <- match.arg(component)
component <- validate_argument(component, c("all", "conditional", "smooth_terms", "location"))

l <- find_parameters.gam(x, component = component)

Expand All @@ -115,11 +105,8 @@ find_parameters.gamm <- function(x,


#' @export
find_parameters.cgam <- function(x,
component = c("all", "conditional", "smooth_terms", "location"),
flatten = FALSE,
...) {
component <- match.arg(component)
find_parameters.cgam <- function(x, component = "all", flatten = FALSE, ...) {
component <- validate_argument(component, c("all", "conditional", "smooth_terms", "location"))
sc <- summary(x)

estimates <- sc$coefficients
Expand Down Expand Up @@ -164,10 +151,7 @@ find_parameters.selection <- find_parameters.SemiParBIV


#' @export
find_parameters.rqss <- function(x,
component = c("all", "conditional", "smooth_terms", "location"),
flatten = FALSE,
...) {
find_parameters.rqss <- function(x, component = "all", flatten = FALSE, ...) {
sc <- summary(x)

pars <- list(
Expand All @@ -178,7 +162,7 @@ find_parameters.rqss <- function(x,
pars$conditional <- text_remove_backticks(pars$conditional)
pars$smooth_terms <- text_remove_backticks(pars$smooth_terms)

component <- match.arg(component)
component <- validate_argument(component, c("all", "conditional", "smooth_terms", "location"))
elements <- .get_elements(effects = "all", component)
pars <- compact_list(pars[elements])

Expand Down
30 changes: 15 additions & 15 deletions R/find_parameters_mfx.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,20 @@
#' m <- lm(mpg ~ wt + cyl + vs, data = mtcars)
#' find_parameters(m)
#' @export
find_parameters.betamfx <- function(x,
component = c("all", "conditional", "precision", "marginal", "location", "distributional", "auxiliary"),
flatten = FALSE,
...) {
find_parameters.betamfx <- function(x, component = "all", flatten = FALSE, ...) {
pars <- list(
marginal = text_remove_backticks(rownames(x$mfxest)),
conditional = text_remove_backticks(names(x$fit$coefficients$mean)),
precision = text_remove_backticks(names(x$fit$coefficients$precision))
)

component <- match.arg(component)
component <- validate_argument(
component,
c(
"all", "conditional", "precision", "marginal", "location",
"distributional", "auxiliary"
)
)
elements <- .get_elements(effects = "all", component = component)
pars <- compact_list(pars[elements])

Expand All @@ -58,16 +61,16 @@ find_parameters.betamfx <- function(x,


#' @export
find_parameters.betaor <- function(x,
component = c("all", "conditional", "precision", "location", "distributional", "auxiliary"),
flatten = FALSE,
...) {
find_parameters.betaor <- function(x, component = "all", flatten = FALSE, ...) {
pars <- list(
conditional = text_remove_backticks(names(x$fit$coefficients$mean)),
precision = text_remove_backticks(names(x$fit$coefficients$precision))
)

component <- match.arg(component)
component <- validate_argument(
component,
c("all", "conditional", "precision", "location", "distributional", "auxiliary")
)
elements <- .get_elements(effects = "all", component = component)
pars <- compact_list(pars[elements])

Expand All @@ -81,14 +84,11 @@ find_parameters.betaor <- function(x,

#' @rdname find_parameters.betamfx
#' @export
find_parameters.logitmfx <- function(x,
component = c("all", "conditional", "marginal", "location"),
flatten = FALSE,
...) {
find_parameters.logitmfx <- function(x, component = "all", flatten = FALSE, ...) {
p <- text_remove_backticks(names(stats::coef(x$fit)))
pars <- list(marginal = text_remove_backticks(rownames(x$mfxest)), conditional = p)

component <- match.arg(component)
component <- validate_argument(component, c("all", "conditional", "marginal", "location"))
elements <- .get_elements(effects = "all", component = component)
pars <- compact_list(pars[elements])

Expand Down
Loading
Loading