Skip to content

Commit

Permalink
Reduce methods appearing in docs, to make docs clearer (#961)
Browse files Browse the repository at this point in the history
* Don't show "usage" for all classes (make docs clearer)

* docs

* docs

* docs

* docs

* docs

* typo

* docs

* find_param
  • Loading branch information
strengejacke authored Nov 6, 2024
1 parent 911cb38 commit 05b9c3c
Show file tree
Hide file tree
Showing 30 changed files with 417 additions and 515 deletions.
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 @@ find_parameters.lavaan <- function(x, flatten = FALSE, ...) {

# 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 @@ find_parameters.mira <- function(x, flatten = FALSE, ...) {


## For questions or problems with this ask Fernando Miguez ([email protected])
#' @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 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 @@ find_parameters.BGGM <- function(x,
#' @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
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

0 comments on commit 05b9c3c

Please sign in to comment.