Easy Access to Model Information for Various Model Objects

A tool to provide an easy, intuitive and consistent access to information contained in various R models, like model formulas, model terms, information about random effects, data that was used to fit the model or data from response variables. 'insight' mainly revolves around two types of functions: Functions that find (the names of) information, starting with 'find_', and functions that get the underlying data, starting with 'get_'. The package has a consistent syntax and works with many different model objects, where otherwise functions to access these information are missing.


CRAN_Status_Badge Documentation Build Status codecov downloads total

Gain insight into your models!

The goal of insight is to provide tools to help an easy, intuitive and consistent accesss to information contained in various models, like model formulas, model terms, information about random effects, data that was used to fit the model or data from response variables. Although there are generic functions to get information and data from models, many modelling-functions from different packages do not provide such methods to access these information. The insight package aims at closing this gap by providing functions that work for (almost) any model.

Installation

Run the following to install the latest GitHub-version of insight:

install.packages("devtools")
devtools::install_github("easystats/insight")

Or install the latest stable release from CRAN:

install.packages("insight")

Documentation and Support

Please visit https://easystats.github.io/insight/ for documentation. In case you want to file an issue or contribute in another way to the package, please follow this guide. For questions about the functionality, you may either contact me via email or also file an issue.

Functions

The syntax of insight mainly revolves around two types of functions. One is to find the names of the things (find_*), and the second is to actually get the things (get_). The things can be the following:

On top of that, the model_info() function runs many checks to help you classify and understand the nature of your model.

List of Supported Packages and Models

AER (ivreg, tobit), afex (mixed), base (aov, aovlist, lm, glm), BayesFactor (BFBayesFactor), betareg (betareg), biglm (biglm, bigglm), blme (blmer, bglmer), brms (brmsfit), censReg, crch, countreg (zerontrunc), coxme, estimatr (lm_robust, iv_robust), feisr (feis), gam (Gam), gamm4 , gamlss, gbm, gee, geepack (geeglm), GLMMadaptive (MixMod), glmmTMB (glmmTMB), gmnl, lfe (felm), lme4 (lmer, glmer, nlmer, glmer.nb), MASS (glmmPQL, polr), mgcv (gam, gamm), multgee (LORgee), nnet (multinom), nlme (lme, gls), ordinal (clm, clm2, clmm), plm, pscl (zeroinf, hurdle), quantreg (rq, crq, rqss), rms (lsr, ols, psm), robust (glmRob, lmRob), robustbase (glmrob, lmrob), robustlmm (rlmer), rstanarm (stanreg, stanmvreg), speedlm (speedlm, speedglm), survey, survival (coxph, survreg), truncreg (truncreg), VGAM (vgam, vglm)

  • Didn't find a model? File an issue and request additional model-support in insight!

Credits

If this package helped you, please consider citing as follows:

News

insight 0.3.0

New supported model classes

  • biglm and bigglm (biglm), feis (feisr), gbm (gbm), BFBayesFactor (BayesFactor), psm (rms), LORgee (multgee), censReg (censReg), ols (rms), speedlm and speedglm (speedglm), svyolr (survey)

New functions

  • is_nullmodel() to check if model is a null-model (intercept-only), i.e. if the conditional part of the model has no predictors.
  • has_intercept() to check if model has an intercept.

Breaking Changes

  • Functions like find_predictors() or find_terms() return NULL for null-models (intercept-only models). Use is_nullmodel() to check if your model only has an intercept-parameter (but no predictors).
  • get_variance() no longer stops if random effects variance cannot be calculated. Rather, the return-value for $var.random will be NULL.

Changes to functions

  • get_variance() now computes the full variance for mixed models with zero-inflation component.
  • get_priors() now returns the default-prior that was defined for all parameters of a class, if certain parameters have no specific prior.
  • find_parameters() gets a flatten-argument, to either return results as list or as simple vector.
  • find_variables() gets a flatten-argument, to either return results as list or as simple vector.

Bug fixes

  • get_data() did not work when model formula contained a function with namespace-prefix (like lm(Sepal.Length ~ splines::bs(Petal.Width, df=4)) (#93).
  • get_priors() failed for stanreg-models, when one or more priors had no adjusted scales (#74).
  • find_random() failed for mixed models with multiple responses.
  • get_random() failed for brmsfit and stanreg models.
  • get_parameters() and find_parameters() did not work for MixMod-objects without zero-inflation component, when component = "all" (the default).
  • find_formula() did not work for plm-models without instrumental variables.
  • find_formula() returned random effects as conditional part of the formula for null-models (only intercept in fixed parts) (#87).
  • Fixed issue with invalid notation of instrumental-variables formula in felm-models for R-devel on Linux.
  • Fixed issue with get_data() for gee models, where incomplete cases were not removed from the data.
  • Fixed potential issue with get_data() for null-models (only intercept in fixed parts) from models of class glmmTMB, brmsfit, MixMod and rstanarm (#91).
  • find_variables() no longer returns (multiple) "1" for random effects.

insight 0.2.0

General

  • Better handling of AsIs-variables with division-operation as dependent variables, e.g. if outcome was defined as I(income/frequency), especially for find_response() and get_data().
  • Revised package-functions related to felm-models due to breaking changes in the lfe-package.

New supported model classes

  • iv_robust (estimatr), crch (crch), gamlss (gamlss), lmrob and glmrob (robustbase, #64), rq, rqss and crq (quantreg), rlmer (robustlmm), mixed (afex), tobit (AER) and survreg (survival).

New functions

  • get_variance(), to calculate the variance components from mixed models of class merMod, glmmTMB, MixMod, rlmer, mixed, lme and stanreg (#52). Furthermore, convenient shortcuts to return the related components directly, like get_variance_random() or get_variance_residual().
  • find_algorithm(), to get information about sampling algorithms and optimizers, and for Bayesian models also about chains and iterations (#38).
  • find_random_slopes(), which returns the names of the random slopes of mixed models.
  • get_priors(), to get a summary of priors used for a model (#39).
  • is_model() to check whether an object is a (supported) regression model (#69).
  • all_models_equal() to check whether objects are all (supported) regression models and of same class.
  • print_color() (resp. print_colour()) to print coloured output to the console. Mainly implemented to reduce package dependencies.

Changes to functions

  • find_parameters() and get_parameters() get a parameters-argument for brmsfit and stanreg models, to allow selection of specific parameters that should be returned (#55).
  • find_parameters() and get_parameters() now also return simplex parameters of monotic effects (brms only) and smooth terms (e.g. for gam-models).
  • find_terms() and find_predictors() no longer return constants, in particular pi (#26).
  • For gls and lme objects, functions like find_formula() etc. also return the correlation component (#19).
  • model_info now returns $is_tweedie for models from tweedie-families.

Bug fixes

  • find_parameters() and get_parameters() did not preserve coefficients of monotonic category-specific effects from brmsfit-objects.
  • Fixed bug that sometimes returned more elements for find_predictors() or get_parameters() than requested.
  • Fixed bug in get_data() for MixMod-objects when response variable was defined via cbind().
  • Fixed bug in get_response() for models that used cbind() with a substraction (e.g. cbind(success, total - success)). In such cases, values for second column (in this example: total) were the substracted values total - success, not the original values from total.

insight 0.1.2

General

  • Initial release.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.