Learn R Programming

⚠️There's a newer version (0.22.0) of this package.Take me there.

parameters

Describe and understand your model’s parameters!

parameters’ primary goal is to provide utilities for processing the parameters of various statistical models. Beyond computing p-values, CIs, Bayesian indices and other measures for a wide variety of models, this package implements features like bootstrapping of parameters and models, feature reduction (feature extraction and variable selection).

Installation

Run the following:

install.packages("parameters")
library("parameters")

Documentation

Click on the buttons above to access the package documentation and the easystats blog, and check-out these vignettes:

Features

Model’s parameters description

The model_parameters() function (that can be accessed via the parameters() shortcut) allows you to extract the parameters and their characteristics from various models in a consistent way. It can be considered as a lightweight alternative to broom::tidy(), with some notable differences:

  • The column names of the returned data frame are specific to their content. For instance, the column containing the statistic is named following the statistic name, i.e., t, z, etc., instead of a generic name such as statistic (however, you can get standardized (generic) column names using standardize_names()).
  • It is able to compute or extract indices not available by default, such as p-values, CIs, etc.
  • It includes feature engineering capabilities, including parameters bootstrapping.

Classical Regression Models

model <- lm(Sepal.Width ~ Petal.Length * Species + Petal.Width, data = iris)

# regular model parameters
model_parameters(model)
# Parameter                           | Coefficient |   SE |         95% CI |     t |  df |      p
# ------------------------------------------------------------------------------------------------
# (Intercept)                         |        2.89 | 0.36 | [ 2.18,  3.60] |  8.01 | 143 | < .001
# Petal.Length                        |        0.26 | 0.25 | [-0.22,  0.75] |  1.07 | 143 | 0.287 
# Species [versicolor]                |       -1.66 | 0.53 | [-2.71, -0.62] | -3.14 | 143 | 0.002 
# Species [virginica]                 |       -1.92 | 0.59 | [-3.08, -0.76] | -3.28 | 143 | 0.001 
# Petal.Width                         |        0.62 | 0.14 | [ 0.34,  0.89] |  4.41 | 143 | < .001
# Petal.Length * Species [versicolor] |       -0.09 | 0.26 | [-0.61,  0.42] | -0.36 | 143 | 0.721 
# Petal.Length * Species [virginica]  |       -0.13 | 0.26 | [-0.64,  0.38] | -0.50 | 143 | 0.618

# standardized parameters
model_parameters(model, standardize = "refit")
# Parameter                           | Coefficient (std.) |   SE |         95% CI |     t |  df |      p
# -------------------------------------------------------------------------------------------------------
# (Intercept)                         |               3.59 | 1.30 | [ 1.03,  6.14] |  8.01 | 143 | < .001
# Petal.Length                        |               1.07 | 1.00 | [-0.89,  3.03] |  1.07 | 143 | 0.287 
# Species [versicolor]                |              -4.62 | 1.31 | [-7.19, -2.06] | -3.14 | 143 | 0.002 
# Species [virginica]                 |              -5.51 | 1.38 | [-8.20, -2.81] | -3.28 | 143 | 0.001 
# Petal.Width                         |               1.08 | 0.24 | [ 0.60,  1.56] |  4.41 | 143 | < .001
# Petal.Length * Species [versicolor] |              -0.38 | 1.06 | [-2.46,  1.70] | -0.36 | 143 | 0.721 
# Petal.Length * Species [virginica]  |              -0.52 | 1.04 | [-2.56,  1.52] | -0.50 | 143 | 0.618

Mixed Models

library(lme4)

model <- lmer(Sepal.Width ~ Petal.Length + (1|Species), data = iris)

# model parameters with CI, df and p-values based on Wald approximation
model_parameters(model)
# Parameter    | Coefficient |   SE |       95% CI |    t |  df |      p
# ----------------------------------------------------------------------
# (Intercept)  |        2.00 | 0.56 | [0.90, 3.10] | 3.56 | 146 | < .001
# Petal.Length |        0.28 | 0.06 | [0.17, 0.40] | 4.75 | 146 | < .001

# model parameters with CI, df and p-values based on Kenward-Roger approximation
model_parameters(model, df_method = "kenward")
# Parameter    | Coefficient |   SE |       95% CI |    t |      p
# ----------------------------------------------------------------
# (Intercept)  |        2.00 | 0.57 | [0.08, 3.92] | 3.53 | 0.046 
# Petal.Length |        0.28 | 0.06 | [0.16, 0.40] | 4.58 | < .001

