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

Show fewer classes in docs when redundant #1044

Merged
merged 29 commits into from
Nov 19, 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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: parameters
Title: Processing of Model Parameters
Version: 0.23.0.10
Version: 0.23.0.11
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

* Added support for `anova()` from models of the *survey* package.

* Documentation was re-organized and clarified, and the index reduced by removing
redundant class-documentation.

## Bug fixes

* Fixed bug when extracting 'pretty labels' for model parameters, which could
Expand Down
15 changes: 9 additions & 6 deletions R/1_model_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
#' - [Default method][model_parameters.default()]: `lm`, `glm`, **stats**, **censReg**,
#' **MASS**, **survey**, ...
#' - [Additive models][model_parameters.cgam()]: **bamlss**, **gamlss**, **mgcv**,
#' **scam**, **VGAM**, `Gam`, `gamm`, ...
#' - [ANOVA][model_parameters.aov()]: **afex**, `aov`, `anova`, ...
#' **scam**, **VGAM**, `Gam` (although the output of `Gam` is more Anova-alike),
#' `gamm`, ...
#' - [ANOVA][model_parameters.aov()]: **afex**, `aov`, `anova`, `Gam`, ...
#' - [Bayesian][model_parameters.stanreg()]: **BayesFactor**, **blavaan**, **brms**,
#' **MCMCglmm**, **posterior**, **rstanarm**, `bayesQR`, `bcplm`, `BGGM`, `blmrm`,
#' `blrm`, `mcmc.list`, `MCMCglmm`, ...
#' - [Clustering][model_parameters.kmeans()]: **hclust**, **kmeans**, **mclust**, **pam**, ...
#' - [Clustering][model_parameters.hclust()]: **hclust**, **kmeans**, **mclust**, **pam**, ...
#' - [Correlations, t-tests, etc.][model_parameters.htest()]: **lmtest**, `htest`,
#' `pairwise.htest`, ...
#' - [Meta-Analysis][model_parameters.rma()]: **metaBMA**, **metafor**, **metaplus**, ...
#' - [Mixed models][model_parameters.merMod()]: **cplm**, **glmmTMB**, **lme4**,
#' - [Mixed models][model_parameters.glmmTMB()]: **cplm**, **glmmTMB**, **lme4**,
#' **lmerTest**, **nlme**, **ordinal**, **robustlmm**, **spaMM**, `mixed`, `MixMod`, ...
#' - [Multinomial, ordinal and cumulative link][model_parameters.mlm()]: **brglm2**,
#' **DirichletReg**, **nnet**, **ordinal**, `mlm`, ...
Expand All @@ -28,13 +29,16 @@
#' **psych**, `sem`, ...
#' - [Zero-inflated and hurdle][model_parameters.zcpglm()]: **cplm**, **mhurdle**,
#' **pscl**, ...
#' - [Other models][model_parameters.averaging()]: **aod**, **bbmle**, **betareg**,
#' - [Other models][model_parameters.glimML()]: **aod**, **bbmle**, **betareg**,
#' **emmeans**, **epiR**, **ggeffects**, **glmx**, **ivfixed**, **ivprobit**,
#' **JRM**, **lmodel2**, **logitsf**, **marginaleffects**, **margins**, **maxLik**,
#' **mediation**, **mfx**, **multcomp**, **mvord**, **plm**, **PMCMRplus**,
#' **quantreg**, **selection**, **systemfit**, **tidymodels**, **varEST**,
#' **WRS2**, `bfsl`, `deltaMethod`, `fitdistr`, `mjoint`, `mle`, `model.avg`, ...
#'
#' A full overview can be found here:
#' https://easystats.github.io/parameters/reference/
#'
#' @param model Statistical Model.
#' @param ... Arguments passed to or from other methods. Non-documented
#' arguments are
Expand Down Expand Up @@ -180,7 +184,7 @@
#'
#' Compared to fixed effects (or single-level) models, determining appropriate
#' df for Wald-based inference in mixed models is more difficult.
#' See [the R GLMM FAQ](https://bbolker.github.io/mixedmodels-misc/glmmFAQ.html#what-are-the-p-values-listed-by-summaryglmerfit-etc.-are-they-reliable)

Check warning on line 187 in R/1_model_parameters.R

