estimate
is a lightweight package helping with model-based
estimations, used in the computation of marginal means, contrast
analysis and predictions.
Run the following:
install.packages("devtools")
devtools::install_github("easystats/estimate")
library("estimate")
Click on the buttons above to access the package documentation and the easystats blog, and check-out these vignettes:
- Data grids
- Marginal means
- Contrast analysis
- Use a model to make predictions
- Describe non-linear curves
The package is built around 5 main functions:
estimate_means()
: Estimates the average values at each factor levelsestimate_contrasts()
: Estimates and tests contrasts between different factor levelsestimate_slopes()
: Estimates the slopes of numeric predictors at different factor levelsestimate_response()
: Predict the response variable using the modelestimate_smooth()
: Describes a non-linear term (e.g. in GAMs) by its linear parts
These functions are powered by the
data_grid()
function, a smart tool for guessing the appropriate reference grid.
The package currently only supports rstanarm
models, but will be
expanded to cover a large variety of frequentist and Bayesian models.
library(rstanarm)
model <- stan_glm(Sepal.Width ~ Species, data = iris)
estimate_means(model)
## Species | Median | 89% CI
## ----------------------------------
## setosa | 3.43 | [3.35, 3.50]
## versicolor | 2.77 | [2.69, 2.85]
## virginica | 2.98 | [2.90, 3.05]
estimate_contrasts(model)
## Level1 | Level2 | Median | 89% CI | pd | % in ROPE | Median (std.)
## --------------------------------------------------------------------------------------
## setosa | versicolor | 0.65 | [0.55, 0.76] | 100% | 0% | 1.50
## setosa | virginica | 0.45 | [0.34, 0.56] | 100% | 0% | 1.03
## versicolor | virginica | -0.20 | [-0.31, -0.09] | 99.85% | 6.10% | -0.47
library(see)
plot(estimate_contrasts(model), estimate_means(model))
model <- stan_glm(Sepal.Width ~ Species * Petal.Length, data = iris)
estimate_contrasts(model, modulate = "Petal.Length", length = 3)
## Level1 | Level2 | Petal.Length | Median | 89% CI | pd | % in ROPE | Median (std.)
## ----------------------------------------------------------------------------------------------------
## setosa | versicolor | 1.00 | 1.53 | [1.06, 2.02] | 100% | 0% | 3.52
## setosa | virginica | 1.00 | 1.22 | [0.69, 1.78] | 99.98% | 0.02% | 2.81
## versicolor | virginica | 1.00 | -0.31 | [-0.98, 0.45] | 74.72% | 13.35% | -0.71
## setosa | versicolor | 3.95 | 1.78 | [1.03, 2.57] | 100% | 0% | 4.07
## setosa | virginica | 3.95 | 1.81 | [1.04, 2.66] | 100% | 0.02% | 4.14
## versicolor | virginica | 3.95 | 0.03 | [-0.18, 0.25] | 59.85% | 52.33% | 0.07
## setosa | versicolor | 6.90 | 2.00 | [0.53, 3.83] | 97.42% | 1.03% | 4.58
## setosa | virginica | 6.90 | 2.40 | [0.92, 4.17] | 99.00% | 0.78% | 5.50
## versicolor | virginica | 6.90 | 0.38 | [-0.08, 0.78] | 91.67% | 10.82% | 0.87
estimate_slopes(model)
## Species | Median | 89% CI | pd | % in ROPE | Median (std.)
## -----------------------------------------------------------------------
## setosa | 0.41 | [0.13, 0.73] | 98.32% | 4.70% | 1.66
## versicolor | 0.33 | [0.19, 0.48] | 99.98% | 0.75% | 1.33
## virginica | 0.21 | [0.09, 0.33] | 99.80% | 6.78% | 0.86
estimate_response(model)
Species | Petal.Length | Median | CI_low | CI_high |
---|---|---|---|---|
setosa | 1.4 | 3.40 | 2.91 | 3.92 |
setosa | 1.4 | 3.40 | 2.83 | 3.87 |
setosa | 1.3 | 3.36 | 2.84 | 3.83 |
setosa | 1.5 | 3.44 | 2.92 | 3.94 |
setosa | 1.4 | 3.40 | 2.88 | 3.91 |
setosa | 1.7 | 3.53 | 3.03 | 4.07 |
model <- stan_glm(Sepal.Width ~ poly(Petal.Length, 2), data=iris)
estimate_link(model)
Petal.Length | Median | CI_low | CI_high |
---|---|---|---|
1.00 | 3.62 | 3.52 | 3.73 |
1.98 | 3.18 | 3.11 | 3.24 |
2.97 | 2.90 | 2.83 | 2.97 |
3.95 | 2.78 | 2.71 | 2.86 |
4.93 | 2.83 | 2.78 | 2.89 |
5.92 | 3.05 | 2.96 | 3.14 |
6.90 | 3.44 | 3.25 | 3.63 |
estimate_smooth(model)
## Part | Start | End | Size | Trend | Linearity
## ------------------------------------------------
## 1 | 1.00 | 4.11 | 53.50% | -0.01 | 0.94
## 2 | 4.11 | 6.90 | 47.00% | 0.01 | 0.94