Structural Models

Besides many types of regression models and packages, it also works for other types of models, such as structural models (EFA, CFA, SEM…).

library(psych)

model <- psych::fa(attitude, nfactors = 3)
model_parameters(model)
# # Rotated loadings from Principal Component Analysis (oblimin-rotation)
# 
# Variable   |   MR1 |   MR2 |   MR3 | Complexity | Uniqueness
# ------------------------------------------------------------
# rating     |  0.90 | -0.07 | -0.05 |       1.02 |       0.23
# complaints |  0.97 | -0.06 |  0.04 |       1.01 |       0.10
# privileges |  0.44 |  0.25 | -0.05 |       1.64 |       0.65
# learning   |  0.47 |  0.54 | -0.28 |       2.51 |       0.24
# raises     |  0.55 |  0.43 |  0.25 |       2.35 |       0.23
# critical   |  0.16 |  0.17 |  0.48 |       1.46 |       0.67
# advance    | -0.11 |  0.91 |  0.07 |       1.04 |       0.22
# 
# The 3 latent factors (oblimin rotation) accounted for 66.60% of the total variance of the original data (MR1 = 38.19%, MR2 = 22.69%, MR3 = 5.72%).

Variable and parameters selection

parameters_selection() can help you quickly select and retain the most relevant predictors using methods tailored for the model type.

library(dplyr)

lm(disp ~ ., data = mtcars) %>% 
  select_parameters() %>% 
  model_parameters()
# Parameter   | Coefficient |     SE |            95% CI |     t | df |      p
# ----------------------------------------------------------------------------
# (Intercept) |      141.70 | 125.67 | [-116.62, 400.02] |  1.13 | 26 | 0.270 
# cyl         |       13.14 |   7.90 | [  -3.10,  29.38] |  1.66 | 26 | 0.108 
# hp          |        0.63 |   0.20 | [   0.22,   1.03] |  3.18 | 26 | 0.004 
# wt          |       80.45 |  12.22 | [  55.33, 105.57] |  6.58 | 26 | < .001
# qsec        |      -14.68 |   6.14 | [ -27.31,  -2.05] | -2.39 | 26 | 0.024 
# carb        |      -28.75 |   5.60 | [ -40.28, -17.23] | -5.13 | 26 | < .001

This function also works for mixed or Bayesian models:

library(rstanarm)

stan_glm(mpg ~ ., data = mtcars, refresh = 0) %>% 
  select_parameters() %>% 
  model_parameters()
# Parameter   | Median |         89% CI |     pd | % in ROPE |  Rhat |  ESS |               Prior
# -----------------------------------------------------------------------------------------------
# (Intercept) |  19.90 | [-0.59, 44.44] | 92.62% |     1.23% | 1.000 | 2348 | Normal (0 +- 60.27)
# wt          |  -3.98 | [-5.92, -1.88] | 99.75% |     0.32% | 1.001 | 2159 | Normal (0 +- 15.40)
# cyl         |  -0.48 | [-1.91,  0.76] | 71.43% |    46.02% | 1.000 | 2651 |  Normal (0 +- 8.44)
# hp          |  -0.02 | [-0.04,  0.01] | 89.22% |      100% | 1.000 | 2766 |  Normal (0 +- 0.22)
# am          |   2.93 | [-0.01,  5.77] | 94.90% |     7.42% | 1.000 | 2813 | Normal (0 +- 15.07)
# qsec        |   0.80 | [-0.18,  1.73] | 91.33% |    35.23% | 1.000 | 2273 |  Normal (0 +- 8.43)
# disp        |   0.01 | [-0.01,  0.03] | 87.08% |      100% | 1.002 | 2601 |  Normal (0 +- 0.12)

Miscellaneous

This packages also contains a lot of other useful functions:

Describe a Distribution

x <- rnorm(300)
describe_distribution(x)
MeanSDMinMaxSkewnessKurtosisnn_Missing
-0.11-330-0.33000

Citation

In order to cite this package, please use the following citation:

Corresponding BibTeX entry:

