A unified syntax for accessing models' information

The richness and variety of packages for building and fitting statistical models in R is absolutely astonishing and contributes to the language’s popularity. However, this diversity makes it hard for developpers that want to create tools that work with different types of models. Indeed, the way to access models’ internal information (such as parameters names, formulae, data, etc.) is not unified, forcing the developers to spend some time figuring out how to do it for each model type.

This time is over!

Insight

Recently, we have decided to collaborate around the new easystats project, a set of packages designed to make your life easier (currently very work in progress). However, in order to create these packages and functions, we needed a basis, a stable cornerstone, that would allow the unified way of accessing models information.

And insight was born.

The goal of insight is to provide tools to help an easy, intuitive and consistent accesss to information contained in various models. Indeed, 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.

insight can be installed as follows:

install.packages("insight")  # Install from CRAN
library(insight)  # Load the package

Example

Let’s see how it works on a very simple regression model:

model <- lm(Sepal.Length ~ Species, data=iris)
  • Find the parameters:
find_parameters(model)
> $conditional
> [1] "(Intercept)"       "Speciesversicolor" "Speciesvirginica"
  • Find the outcome’s name:
find_response(model)
> [1] "Sepal.Length"
  • Find the formula:
find_formula(model)
> $conditional
> Sepal.Length ~ Species
> 
> attr(,"class")
> [1] "insight_formula" "list"
  • Find the variables in the formula:
find_variables(model)
> $response
> [1] "Sepal.Length"
> 
> $conditional
> [1] "Species"
  • Find the algorithm:
find_algorithm(model)
> $algorithm
> [1] "OLS"

Moreover, insight also includes functions to deal with Bayesian (get_priors()) and mixed models (find_random()).

insight works on a high number of models (see the list here), and continue to grow thanks to your suggestions! As easystats is a new project in active development, do not hesitate to contact us if you want to get involved :)

  • Check out our other blog posts here!