diff --git a/R/find_parameters_other.R b/R/find_parameters_other.R index 7d1e58919..219443d98 100644 --- a/R/find_parameters_other.R +++ b/R/find_parameters_other.R @@ -9,6 +9,8 @@ #' @inheritParams find_parameters.betamfx #' @inheritParams find_predictors #' +#' @inheritSection find_predictors Model components +#' #' @return A list of parameter names. The returned list may have following #' elements, usually requested via the `component` argument: #' @@ -18,10 +20,11 @@ #' - `survival` for model of class `mjoint`. #' - `extra` for models of class `glmx`. #' -#' @examples -#' data(mtcars) -#' m <- lm(mpg ~ wt + cyl + vs, data = mtcars) +#' @examplesIf requireNamespace("betareg", quietly = TRUE) +#' data("GasolineYield", package = "betareg") +#' m <- betareg::betareg(yield ~ batch + temp, data = GasolineYield) #' find_parameters(m) +#' find_parameters(m, component = "precision") #' @export find_parameters.averaging <- function(x, component = "conditional", flatten = FALSE, ...) { component <- validate_argument(component, c("conditional", "full")) diff --git a/R/find_predictors.R b/R/find_predictors.R index 49933e715..263b8ab22 100644 --- a/R/find_predictors.R +++ b/R/find_predictors.R @@ -56,6 +56,9 @@ #' - **averaging**:`"conditional"` and `"full"` #' - **mjoint**: `"survival"` #' - **mfx**: `"precision"`, `"marginal"` +#' - **betareg**, **DirichletRegModel**: `"precision"` +#' - **mvord**: `"thresholds"` and `"correlation"` +#' - **clm2**: `"scale"` #' #' For models of class `brmsfit` (package **brms**), `component`, even more #' options are possible for the `component` argument, which are not all diff --git a/R/get_parameters_others.R b/R/get_parameters_others.R index 6cb836e94..27c36613c 100644 --- a/R/get_parameters_others.R +++ b/R/get_parameters_others.R @@ -13,15 +13,17 @@ #' @return A data frame with three columns: the parameter names, the related #' point estimates and the component. #' -#' @examples -#' data(mtcars) -#' m <- lm(mpg ~ wt + cyl + vs, data = mtcars) +#' @examplesIf requireNamespace("betareg", quietly = TRUE) +#' data("GasolineYield", package = "betareg") +#' m <- betareg::betareg(yield ~ batch + temp, data = GasolineYield) #' get_parameters(m) +#' get_parameters(m, component = "precision") #' @export -get_parameters.betareg <- function(x, - component = c("all", "conditional", "precision", "location", "distributional", "auxiliary"), - ...) { - component <- match.arg(component) +get_parameters.betareg <- function(x, component = "all", ...) { + component <- validate_argument( + component, + c("all", "conditional", "precision", "location", "distributional", "auxiliary") + ) cf <- stats::coef(x) params <- data.frame( @@ -40,10 +42,9 @@ get_parameters.betareg <- function(x, } -#' @rdname get_parameters.betareg #' @export -get_parameters.glmgee <- function(x, component = c("all", "conditional", "dispersion"), ...) { - component <- match.arg(component) +get_parameters.glmgee <- function(x, component = "all", ...) { + component <- validate_argument(component, c("all", "conditional", "dispersion")) junk <- utils::capture.output({ cs <- suppressWarnings(stats::coef(summary(x, corr = FALSE))) @@ -99,12 +100,12 @@ get_parameters.nestedLogit <- function(x, component = "all", verbose = TRUE, ... } -#' @rdname get_parameters.betareg #' @export -get_parameters.DirichletRegModel <- function(x, - component = c("all", "conditional", "precision", "location", "distributional", "auxiliary"), - ...) { - component <- match.arg(component) +get_parameters.DirichletRegModel <- function(x, component = "all", ...) { + component <- validate_argument( + component, + c("all", "conditional", "precision", "location", "distributional", "auxiliary") + ) cf <- stats::coef(x) if (x$parametrization == "common") { @@ -139,12 +140,9 @@ get_parameters.DirichletRegModel <- function(x, } -#' @rdname get_parameters.betareg #' @export -get_parameters.averaging <- function(x, - component = c("conditional", "full"), - ...) { - component <- match.arg(component) +get_parameters.averaging <- function(x, component = "conditional", ...) { + component <- validate_argument(component, c("conditional", "full")) cf <- stats::coef(x, full = component == "full") params <- data.frame( @@ -158,12 +156,12 @@ get_parameters.averaging <- function(x, } -#' @rdname get_parameters.betareg #' @export -get_parameters.glmx <- function(x, - component = c("all", "conditional", "extra", "location", "distributional", "auxiliary"), - ...) { - component <- match.arg(component) +get_parameters.glmx <- function(x, component = "all", ...) { + component <- validate_argument( + component, + c("all", "conditional", "extra", "location", "distributional", "auxiliary") + ) cf <- stats::coef(summary(x)) params <- rbind( @@ -191,12 +189,9 @@ get_parameters.glmx <- function(x, } -#' @rdname get_parameters.betareg #' @export -get_parameters.clm2 <- function(x, - component = c("all", "conditional", "scale"), - ...) { - component <- match.arg(component) +get_parameters.clm2 <- function(x, component = "all", ...) { + component <- validate_argument(component,c("all", "conditional", "scale")) cf <- stats::coef(summary(x)) n_intercepts <- length(x$xi) @@ -223,12 +218,12 @@ get_parameters.clm2 <- function(x, get_parameters.clmm2 <- get_parameters.clm2 -#' @rdname get_parameters.betareg #' @export -get_parameters.mvord <- function(x, - component = c("all", "conditional", "thresholds", "correlation"), - ...) { - component <- match.arg(component) +get_parameters.mvord <- function(x, component = "all", ...) { + component <- validate_argument( + component, + c("all", "conditional", "thresholds", "correlation") + ) junk <- utils::capture.output(s <- summary(x)) # nolint # intercepts thresholds thresholds <- as.data.frame(s$thresholds) @@ -278,13 +273,9 @@ get_parameters.mvord <- function(x, } - -#' @rdname get_parameters.betareg #' @export -get_parameters.mjoint <- function(x, - component = c("all", "conditional", "survival"), - ...) { - component <- match.arg(component) +get_parameters.mjoint <- function(x, component = "all", ...) { + component <- validate_argument(component, c("all", "conditional", "survival")) s <- summary(x) params <- rbind( @@ -312,7 +303,6 @@ get_parameters.mjoint <- function(x, } - #' @export get_parameters.systemfit <- function(x, ...) { cf <- stats::coef(summary(x)) @@ -335,6 +325,7 @@ get_parameters.systemfit <- function(x, ...) { do.call(rbind, out) } + #' @export get_parameters.marginaleffects <- function(x, summary = FALSE, merge_parameters = FALSE, ...) { # check if we have a Bayesian model here diff --git a/man/find_parameters.Rd b/man/find_parameters.Rd index 7494b3e63..e7b9415d7 100644 --- a/man/find_parameters.Rd +++ b/man/find_parameters.Rd @@ -77,6 +77,9 @@ Some model classes also allow rather uncommon options. These are: \item \strong{averaging}:\code{"conditional"} and \code{"full"} \item \strong{mjoint}: \code{"survival"} \item \strong{mfx}: \code{"precision"}, \code{"marginal"} +\item \strong{betareg}, \strong{DirichletRegModel}: \code{"precision"} +\item \strong{mvord}: \code{"thresholds"} and \code{"correlation"} +\item \strong{clm2}: \code{"scale"} } For models of class \code{brmsfit} (package \strong{brms}), \code{component}, even more diff --git a/man/find_parameters.averaging.Rd b/man/find_parameters.averaging.Rd index 43f1031c5..61a2808ec 100644 --- a/man/find_parameters.averaging.Rd +++ b/man/find_parameters.averaging.Rd @@ -49,8 +49,60 @@ elements, usually requested via the \code{component} argument: Returns the names of model parameters, like they typically appear in the \code{summary()} output. } +\section{Model components}{ + +Possible values for the \code{component} argument depend on the model class. +Following are valid options: +\itemize{ +\item \code{"all"}: returns all model components, applies to all models, but will only +have an effect for models with more than just the conditional model component. +\item \code{"conditional"}: only returns the conditional component, i.e. "fixed effects" +terms from the model. Will only have an effect for models with more than +just the conditional model component. +\item \code{"smooth_terms"}: returns smooth terms, only applies to GAMs (or similar +models that may contain smooth terms). +\item \code{"zero_inflated"} (or \code{"zi"}): returns the zero-inflation component. +\item \code{"dispersion"}: returns the dispersion model component. This is common +for models with zero-inflation or that can model the dispersion parameter. +\item \code{"instruments"}: for instrumental-variable or some fixed effects regression, +returns the instruments. +\item \code{"nonlinear"}: for non-linear models (like models of class \code{nlmerMod} or +\code{nls}), returns staring estimates for the nonlinear parameters. +\item \code{"correlation"}: for models with correlation-component, like \code{gls}, the +variables used to describe the correlation structure are returned. +\item \code{"location"}: returns location parameters such as \code{conditional}, +\code{zero_inflated}, \code{smooth_terms}, or \code{instruments} (everything that are +fixed or random effects - depending on the \code{effects} argument - but no +auxiliary parameters). +\item \code{"distributional"} (or \code{"auxiliary"}): components like \code{sigma}, \code{dispersion}, +\code{beta} or \code{precision} (and other auxiliary parameters) are returned. +} + +\strong{Special models} + +Some model classes also allow rather uncommon options. These are: +\itemize{ +\item \strong{mhurdle}: \code{"infrequent_purchase"}, \code{"ip"}, and \code{"auxiliary"} +\item \strong{BGGM}: \code{"correlation"} and \code{"intercept"} +\item \strong{BFBayesFactor}, \strong{glmx}: \code{"extra"} +\item \strong{averaging}:\code{"conditional"} and \code{"full"} +\item \strong{mjoint}: \code{"survival"} +\item \strong{mfx}: \code{"precision"}, \code{"marginal"} +\item \strong{betareg}, \strong{DirichletRegModel}: \code{"precision"} +\item \strong{mvord}: \code{"thresholds"} and \code{"correlation"} +\item \strong{clm2}: \code{"scale"} +} + +For models of class \code{brmsfit} (package \strong{brms}), \code{component}, even more +options are possible for the \code{component} argument, which are not all +documented in detail here. +} + \examples{ -data(mtcars) -m <- lm(mpg ~ wt + cyl + vs, data = mtcars) +\dontshow{if (requireNamespace("betareg", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +data("GasolineYield", package = "betareg") +m <- betareg::betareg(yield ~ batch + temp, data = GasolineYield) find_parameters(m) +find_parameters(m, component = "precision") +\dontshow{\}) # examplesIf} } diff --git a/man/find_parameters.betamfx.Rd b/man/find_parameters.betamfx.Rd index 2f2a82823..de51a1905 100644 --- a/man/find_parameters.betamfx.Rd +++ b/man/find_parameters.betamfx.Rd @@ -89,6 +89,9 @@ Some model classes also allow rather uncommon options. These are: \item \strong{averaging}:\code{"conditional"} and \code{"full"} \item \strong{mjoint}: \code{"survival"} \item \strong{mfx}: \code{"precision"}, \code{"marginal"} +\item \strong{betareg}, \strong{DirichletRegModel}: \code{"precision"} +\item \strong{mvord}: \code{"thresholds"} and \code{"correlation"} +\item \strong{clm2}: \code{"scale"} } For models of class \code{brmsfit} (package \strong{brms}), \code{component}, even more diff --git a/man/find_parameters.glmmTMB.Rd b/man/find_parameters.glmmTMB.Rd index f880da002..129d70bd9 100644 --- a/man/find_parameters.glmmTMB.Rd +++ b/man/find_parameters.glmmTMB.Rd @@ -92,6 +92,9 @@ Some model classes also allow rather uncommon options. These are: \item \strong{averaging}:\code{"conditional"} and \code{"full"} \item \strong{mjoint}: \code{"survival"} \item \strong{mfx}: \code{"precision"}, \code{"marginal"} +\item \strong{betareg}, \strong{DirichletRegModel}: \code{"precision"} +\item \strong{mvord}: \code{"thresholds"} and \code{"correlation"} +\item \strong{clm2}: \code{"scale"} } For models of class \code{brmsfit} (package \strong{brms}), \code{component}, even more diff --git a/man/find_parameters.zeroinfl.Rd b/man/find_parameters.zeroinfl.Rd index 37520a191..5021af56f 100644 --- a/man/find_parameters.zeroinfl.Rd +++ b/man/find_parameters.zeroinfl.Rd @@ -88,6 +88,9 @@ Some model classes also allow rather uncommon options. These are: \item \strong{averaging}:\code{"conditional"} and \code{"full"} \item \strong{mjoint}: \code{"survival"} \item \strong{mfx}: \code{"precision"}, \code{"marginal"} +\item \strong{betareg}, \strong{DirichletRegModel}: \code{"precision"} +\item \strong{mvord}: \code{"thresholds"} and \code{"correlation"} +\item \strong{clm2}: \code{"scale"} } For models of class \code{brmsfit} (package \strong{brms}), \code{component}, even more diff --git a/man/find_predictors.Rd b/man/find_predictors.Rd index d5a74fb2e..8081b9157 100644 --- a/man/find_predictors.Rd +++ b/man/find_predictors.Rd @@ -104,6 +104,9 @@ Some model classes also allow rather uncommon options. These are: \item \strong{averaging}:\code{"conditional"} and \code{"full"} \item \strong{mjoint}: \code{"survival"} \item \strong{mfx}: \code{"precision"}, \code{"marginal"} +\item \strong{betareg}, \strong{DirichletRegModel}: \code{"precision"} +\item \strong{mvord}: \code{"thresholds"} and \code{"correlation"} +\item \strong{clm2}: \code{"scale"} } For models of class \code{brmsfit} (package \strong{brms}), \code{component}, even more diff --git a/man/find_variables.Rd b/man/find_variables.Rd index 0101bd37b..31963937f 100644 --- a/man/find_variables.Rd +++ b/man/find_variables.Rd @@ -96,6 +96,9 @@ Some model classes also allow rather uncommon options. These are: \item \strong{averaging}:\code{"conditional"} and \code{"full"} \item \strong{mjoint}: \code{"survival"} \item \strong{mfx}: \code{"precision"}, \code{"marginal"} +\item \strong{betareg}, \strong{DirichletRegModel}: \code{"precision"} +\item \strong{mvord}: \code{"thresholds"} and \code{"correlation"} +\item \strong{clm2}: \code{"scale"} } For models of class \code{brmsfit} (package \strong{brms}), \code{component}, even more diff --git a/man/get_data.Rd b/man/get_data.Rd index 98c7005f7..e1ac3d0da 100644 --- a/man/get_data.Rd +++ b/man/get_data.Rd @@ -130,6 +130,9 @@ Some model classes also allow rather uncommon options. These are: \item \strong{averaging}:\code{"conditional"} and \code{"full"} \item \strong{mjoint}: \code{"survival"} \item \strong{mfx}: \code{"precision"}, \code{"marginal"} +\item \strong{betareg}, \strong{DirichletRegModel}: \code{"precision"} +\item \strong{mvord}: \code{"thresholds"} and \code{"correlation"} +\item \strong{clm2}: \code{"scale"} } For models of class \code{brmsfit} (package \strong{brms}), \code{component}, even more diff --git a/man/get_parameters.BGGM.Rd b/man/get_parameters.BGGM.Rd index 21fc660c7..e9b1cdf5e 100644 --- a/man/get_parameters.BGGM.Rd +++ b/man/get_parameters.BGGM.Rd @@ -148,6 +148,9 @@ Some model classes also allow rather uncommon options. These are: \item \strong{averaging}:\code{"conditional"} and \code{"full"} \item \strong{mjoint}: \code{"survival"} \item \strong{mfx}: \code{"precision"}, \code{"marginal"} +\item \strong{betareg}, \strong{DirichletRegModel}: \code{"precision"} +\item \strong{mvord}: \code{"thresholds"} and \code{"correlation"} +\item \strong{clm2}: \code{"scale"} } For models of class \code{brmsfit} (package \strong{brms}), \code{component}, even more diff --git a/man/get_parameters.Rd b/man/get_parameters.Rd index 77699854e..5371bc0eb 100644 --- a/man/get_parameters.Rd +++ b/man/get_parameters.Rd @@ -87,6 +87,9 @@ Some model classes also allow rather uncommon options. These are: \item \strong{averaging}:\code{"conditional"} and \code{"full"} \item \strong{mjoint}: \code{"survival"} \item \strong{mfx}: \code{"precision"}, \code{"marginal"} +\item \strong{betareg}, \strong{DirichletRegModel}: \code{"precision"} +\item \strong{mvord}: \code{"thresholds"} and \code{"correlation"} +\item \strong{clm2}: \code{"scale"} } For models of class \code{brmsfit} (package \strong{brms}), \code{component}, even more diff --git a/man/get_parameters.betamfx.Rd b/man/get_parameters.betamfx.Rd index b14fb5acd..e3a4476b9 100644 --- a/man/get_parameters.betamfx.Rd +++ b/man/get_parameters.betamfx.Rd @@ -71,6 +71,9 @@ Some model classes also allow rather uncommon options. These are: \item \strong{averaging}:\code{"conditional"} and \code{"full"} \item \strong{mjoint}: \code{"survival"} \item \strong{mfx}: \code{"precision"}, \code{"marginal"} +\item \strong{betareg}, \strong{DirichletRegModel}: \code{"precision"} +\item \strong{mvord}: \code{"thresholds"} and \code{"correlation"} +\item \strong{clm2}: \code{"scale"} } For models of class \code{brmsfit} (package \strong{brms}), \code{component}, even more diff --git a/man/get_parameters.betareg.Rd b/man/get_parameters.betareg.Rd index 4a5bbd594..16e6a8aa0 100644 --- a/man/get_parameters.betareg.Rd +++ b/man/get_parameters.betareg.Rd @@ -2,48 +2,9 @@ % Please edit documentation in R/get_parameters_others.R \name{get_parameters.betareg} \alias{get_parameters.betareg} -\alias{get_parameters.glmgee} -\alias{get_parameters.DirichletRegModel} -\alias{get_parameters.averaging} -\alias{get_parameters.glmx} -\alias{get_parameters.clm2} -\alias{get_parameters.mvord} -\alias{get_parameters.mjoint} \title{Get model parameters from models with special components} \usage{ -\method{get_parameters}{betareg}( - x, - component = c("all", "conditional", "precision", "location", "distributional", - "auxiliary"), - ... -) - -\method{get_parameters}{glmgee}(x, component = c("all", "conditional", "dispersion"), ...) - -\method{get_parameters}{DirichletRegModel}( - x, - component = c("all", "conditional", "precision", "location", "distributional", - "auxiliary"), - ... -) - -\method{get_parameters}{averaging}(x, component = c("conditional", "full"), ...) - -\method{get_parameters}{glmx}( - x, - component = c("all", "conditional", "extra", "location", "distributional", "auxiliary"), - ... -) - -\method{get_parameters}{clm2}(x, component = c("all", "conditional", "scale"), ...) - -\method{get_parameters}{mvord}( - x, - component = c("all", "conditional", "thresholds", "correlation"), - ... -) - -\method{get_parameters}{mjoint}(x, component = c("all", "conditional", "survival"), ...) +\method{get_parameters}{betareg}(x, component = "all", ...) } \arguments{ \item{x}{A fitted model.} @@ -103,6 +64,9 @@ Some model classes also allow rather uncommon options. These are: \item \strong{averaging}:\code{"conditional"} and \code{"full"} \item \strong{mjoint}: \code{"survival"} \item \strong{mfx}: \code{"precision"}, \code{"marginal"} +\item \strong{betareg}, \strong{DirichletRegModel}: \code{"precision"} +\item \strong{mvord}: \code{"thresholds"} and \code{"correlation"} +\item \strong{clm2}: \code{"scale"} } For models of class \code{brmsfit} (package \strong{brms}), \code{component}, even more @@ -111,7 +75,10 @@ documented in detail here. } \examples{ -data(mtcars) -m <- lm(mpg ~ wt + cyl + vs, data = mtcars) +\dontshow{if (requireNamespace("betareg", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +data("GasolineYield", package = "betareg") +m <- betareg::betareg(yield ~ batch + temp, data = GasolineYield) get_parameters(m) +get_parameters(m, component = "precision") +\dontshow{\}) # examplesIf} } diff --git a/man/get_parameters.gamm.Rd b/man/get_parameters.gamm.Rd index 7e6cecc67..dbcdecd73 100644 --- a/man/get_parameters.gamm.Rd +++ b/man/get_parameters.gamm.Rd @@ -79,6 +79,9 @@ Some model classes also allow rather uncommon options. These are: \item \strong{averaging}:\code{"conditional"} and \code{"full"} \item \strong{mjoint}: \code{"survival"} \item \strong{mfx}: \code{"precision"}, \code{"marginal"} +\item \strong{betareg}, \strong{DirichletRegModel}: \code{"precision"} +\item \strong{mvord}: \code{"thresholds"} and \code{"correlation"} +\item \strong{clm2}: \code{"scale"} } For models of class \code{brmsfit} (package \strong{brms}), \code{component}, even more diff --git a/man/get_parameters.glmmTMB.Rd b/man/get_parameters.glmmTMB.Rd index d4c60234c..2624033b1 100644 --- a/man/get_parameters.glmmTMB.Rd +++ b/man/get_parameters.glmmTMB.Rd @@ -83,6 +83,9 @@ Some model classes also allow rather uncommon options. These are: \item \strong{averaging}:\code{"conditional"} and \code{"full"} \item \strong{mjoint}: \code{"survival"} \item \strong{mfx}: \code{"precision"}, \code{"marginal"} +\item \strong{betareg}, \strong{DirichletRegModel}: \code{"precision"} +\item \strong{mvord}: \code{"thresholds"} and \code{"correlation"} +\item \strong{clm2}: \code{"scale"} } For models of class \code{brmsfit} (package \strong{brms}), \code{component}, even more diff --git a/man/get_parameters.zeroinfl.Rd b/man/get_parameters.zeroinfl.Rd index 709f59dcb..64d2a36d7 100644 --- a/man/get_parameters.zeroinfl.Rd +++ b/man/get_parameters.zeroinfl.Rd @@ -65,6 +65,9 @@ Some model classes also allow rather uncommon options. These are: \item \strong{averaging}:\code{"conditional"} and \code{"full"} \item \strong{mjoint}: \code{"survival"} \item \strong{mfx}: \code{"precision"}, \code{"marginal"} +\item \strong{betareg}, \strong{DirichletRegModel}: \code{"precision"} +\item \strong{mvord}: \code{"thresholds"} and \code{"correlation"} +\item \strong{clm2}: \code{"scale"} } For models of class \code{brmsfit} (package \strong{brms}), \code{component}, even more