Skip to content

Commit

Permalink
Merge branch 'main' into dcchoice
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke authored Oct 24, 2023
2 parents 3ef1b78 + eb3900b commit b1f5212
Show file tree
Hide file tree
Showing 58 changed files with 392 additions and 165 deletions.
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 0.19.5
Date: 2023-09-13 07:09:16 UTC
SHA: 3ebd4e597e7a67ee0ed14bff617c5889b01767bb
Version: 0.19.6
Date: 2023-10-12 10:36:43 UTC
SHA: f2fbc4f7b48031b6359e0b815389c989cbf2976f
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: insight
Title: Easy Access to Model Information for Various Model Objects
Version: 0.19.5.13
Version: 0.19.6.3
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down Expand Up @@ -123,6 +123,7 @@ Suggests:
gee,
geepack,
geoR,
ggeffects,
GLMMadaptive,
glmmTMB,
gmnl,
Expand Down Expand Up @@ -206,3 +207,4 @@ Config/Needs/website:
rstudio/bslib,
r-lib/pkgdown,
easystats/easystatstemplate
Remotes: strengejacke/ggeffects
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ S3method(get_parameters,gam)
S3method(get_parameters,gamlss)
S3method(get_parameters,gamm)
S3method(get_parameters,gbm)
S3method(get_parameters,ggcomparisons)
S3method(get_parameters,glht)
S3method(get_parameters,glimML)
S3method(get_parameters,glmm)
Expand Down Expand Up @@ -816,6 +817,7 @@ S3method(get_statistic,gamm)
S3method(get_statistic,garch)
S3method(get_statistic,gee)
S3method(get_statistic,geeglm)
S3method(get_statistic,ggcomparisons)
S3method(get_statistic,glht)
S3method(get_statistic,glimML)
S3method(get_statistic,glmm)
Expand Down Expand Up @@ -1317,6 +1319,7 @@ S3method(model_info,gamlss)
S3method(model_info,gamm)
S3method(model_info,garch)
S3method(model_info,gbm)
S3method(model_info,ggcomparisons)
S3method(model_info,glht)
S3method(model_info,glimML)
S3method(model_info,glmm)
Expand Down
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# insight 0.19.7

## General

* Support for objects of class `ggcomparisons` from `ggeffects::hypothesis_test()`.

## Changes to functions

* `get_varcov()` for models of class `pgmm` (package *plm*) now also supported
robust variance-covariance matrices (i.e. argument `vcov`).

# insight 0.19.6