@Article{,
  title = {Describe and understand your model's parameters},
  author = {Dominique Makowski and Mattan S. Ben-Shachar and Daniel
  Lüdecke},
  journal = {CRAN},
  year = {2019},
  note = {R package},
  url = {https://github.com/easystats/parameters},
}

Copy Link

Version

Install

install.packages('parameters')

Monthly Downloads

87,418

Version

0.4.1

License

GPL-3

Maintainer

Daniel Lüdecke

Last Published

January 17th, 2020

Functions in parameters (0.4.1)

cluster_discrimination

Compute a linear discriminant analysis on classified cluster groups
describe_distribution

Describe a distribution
cluster_analysis

Compute cluster analysis and return group indices
check_factorstructure

Check suitability of data for Factor Analysis (FA)
demean

Compute group-meaned and de-meaned variables
.factor_to_numeric

Safe transformation from factor/character to numeric
format_bf

Bayes Factor formatting
.factor_to_dummy

Safe transformation from factor/character to numeric
degrees_of_freedom

Degrees of Freedom (DoF)
format_algorithm

Model Algorithm formatting
check_sphericity

Bartlett's Test of Sphericity
model_parameters.Mclust

Mixture Models Parameters
.data_frame

help-functions
.compact_list

remove NULL elements from lists
equivalence_test.lm

Equivalence test
ci.merMod

Confidence Interval (CI)
factor_analysis

Factor Analysis (FA)
model_parameters.mixor

Parameters from Mixed Models
n_parameters

Count number of parameters in a model
rescale_weights

Rescale design weights for multilevel analysis
format_pd

Probability of direction (pd) formatting
format_parameters

Parameter names formatting
reexports

Objects exported from other packages
n_factors

Number of components/factors to retain in PCA/FA
model_parameters.lavaan

Parameters from CFA/SEM models
model_parameters

Model Parameters
cmds

Classical Multidimensional Scaling (cMDS)
.flatten_list

Flatten a list
model_parameters.aov

Parameters from ANOVAs
model_parameters.htest

Parameters from Correlations and t-tests
.n_factors_sescree

Standard Error Scree and Coefficient of Determination Procedures
.n_factors_bentler

Bentler and Yuan's Procedure
model_parameters.befa

Parameters from PCA/FA
.n_factors_cng

Cattell-Nelson-Gorsuch CNG Indices
convert_data_to_numeric

Convert data to numeric
.recode_to_zero

Recode a variable so its lowest value is beginning with zero
format_model

Model Name formatting
.n_factors_bartlett

Bartlett, Anderson and Lawley Procedures
model_parameters.kmeans

Parameters from Cluster Models (k-means, ...)
ci_wald

Wald-test approximation for CIs and p-values
parameters_table

Parameter table formatting
model_parameters.zeroinfl

Model Parameters from Zero-Inflated Models
format_number

Convert number to words
.compact_character

remove empty string from character
.n_factors_scree

Non Graphical Cattell's Scree Test
.find_most_common

Find most common occurence
.filter_component

for models with zero-inflation component, return required component of model-summary
.n_factors_mreg

Multiple Regression Procedure
n_clusters

Number of clusters to extract
format_order

Order (first, second, ...) formatting
dof_ml1

p-values using the "m-l-1" heuristic
format_rope

Percentage in ROPE formatting
dof_satterthwaite

p-values using Satterthwaite approximation
simulate_model

Simulated draws from model coefficients
smoothness

Quantify the smoothness of a vector
skewness

Compute Skewness and Kurtosis
model_parameters.PCA

Parameters from Structural Models (PCA, EFA, ...)
dof_kenward

p-values using Kenward-Roger approximation
print

Print model parameters
model_parameters.stanreg

Parameters from Bayesian Models
format_p

p-values formatting
p_value

p-values
reduce_parameters

Dimensionality reduction (DR) / Features Reduction
standard_error_robust

Standard Errors
standardize_names

Standardize column names
principal_components

Principal Component Analysis (PCA)
reshape_loadings

Reshape loadings between wide/long formats
model_parameters.gam

Parameters of Generalized Additive (Mixed) Models
model_parameters.default

Parameters from (General) Linear Models
parameters_type

Type of model parameters
model_parameters.BFBayesFactor

Parameters from BayesFactor objects
select_parameters

Automated selection of model parameters
simulate_parameters

Simulate Model Parameters
check_multimodal

Check if a distribution is unimodal or multimodal
convert_efa_to_cfa

Conversion between EFA results and CFA structure
check_kmo

Kaiser, Meyer, Olkin (KMO) Measure of Sampling Adequacy (MSA) for Factor Analysis
data_partition

Partition data into a test and a training set
bootstrap_parameters

Parameters bootstrapping
bootstrap_model

Model bootstrapping
DRR

Dimensionality Reduction via Regression (DRR)
ICA

Independent Component Analysis (ICA)
check_clusterstructure

Check suitability of data for clustering