View workflow job for this annotation

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

file=R/1_model_parameters.R,line=187,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 151 characters.

Check warning on line 187 in R/1_model_parameters.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/1_model_parameters.R,line=187,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 151 characters.
#' for a discussion.
#'
#' Several approximate methods for computing df are available, but you should
Expand Down Expand Up @@ -757,7 +761,6 @@
#################### .glm ----------------------


#' @rdname model_parameters.default
#' @export
model_parameters.glm <- function(model,
ci = 0.95,
Expand Down
60 changes: 42 additions & 18 deletions R/2_ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,35 @@
#' @param x A statistical model.
#' @param ci Confidence Interval (CI) level. Default to `0.95` (`95%`).
#' @param dof Number of degrees of freedom to be used when calculating
#' confidence intervals. If `NULL` (default), the degrees of freedom are
#' retrieved by calling [`insight::get_df()`] with approximation method
#' defined in `method`. If not `NULL`, use this argument to override the
#' default degrees of freedom used to compute confidence intervals.
#' @param method Method for computing degrees of freedom for
#' confidence intervals (CI) and the related p-values. Allowed are following
#' options (which vary depending on the model class): `"residual"`,
#' `"normal"`, `"likelihood"`, `"satterthwaite"`, `"kenward"`, `"wald"`,
#' `"profile"`, `"boot"`, `"uniroot"`, `"ml1"`, `"betwithin"`, `"hdi"`,
#' `"quantile"`, `"ci"`, `"eti"`, `"si"`, `"bci"`, or `"bcai"`. See section
#' _Confidence intervals and approximation of degrees of freedom_ in
#' [`model_parameters()`] for further details.
#' confidence intervals. If `NULL` (default), the degrees of freedom are
#' retrieved by calling [`insight::get_df()`] with approximation method defined
#' in `method`. If not `NULL`, use this argument to override the default degrees
#' of freedom used to compute confidence intervals.
#' @param method Method for computing degrees of freedom for confidence
#' intervals (CI) and the related p-values. Allowed are following options (which
#' vary depending on the model class): `"residual"`, `"normal"`, `"likelihood"`,
#' `"satterthwaite"`, `"kenward"`, `"wald"`, `"profile"`, `"boot"`, `"uniroot"`,
#' `"ml1"`, `"betwithin"`, `"hdi"`, `"quantile"`, `"ci"`, `"eti"`, `"si"`,
#' `"bci"`, or `"bcai"`. See section _Confidence intervals and approximation of
#' degrees of freedom_ in [`model_parameters()`] for further details.
#' @param component Model component for which parameters should be shown. See
#' the documentation for your object's class in [`model_parameters()`] or
#' [`p_value()`] for further details.
#' the documentation for your object's class in [`model_parameters()`] or
#' [`p_value()`] for further details, or see section _Model components_.
#' @param iterations The number of bootstrap replicates. Only applies to models
#' of class `merMod` when `method=boot`.
#' of class `merMod` when `method=boot`.
#' @param verbose Toggle warnings and messages.
#' @param ... Additional arguments passed down to the underlying functions.
#' E.g., arguments like `vcov` or `vcov_args` can be used to compute confidence
#' intervals using a specific variance-covariance matrix for the standard
#' errors.
#' @inheritParams standard_error
#'
#' @return A data frame containing the CI bounds.
#'
#' @inheritSection model_parameters Confidence intervals and approximation of degrees of freedom
#'
#' @inheritSection model_parameters.zcpglm Model components
#'
#' @examplesIf require("glmmTMB") && requireNamespace("sandwich")
#' data(qol_cancer)
#' model <- lm(QoL ~ time + age + education, data = qol_cancer)
Expand All @@ -57,10 +59,29 @@
#' ci(model, component = "zi")
#' }
#' @export
ci.default <- function(x, ci = 0.95, dof = NULL, method = NULL, ...) {
ci.default <- function(x,
ci = 0.95,
dof = NULL,
method = NULL,
iterations = 500,
component = "all",
vcov = NULL,
vcov_args = NULL,
verbose = TRUE,
...) {
# check for valid input
.is_model_valid(x)
.ci_generic(model = x, ci = ci, dof = dof, method = method, ...)
.ci_generic(
model = x,
ci = ci,
dof = dof,
method = method,
component = component,
vcov = vcov,
vcov_args = vcov_args,
verbose = verbose,
...
)
}


Expand All @@ -73,7 +94,10 @@ ci.glm <- function(x,
vcov_args = NULL,
verbose = TRUE,
...) {
method <- insight::validate_argument(method, c("profile", "wald", "normal", "residual"))
method <- insight::validate_argument(
method,
c("profile", "wald", "normal", "residual")
)

# No robust vcov for profile method
if (method == "profile") {
Expand Down
23 changes: 17 additions & 6 deletions R/3_p_value.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
#' @name p_value
#'
#' @description This function attempts to return, or compute, p-values of a model's
#' parameters. See the documentation for your object's class:
#' - [Bayesian models][p_value.BFBayesFactor] (**rstanarm**, **brms**, **MCMCglmm**, ...)
#' - [Zero-inflated models][p_value.zeroinfl] (`hurdle`, `zeroinfl`, `zerocount`, ...)
#' - [Marginal effects models][p_value.poissonmfx] (**mfx**)
#' - [Models with special components][p_value.DirichletRegModel] (`DirichletRegModel`, `clm2`, `cgam`, ...)
#' parameters.
#'
#' @param model A statistical model.
#' @param adjust Character value naming the method used to adjust p-values or
Expand All @@ -17,14 +13,29 @@
#'
#' @inheritSection model_parameters Confidence intervals and approximation of degrees of freedom
#'
#' @inheritSection model_parameters.zcpglm Model components
#'
#' @details
#' For Bayesian models, the p-values corresponds to the *probability of
#' direction* ([`bayestestR::p_direction()`]), which is converted to a p-value
#' using `bayestestR::convert_pd_to_p()`.
#'
#' @return A data frame with at least two columns: the parameter names and the
#' p-values. Depending on the model, may also include columns for model
#' components etc.
#'
#' @examples
#' @examplesIf require("pscl", quietly = TRUE)
#' data(iris)
#' model <- lm(Petal.Length ~ Sepal.Length + Species, data = iris)
#' p_value(model)
#'
#' data("bioChemists", package = "pscl")
#' model <- pscl::zeroinfl(
#' art ~ fem + mar + kid5 | kid5 + phd,
#' data = bioChemists
#' )
#' p_value(model)
#' p_value(model, component = "zi")
#' @export
p_value <- function(model, ...) {
UseMethod("p_value")
Expand Down
10 changes: 6 additions & 4 deletions R/4_standard_error.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Standard Errors
#' @title Standard Errors
#' @name standard_error
#'
#' `standard_error()` attempts to return standard errors of model
#' @description `standard_error()` attempts to return standard errors of model
#' parameters.
#'
#' @param model A model.
Expand All @@ -21,8 +22,8 @@
#' - Cluster-robust: `"CR"`, `"CR0"`, `"CR1"`, `"CR1p"`, `"CR1S"`,
#' `"CR2"`, `"CR3"`. See `?clubSandwich::vcovCR`
#' - Bootstrap: `"BS"`, `"xy"`, `"residual"`, `"wild"`, `"mammen"`,
#' `"fractional"`, `"jackknife"`, `"norm"`, `"webb"`.
#' See `?sandwich::vcovBS`
#' `"fractional"`, `"jackknife"`, `"norm"`, `"webb"`. See
#' `?sandwich::vcovBS`
#' - Other `sandwich` package functions: `"HAC"`, `"PC"`, `"CL"`, `"OPG"`,
#' `"PL"`.
#' @param vcov_args List of arguments to be passed to the function identified by
Expand Down Expand Up @@ -75,6 +76,7 @@ standard_error <- function(model, ...) {
#' @rdname standard_error
#' @export
standard_error.default <- function(model,
effects = "fixed",
component = "all",
vcov = NULL,
vcov_args = NULL,
Expand Down
12 changes: 9 additions & 3 deletions R/5_simulate_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#' @inheritParams bootstrap_model
#' @inheritParams p_value
#'
#' @inheritSection model_parameters.zcpglm Model components
#'
#' @return A data frame.
#'
#' @seealso [`simulate_parameters()`], [`bootstrap_model()`], [`bootstrap_parameters()`]
Expand Down Expand Up @@ -57,9 +59,9 @@

# Models with single component only -----------------------------------------


#' @rdname simulate_model
#' @export
simulate_model.default <- function(model, iterations = 1000, ...) {
simulate_model.default <- function(model, iterations = 1000, component = "all", ...) {
# check for valid input
.is_model_valid(model)

Expand Down Expand Up @@ -229,7 +231,11 @@
# helper -----------------------------------------


.simulate_model <- function(model, iterations, component = "conditional", effects = "fixed", ...) {
.simulate_model <- function(model,
iterations,
component = "conditional",
effects = "fixed",
...) {
if (is.null(iterations)) iterations <- 1000

params <- insight::get_parameters(model, effects = effects, component = component, verbose = FALSE)
Expand All @@ -252,7 +258,7 @@
# }
}

.mvrnorm <- function(n = 1, mu, Sigma, tol = 1e-06) {

Check warning on line 261 in R/5_simulate_model.R

View workflow job for this annotation

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

file=R/5_simulate_model.R,line=261,col=29,[function_argument_linter] Arguments without defaults should come before arguments with defaults.

Check warning on line 261 in R/5_simulate_model.R

View workflow job for this annotation

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

file=R/5_simulate_model.R,line=261,col=33,[function_argument_linter] Arguments without defaults should come before arguments with defaults.

Check warning on line 261 in R/5_simulate_model.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/5_simulate_model.R,line=261,col=29,[function_argument_linter] Arguments without defaults should come before arguments with defaults.

Check warning on line 261 in R/5_simulate_model.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/5_simulate_model.R,line=261,col=33,[function_argument_linter] Arguments without defaults should come before arguments with defaults.
p <- length(mu)
if (!all(dim(Sigma) == c(p, p))) {
insight::format_error(
Expand Down
24 changes: 15 additions & 9 deletions R/bootstrap_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,21 @@ bootstrap_model <- function(model,
bootstrap_model.default <- function(model,
iterations = 1000,
type = "ordinary",
parallel = c("no", "multicore", "snow"),
parallel = "no",
n_cpus = 1,
cluster = NULL,
verbose = FALSE,
...) {
# check for valid input
.is_model_valid(model)

insight::check_if_installed("boot")

type <- insight::validate_argument(type, c("ordinary", "parametric", "balanced", "permutation", "antithetic"))
parallel <- match.arg(parallel)
type <- insight::validate_argument(
type,
c("ordinary", "parametric", "balanced", "permutation", "antithetic")
)
parallel <- insight::validate_argument(parallel, c("no", "multicore", "snow"))

model_data <- data <- insight::get_data(model, verbose = FALSE) # nolint
model_response <- insight::find_response(model)
Expand Down Expand Up @@ -144,20 +148,19 @@ bootstrap_model.default <- function(model,
}


#' @rdname bootstrap_model
#' @export
bootstrap_model.merMod <- function(model,
iterations = 1000,
type = "parametric",
parallel = c("no", "multicore", "snow"),
parallel = "no",
n_cpus = 1,
cluster = NULL,
verbose = FALSE,
...) {
insight::check_if_installed("lme4")

type <- insight::validate_argument(type, c("parametric", "semiparametric"))
parallel <- match.arg(parallel)
parallel <- insight::validate_argument(parallel, c("no", "multicore", "snow"))

boot_function <- function(model) {
params <- insight::get_parameters(model, verbose = FALSE)
Expand Down Expand Up @@ -222,14 +225,17 @@ bootstrap_model.glmmTMB <- bootstrap_model.merMod
bootstrap_model.nestedLogit <- function(model,
iterations = 1000,
type = "ordinary",
parallel = c("no", "multicore", "snow"),
parallel = "no",
n_cpus = 1,
verbose = FALSE,
...) {
insight::check_if_installed("boot")

type <- insight::validate_argument(type, c("ordinary", "balanced", "permutation", "antithetic"))
parallel <- match.arg(parallel)
type <- insight::validate_argument(
type,
c("ordinary", "balanced", "permutation", "antithetic")
)
parallel <- insight::validate_argument(parallel, c("no", "multicore", "snow"))

model_data <- data <- insight::get_data(model, verbose = FALSE) # nolint
model_response <- insight::find_response(model)
Expand Down
Loading
Loading