## General
Expand Down
6 changes: 3 additions & 3 deletions R/clean_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
#' The `Effects` column indicate if a parameter is a *fixed* or *random* effect.
#' The `Component` can either be *conditional* or *zero_inflated*. For models
#' with random effects, the `Group` column indicates the grouping factor of the
#' random effects. For multivariate response models from {brms} or
#' {rstanarm}, an additional *Response* column is included, to indicate
#' random effects. For multivariate response models from **brms** or
#' **rstanarm**, an additional *Response* column is included, to indicate
#' which parameters belong to which response formula. Furthermore,
#' *Cleaned_Parameter* column is returned that contains "human readable"
#' parameter names (which are mostly identical to `Parameter`, except for for
#' models from {brms} or {rstanarm}, or for specific terms like smooth-
#' models from **brms** or **rstanarm**, or for specific terms like smooth-
#' or spline-terms).
#'
#' @examplesIf require("curl", quietly = TRUE) && curl::has_internet() && require("brms")
Expand Down
4 changes: 2 additions & 2 deletions R/find_formula.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#' - `conditional`, the "fixed effects" part from the model (in the
#' context of fixed-effects or instrumental variable regression, also
#' called *regressors*) . One exception are `DirichletRegModel` models
#' from {DirichletReg}, which has two or three components,
#' from **DirichletReg**, which has two or three components,
#' depending on `model`.
#'
#' - `random`, the "random effects" part from the model (or the
Expand Down Expand Up @@ -49,7 +49,7 @@
#' `feisr::feis()`, the formula for the slope parameters
#'
#' - `precision`, for `DirichletRegModel` models from
#' {DirichletReg}, when parametrization (i.e. `model`) is
#' **DirichletReg**, when parametrization (i.e. `model`) is
#' `"alternative"`.
#'
#' @note For models of class `lme` or `gls` the correlation-component
Expand Down
14 changes: 7 additions & 7 deletions R/find_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
#' names equal the column names of the posterior samples after coercion
#' from `as.data.frame()`. See the documentation for your object's class:
#'
#' - [Bayesian models][find_parameters.BGGM] ({rstanarm}, {brms}, {MCMCglmm}, ...)
#' - [Generalized additive models][find_parameters.gamlss] ({mgcv}, {VGAM}, ...)
#' - [Marginal effects models][find_parameters.betamfx] ({mfx})
#' - [Estimated marginal means][find_parameters.emmGrid] ({emmeans})
#' - [Mixed models][find_parameters.glmmTMB] ({lme4}, {glmmTMB}, {GLMMadaptive}, ...)
#' - [Zero-inflated and hurdle models][find_parameters.zeroinfl] ({pscl}, ...)
#' - [Models with special components][find_parameters.averaging] ({betareg}, {MuMIn}, ...)
#' - [Bayesian models][find_parameters.BGGM] (**rstanarm**, **brms**, **MCMCglmm**, ...)
#' - [Generalized additive models][find_parameters.gamlss] (**mgcv**, **VGAM**, ...)
#' - [Marginal effects models][find_parameters.betamfx] (**mfx**)
#' - [Estimated marginal means][find_parameters.emmGrid] (**emmeans**)
#' - [Mixed models][find_parameters.glmmTMB] (**lme4**, **glmmTMB**, **GLMMadaptive**, ...)
#' - [Zero-inflated and hurdle models][find_parameters.zeroinfl] (**pscl**, ...)
#' - [Models with special components][find_parameters.averaging] (**betareg**, **MuMIn**, ...)
#'
#' @param verbose Toggle messages and warnings.
#' @param ... Currently not used.
Expand Down
8 changes: 4 additions & 4 deletions R/find_parameters_bayesian.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
#' component of the model
#' - `smooth_terms`, the smooth parameters
#'
#' Furthermore, some models, especially from {brms}, can also return auxiliary
#' Furthermore, some models, especially from **brms**, can also return auxiliary
#' parameters. These may be one of the following:
#'
#' - `sigma`, the residual standard deviation (auxiliary parameter)
#' - `dispersion`, the dispersion parameters (auxiliary parameter)
#' - `beta`, the beta parameter (auxiliary parameter)
#' - `simplex`, simplex parameters of monotonic effects (\pkg{brms} only)
#' - `mix`, mixture parameters (\pkg{brms} only)
#' - `shiftprop`, shifted proportion parameters (\pkg{brms} only)
#' - `simplex`, simplex parameters of monotonic effects (**brms** only)
#' - `mix`, mixture parameters (**brms** only)
#' - `shiftprop`, shifted proportion parameters (**brms** only)
#'
#' @examples
#' data(mtcars)
Expand Down
2 changes: 1 addition & 1 deletion R/find_parameters_mfx.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' term, the instrumental variables or marginal effects be returned? Applies
#' to models with zero-inflated and/or dispersion formula, or to models with
#' instrumental variables (so called fixed-effects regressions), or models
#' with marginal effects from \pkg{mfx}. May be abbreviated. Note that the
#' with marginal effects from **mfx**. May be abbreviated. Note that the
#' *conditional* component is also called *count* or *mean*
#' component, depending on the model. There are three convenient shortcuts:
#' `component = "all"` returns all possible parameters.
Expand Down
4 changes: 2 additions & 2 deletions R/find_statistic.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ find_statistic <- function(x, ...) {
"deltaMethod", "DirichletRegModel",
"ergm",
"feglm", "flexsurvreg",
"gee", "glimML", "glmm", "glmmadmb", "glmmFit", "glmmLasso", "glmmTMB",
"glmx", "gmnl",
"gee", "ggcomparisons", "glimML", "glmm", "glmmadmb", "glmmFit", "glmmLasso",
"glmmTMB", "glmx", "gmnl",
"hurdle",
"lavaan", "loggammacenslmrob", "logitmfx", "logitor", "logitr", "LORgee", "lrm",
"margins", "marginaleffects", "marginaleffects.summary", "metaplus", "mixor",
Expand Down
2 changes: 1 addition & 1 deletion R/format_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' converts all columns into character vectors!
#'
#' @param x A data frame of model's parameters, as returned by various functions
#' of the {easystats}-packages. May also be a result from
#' of the **easystats**-packages. May also be a result from
#' `broom::tidy()`.
#' @param pretty_names Return "pretty" (i.e. more human readable) parameter
#' names.
Expand Down
2 changes: 1 addition & 1 deletion R/get_auxiliary.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#' degrees of freedom. For models of class `glmmTMB`, dispersion is
#' \ifelse{html}{\out{&sigma;<sup>2</sup>}}{\eqn{\sigma^2}}.
#' }
#' \subsection{\pkg{brms} models}{
#' \subsection{**brms** models}{
#' For models of class `brmsfit`, there are different options for the
#' `type` argument. See a list of supported auxiliary parameters here:
#' [find_parameters.BGGM()].
Expand Down
6 changes: 3 additions & 3 deletions R/get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -2168,10 +2168,10 @@ get_data.rma <- function(x,
mf_attr[c("yi.names", "vi.names", "digits", "class")]
)
if (isTRUE(include_interval)) {
model_response <- tryCatch(mf[[find_response(x)]], error = function(x) NULL)
sei <- tryCatch(mf[[model_call$sei]], error = function(x) NULL)
model_response <- .safe(mf[[find_response(x)]])
sei <- .safe(mf[[model_call$sei]])
if (is.null(sei)) {
sei <- tryCatch(sqrt(mf[[model_call$vi]]), error = function(x) NULL)
sei <- .safe(sqrt(mf[[model_call$vi]]))
}
if (is.null(sei)) {
format_error("Could not find `sei` or `vi` for this model.")
Expand Down
2 changes: 1 addition & 1 deletion R/get_loglikelihood.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#' @return An object of class `"logLik"`, also containing the
#' log-likelihoods for each observation as a `per_observation` attribute
#' (`attributes(get_loglikelihood(x))$per_observation`) when possible.
#' The code was partly inspired from the {nonnest2} package.
#' The code was partly inspired from the **nonnest2** package.
#'
#' @examples
#' x <- lm(Sepal.Length ~ Petal.Width + Species, data = iris)
Expand Down
14 changes: 7 additions & 7 deletions R/get_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#' @description Returns the coefficients (or posterior samples for Bayesian
#' models) from a model. See the documentation for your object's class:
#'
#' - [Bayesian models][get_parameters.BGGM] ({rstanarm}, {brms}, {MCMCglmm}, ...)
#' - [Estimated marginal means][get_parameters.emmGrid] ({emmeans})
#' - [Generalized additive models][get_parameters.gamm] ({mgcv}, {VGAM}, ...)
#' - [Marginal effects models][get_parameters.betamfx] ({mfx})
#' - [Mixed models][get_parameters.glmm] ({lme4}, {glmmTMB}, {GLMMadaptive}, ...)
#' - [Zero-inflated and hurdle models][get_parameters.zeroinfl] ({pscl}, ...)
#' - [Models with special components][get_parameters.betareg] ({betareg}, {MuMIn}, ...)
#' - [Bayesian models][get_parameters.BGGM] (**rstanarm**, **brms**, **MCMCglmm**, ...)
#' - [Estimated marginal means][get_parameters.emmGrid] (**emmeans**)
#' - [Generalized additive models][get_parameters.gamm] (**mgcv**, **VGAM**, ...)
#' - [Marginal effects models][get_parameters.betamfx] (**mfx**)
#' - [Mixed models][get_parameters.glmm] (**lme4**, **glmmTMB**, **GLMMadaptive**, ...)
#' - [Zero-inflated and hurdle models][get_parameters.zeroinfl] (**pscl**, ...)
#' - [Models with special components][get_parameters.betareg] (**betareg**, **MuMIn**, ...)
#' - [Hypothesis tests][get_parameters.htest] (`htest`)
#'
#' @param verbose Toggle messages and warnings.
Expand Down
4 changes: 2 additions & 2 deletions R/get_parameters_bayesian.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#' `effects` and `component` can be used.
#'
#' @section BFBayesFactor Models:
#' Note that for `BFBayesFactor` models (from the \pkg{BayesFactor}
#' package), posteriors are only extracted from the first numerator model (i.e.,
#' Note that for `BFBayesFactor` models (from the **BayesFactor** package),
#' posteriors are only extracted from the first numerator model (i.e.,
#' `model[1]`). If you want to apply some function `foo()` to another
#' model stored in the `BFBayesFactor` object, index it directly, e.g.
#' `foo(model[2])`, `foo(1/model[5])`, etc.
Expand Down
2 changes: 1 addition & 1 deletion R/get_parameters_emmeans.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#'
#' @note
#' Note that `emmGrid` or `emm_list` objects returned by functions from
#' {emmeans} have a different structure compared to usual regression models.
#' **emmeans** have a different structure compared to usual regression models.
#' Hence, the `Parameter` column does not always contain names of *variables*,
#' but may rather contain *values*, e.g. for contrasts. See an example for
#' pairwise comparisons below.
Expand Down
2 changes: 1 addition & 1 deletion R/get_parameters_mixed.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' parameter names and the related point estimates. If `effects =
#' "random"`, a list of data frames with the random effects (as returned by
#' `ranef()`), unless the random effects have the same simplified
#' structure as fixed effects (e.g. for models from {MCMCglmm}).
#' structure as fixed effects (e.g. for models from **MCMCglmm**).
#'
#' @details In most cases when models either return different "effects" (fixed,
#' random) or "components" (conditional, zero-inflated, ...), the arguments
Expand Down
28 changes: 28 additions & 0 deletions R/get_parameters_others.R
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,31 @@ get_parameters.deltaMethod <- function(x, ...) {
row.names = NULL
)
}


#' @export
get_parameters.ggcomparisons <- function(x, merge_parameters = FALSE, ...) {
estimate_pos <- which(colnames(x) == attr(x, "estimate_name"))
params <- x[, seq_len(estimate_pos - 1), drop = FALSE]

if (isTRUE(merge_parameters) && ncol(params) > 1L) {
r <- apply(params, 1, function(i) paste0(colnames(params), " [", i, "]"))
out <- data.frame(
Parameter = unname(vapply(as.data.frame(r), toString, character(1))),
Estimate = x[[estimate_pos]],
stringsAsFactors = FALSE,
row.names = NULL
)
} else {
out <- data.frame(
params,
Estimate = x[[estimate_pos]],
stringsAsFactors = FALSE,
row.names = NULL
)
if (isTRUE(merge_parameters)) {
colnames(out)[1] <- "Parameter"
}
}
text_remove_backticks(out)
}
2 changes: 1 addition & 1 deletion R/get_predicted.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
#' + `NULL` uses the default method, which varies based on the model type.
#' + Most frequentist models: `"wald"` (default), `"residual"` or `"normal"`.
#' + Bayesian models: `"quantile"` (default), `"hdi"`, `"eti"`, and `"spi"`.
#' + Mixed effects {lme4} models: `"wald"` (default), `"residual"`, `"normal"`,
#' + Mixed effects **lme4** models: `"wald"` (default), `"residual"`, `"normal"`,
#' `"satterthwaite"`, and `"kenward-roger"`.
#'
#' See [`get_df()`] for details.
Expand Down
27 changes: 27 additions & 0 deletions R/get_statistic.R
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,33 @@ get_statistic.emm_list <- function(x, ci = 0.95, adjust = "none", ...) {
}


#' @export
get_statistic.ggcomparisons <- function(x, merge_parameters = FALSE, ...) {
estimate_pos <- which(colnames(x) == attr(x, "estimate_name"))
if (isTRUE(merge_parameters)) {
params <- get_parameters(x, merge_parameters = TRUE)["Parameter"]
} else {
params <- x[, seq_len(estimate_pos - 1), drop = FALSE]
}

stat <- .safe(x[[estimate_pos]] / attributes(x)$standard_error)
if (is.null(stat)) {
return(NULL)
}

out <- data.frame(
params,
Statistic = as.vector(stat),
stringsAsFactors = FALSE,
row.names = NULL
)

out <- text_remove_backticks(out)
attr(out, "statistic") <- find_statistic(x)
out
}


#' @export
get_statistic.robmixglm <- function(x, ...) {
cs <- stats::coef(summary(x))
Expand Down
27 changes: 22 additions & 5 deletions R/get_varcov.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
#' - Other `sandwich` package functions: `"vcovHAC"`, `"vcovPC"`, `"vcovCL"`,
#' `"vcovPL"`.
#' @param vcov_args List of arguments to be passed to the function identified by
#' the `vcov` argument. This function is typically supplied by the {sandwich}
#' or {clubSandwich} packages. Please refer to their documentation (e.g.,
#' the `vcov` argument. This function is typically supplied by the **sandwich**
#' or **clubSandwich** packages. Please refer to their documentation (e.g.,
#' `?sandwich::vcovHAC`) to see the list of available arguments. If no estimation
#' type (argument `type`) is given, the default type for `"HC"` (or `"vcovHC"`)
#' equals the default from the {sandwich} package; for type `"CR"` (or
#' equals the default from the **sandwich** package; for type `"CR"` (or
#' `"vcoCR"`), the default is set to `"CR3"`.
#' @param verbose Toggle warnings.
#' @param ... Currently not used.
Expand Down Expand Up @@ -295,10 +295,27 @@ get_varcov.glmx <- function(x,


#' @export
get_varcov.pgmm <- function(x, component = c("conditional", "all"), verbose = TRUE, ...) {
get_varcov.pgmm <- function(x,
component = c("conditional", "all"),
vcov = NULL,
vcov_args = NULL,
verbose = TRUE,
...) {
.check_get_varcov_dots(x, ...)
# process vcov-argument
vcov <- .check_vcov_args(x, vcov = vcov, verbose = verbose, ...)
component <- match.arg(component)
vc <- stats::vcov(x)

if (is.null(vcov)) {
vc <- suppressWarnings(stats::vcov(x))
} else {
vc <- .get_varcov_sandwich(x,
vcov_fun = vcov,
vcov_args = vcov_args,
verbose = FALSE,
...
)
}

if (component != "all") {
keep <- match(find_parameters(x)[[component]], rownames(vc))
Expand Down
4 changes: 2 additions & 2 deletions R/get_variances.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@
#' intercepts and slopes.
#'
#' @note This function supports models of class `merMod` (including models
#' from {blme}), `clmm`, `cpglmm`, `glmmadmb`, `glmmTMB`, `MixMod`, `lme`,
#' from **blme**), `clmm`, `cpglmm`, `glmmadmb`, `glmmTMB`, `MixMod`, `lme`,
#' `mixed`, `rlmerMod`, `stanreg`, `brmsfit` or `wbm`. Support for objects of
#' class `MixMod` ({GLMMadaptive}), `lme` ({nlme}) or `brmsfit` ({brms}) is
#' class `MixMod` (**GLMMadaptive**), `lme` (**nlme**) or `brmsfit` (**brms**) is
#' experimental and may not work for all models.
#'
#' @references
Expand Down
4 changes: 2 additions & 2 deletions R/insight-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#' to obtain model information and data, many package-specific modelling functions
#' do not provide such methods to allow users to access such valuable information.
#'
#' {insight} is an R-package that fills this important gap by providing a
#' **insight** is an R-package that fills this important gap by providing a
#' suite of functions to support almost any model (see a list of the many models
#' supported below in the **List of Supported Packages and Models** section).
#' The goal of {insight}, then, is to provide tools to provide *easy*,
#' The goal of **insight**, then, is to provide tools to provide *easy*,
#' *intuitive*, and *consistent* access to information contained in model
#' objects. These tools aid applied research in virtually any field who fit,
#' diagnose, and present statistical models by streamlining access to every
Expand Down
Loading

0 comments on commit b1f5212

Please sign in to comment.