Skip to content

Commit

Permalink
Include recommendation to use meta-package
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil committed Oct 5, 2022
1 parent ccba460 commit 74a79c6
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 107 deletions.
2 changes: 1 addition & 1 deletion R/estimate_grouplevel.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#' # Bayesian models
#' \donttest{
#' if (require("rstanarm")) {
#' model <- rstanarm::stan_lmer(mpg ~ hp + (1 | carb) + (1|gear), data = mtcars, refresh = 0)
#' model <- rstanarm::stan_lmer(mpg ~ hp + (1 | carb) + (1 | gear), data = mtcars, refresh = 0)
#' # Broken estimate_grouplevel(model)
#' }
#' }
Expand Down
15 changes: 9 additions & 6 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,20 @@ Development | R-universe | `install.packages("modelbased", repos = "https://easy

Once you have downloaded the package, you can then load it using:

```{r, eval=FALSE}
```{r, eval=FALSE}
library("modelbased")
```

## Documentation
> **Tip**
>
> **Instead of `library(datawizard)`, use `library(easystats)`.**
> **This will make all features of the easystats-ecosystem available.**
>
> **To stay updated, use `easystats::install_latest()`.**
[![Documentation](https://img.shields.io/badge/documentation-modelbased-orange.svg?colorB=E91E63)](https://easystats.github.io/modelbased/)
[![Blog](https://img.shields.io/badge/blog-easystats-orange.svg?colorB=FF9800)](https://easystats.github.io/blog/posts/)
[![Features](https://img.shields.io/badge/features-modelbased-orange.svg?colorB=2196F3)](https://easystats.github.io/modelbased/reference/index.html)
## Documentation

Click on the buttons above to access the package [**documentation**](https://easystats.github.io/modelbased/) and the [**easystats blog**](https://easystats.github.io/blog/posts/), and check-out these vignettes:
Access the package [**documentation**](https://easystats.github.io/modelbased/), and check-out these vignettes:

- [**Visualisation matrix**](https://easystats.github.io/modelbased/articles/visualisation_matrix.html)
- [**Marginal means**](https://easystats.github.io/modelbased/articles/estimate_means.html)
Expand Down
186 changes: 94 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[![downloads](http://cranlogs.r-pkg.org/badges/modelbased)](https://cran.r-project.org/package=modelbased)
[![total](https://cranlogs.r-pkg.org/badges/grand-total/modelbased)](https://cranlogs.r-pkg.org/)
[![status](https://tinyverse.netlify.com/badge/modelbased)](https://CRAN.R-project.org/package=modelbased)
[![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html)

***Taking your models to new heights***

Expand Down Expand Up @@ -36,64 +37,65 @@ Once you have downloaded the package, you can then load it using:
library("modelbased")
```

## Documentation
> **Tip**
>
> **Instead of `library(datawizard)`, use `library(easystats)`.** **This
> will make all features of the easystats-ecosystem available.**
>
> **To stay updated, use `easystats::install_latest()`.**
[![Documentation](https://img.shields.io/badge/documentation-modelbased-orange.svg?colorB=E91E63)](https://easystats.github.io/modelbased/)
[![Blog](https://img.shields.io/badge/blog-easystats-orange.svg?colorB=FF9800)](https://easystats.github.io/blog/posts/)
[![Features](https://img.shields.io/badge/features-modelbased-orange.svg?colorB=2196F3)](https://easystats.github.io/modelbased/reference/index.html)
## Documentation

Click on the buttons above to access the package
[**documentation**](https://easystats.github.io/modelbased/) and the
[**easystats blog**](https://easystats.github.io/blog/posts/), and
Access the package
[**documentation**](https://easystats.github.io/modelbased/), and
check-out these vignettes:

- [**Visualisation
matrix**](https://easystats.github.io/modelbased/articles/visualisation_matrix.html)
- [**Marginal
means**](https://easystats.github.io/modelbased/articles/estimate_means.html)
- [**Contrast
analysis**](https://easystats.github.io/modelbased/articles/estimate_contrasts.html)
- [**Marginal
effects**](https://easystats.github.io/modelbased/articles/estimate_slopes.html)
- [**Use a model to make
predictions**](https://easystats.github.io/modelbased/articles/estimate_response.html)
- [**Describe non-linear
curves**](https://easystats.github.io/modelbased/articles/describe_nonlinear.html)
- [**Interpret models using Effect
Derivatives**](https://easystats.github.io/modelbased/articles/derivatives.html)
- [**Estimate and re-use random
effects**](https://easystats.github.io/modelbased/articles/estimate_grouplevel.html)
- [**The modelisation
approach**](https://easystats.github.io/modelbased/articles/modelisation_approach.html)
- [**Visualisation
matrix**](https://easystats.github.io/modelbased/articles/visualisation_matrix.html)
- [**Marginal
means**](https://easystats.github.io/modelbased/articles/estimate_means.html)
- [**Contrast
analysis**](https://easystats.github.io/modelbased/articles/estimate_contrasts.html)
- [**Marginal
effects**](https://easystats.github.io/modelbased/articles/estimate_slopes.html)
- [**Use a model to make
predictions**](https://easystats.github.io/modelbased/articles/estimate_response.html)
- [**Describe non-linear
curves**](https://easystats.github.io/modelbased/articles/describe_nonlinear.html)
- [**Interpret models using Effect
Derivatives**](https://easystats.github.io/modelbased/articles/derivatives.html)
- [**Estimate and re-use random
effects**](https://easystats.github.io/modelbased/articles/estimate_grouplevel.html)
- [**The modelisation
approach**](https://easystats.github.io/modelbased/articles/modelisation_approach.html)

# Features

The package is built around 5 main functions:

- [`estimate_means()`](https://easystats.github.io/modelbased/reference/estimate_means.html):
Estimates the average values at each factor levels
- [`estimate_contrasts()`](https://easystats.github.io/modelbased/reference/estimate_contrasts.html):
Estimates and tests contrasts between different factor levels
- [`estimate_slopes()`](https://easystats.github.io/modelbased/reference/estimate_slopes.html):
Estimates the slopes of numeric predictors at different factor
levels or alongside a numeric predictor
- [`estimate_expectation()`](https://easystats.github.io/modelbased/articles/estimate_response.html):
Predict the response variable using the model
- [`estimate_means()`](https://easystats.github.io/modelbased/reference/estimate_means.html):
Estimates the average values at each factor levels
- [`estimate_contrasts()`](https://easystats.github.io/modelbased/reference/estimate_contrasts.html):
Estimates and tests contrasts between different factor levels
- [`estimate_slopes()`](https://easystats.github.io/modelbased/reference/estimate_slopes.html):
Estimates the slopes of numeric predictors at different factor levels
or alongside a numeric predictor
- [`estimate_expectation()`](https://easystats.github.io/modelbased/articles/estimate_response.html):
Predict the response variable using the model

These functions are powered by the
[`visualisation_matrix()`](https://easystats.github.io/modelbased/reference/visualisation_matrix.html)
function, a smart tool for guessing the appropriate reference grid.

## Create smart grids to represent complex interactions

- **Problem**: I want to graphically represent the interaction between
two continuous variable. On top of that, I would like to express one
of them in terms of standardized change (i.e., standard deviation
relative to the mean).
- **Solution**: Create a data grid following the desired
specifications, and feed it to the model to obtain predictions.
Format some of the columns for better readability, and plot using
`ggplot`.
- **Problem**: I want to graphically represent the interaction between
two continuous variable. On top of that, I would like to express one
of them in terms of standardized change (i.e., standard deviation
relative to the mean).
- **Solution**: Create a data grid following the desired specifications,
and feed it to the model to obtain predictions. Format some of the
columns for better readability, and plot using `ggplot`.

Check-out [**this
vignette**](https://easystats.github.io/modelbased/articles/visualisation_matrix.html)
Expand Down Expand Up @@ -135,12 +137,12 @@ ggplot(iris, aes(x = Petal.Length, y = Sepal.Length)) +

## Estimate marginal means

- **Problem**: My model has a factor as a predictor, and the
parameters only return the difference between levels and the
intercept. I want to see the values *at* each factor level.
- **Solution**: Estimate model-based means (“marginal means”). You can
visualize them by plotting their confidence interval and the
original data.
- **Problem**: My model has a factor as a predictor, and the parameters
only return the difference between levels and the intercept. I want to
see the values *at* each factor level.
- **Solution**: Estimate model-based means (“marginal means”). You can
visualize them by plotting their confidence interval and the original
data.

Check-out [**this
vignette**](https://easystats.github.io/modelbased/articles/estimate_means.html)
Expand Down Expand Up @@ -186,12 +188,12 @@ ggplot(iris, aes(x = Species, y = Sepal.Width)) +

## Contrast analysis

- **Problem**: The parameters of my model only return the difference
between some of the factor levels and the intercept. I want to see
the differences between each levels, as I would do with post-hoc
comparison tests in ANOVAs.
- **Solution**: Estimate model-based contrasts (“marginal contrasts”).
You can visualize them by plotting their confidence interval.
- **Problem**: The parameters of my model only return the difference
between some of the factor levels and the intercept. I want to see the
differences between each levels, as I would do with post-hoc
comparison tests in ANOVAs.
- **Solution**: Estimate model-based contrasts (“marginal contrasts”).
You can visualize them by plotting their confidence interval.

Check-out [**this
vignette**](https://easystats.github.io/modelbased/articles/estimate_contrasts.html)
Expand All @@ -210,7 +212,7 @@ contrasts
## ------------------------------------------------------------------------------
## setosa | versicolor | 0.66 | [ 0.49, 0.82] | 0.07 | 9.69 | < .001
## setosa | virginica | 0.45 | [ 0.29, 0.62] | 0.07 | 6.68 | < .001
## versicolor | virginica | -0.20 | [-0.37, -0.04] | 0.07 | -3.00 | 0.009
## versicolor | virginica | -0.20 | [-0.37, -0.04] | 0.07 | -3.00 | 0.003
##
## Marginal contrasts estimated at Species
## p-value adjustment method: Holm (1979)
Expand All @@ -220,13 +222,13 @@ contrasts

## Check the contrasts at different points of another linear predictor

- **Problem**: In the case of an interaction between a factor and a
continuous variable, you might be interested in computing how the
differences between the factor levels (the contrasts) change
depending on the other continuous variable.
- **Solution**: You can estimate the marginal contrasts at different
values of a continuous variable (the *modulator*), and plot these
differences (they are significant if their 95% CI doesn’t cover 0).
- **Problem**: In the case of an interaction between a factor and a
continuous variable, you might be interested in computing how the
differences between the factor levels (the contrasts) change depending
on the other continuous variable.
- **Solution**: You can estimate the marginal contrasts at different
values of a continuous variable (the *modulator*), and plot these
differences (they are significant if their 95% CI doesn’t cover 0).

``` r
model <- lm(Sepal.Width ~ Species * Petal.Length, data = iris)
Expand All @@ -238,13 +240,13 @@ estimate_contrasts(model, at = "Petal.Length", length = 3)
## --------------------------------------------------------------------------------------------
## setosa | versicolor | 1.00 | 1.70 | [ 0.87, 2.53] | 0.34 | 4.97 | < .001
## setosa | versicolor | 3.95 | 1.74 | [ 0.16, 3.32] | 0.65 | 2.67 | 0.023
## setosa | versicolor | 6.90 | 1.78 | [-1.71, 5.26] | 1.44 | 1.24 | 0.434
## setosa | virginica | 1.00 | 1.34 | [ 0.38, 2.30] | 0.40 | 3.38 | 0.003
## setosa | virginica | 3.95 | 1.79 | [ 0.19, 3.40] | 0.66 | 2.70 | 0.021
## setosa | virginica | 6.90 | 2.25 | [-1.19, 5.69] | 1.42 | 1.58 | 0.257
## versicolor | virginica | 1.00 | -0.36 | [-1.55, 0.83] | 0.49 | -0.73 | 0.747
## versicolor | virginica | 3.95 | 0.06 | [-0.30, 0.42] | 0.15 | 0.37 | 0.926
## versicolor | virginica | 6.90 | 0.47 | [-0.22, 1.16] | 0.28 | 1.65 | 0.229
## setosa | versicolor | 6.90 | 1.78 | [-1.71, 5.26] | 1.44 | 1.24 | 0.304
## setosa | virginica | 1.00 | 1.34 | [ 0.38, 2.30] | 0.40 | 3.38 | 0.002
## setosa | virginica | 3.95 | 1.79 | [ 0.19, 3.40] | 0.66 | 2.70 | 0.023
## setosa | virginica | 6.90 | 2.25 | [-1.19, 5.69] | 1.42 | 1.58 | 0.304
## versicolor | virginica | 1.00 | -0.36 | [-1.55, 0.83] | 0.49 | -0.73 | 0.468
## versicolor | virginica | 3.95 | 0.06 | [-0.30, 0.42] | 0.15 | 0.37 | 0.710
## versicolor | virginica | 6.90 | 0.47 | [-0.22, 1.16] | 0.28 | 1.65 | 0.304
##
## Marginal contrasts estimated at Species
## p-value adjustment method: Holm (1979)
Expand Down Expand Up @@ -272,14 +274,14 @@ ggplot(contrasts, aes(x = Petal.Length, y = Difference, )) +

## Generate predictions from your model to compare it with original data

- **Problem**: You fitted different models, and you want to
intuitively visualize how they compare in terms of fit quality and
prediction accuracy, so that you don’t only rely on abstract indices
of performance.
- **Solution**: You can predict the response variable from different
models and plot them against the original true response. The closest
the points are on the identity line (the diagonal), the closest they
are from a perfect fit.
- **Problem**: You fitted different models, and you want to intuitively
visualize how they compare in terms of fit quality and prediction
accuracy, so that you don’t only rely on abstract indices of
performance.
- **Solution**: You can predict the response variable from different
models and plot them against the original true response. The closest
the points are on the identity line (the diagonal), the closest they
are from a perfect fit.

Check-out [**this
vignette**](https://easystats.github.io/modelbased/articles/estimate_response.html)
Expand Down Expand Up @@ -328,10 +330,10 @@ ggplot(data = pred1, aes(x = Petal.Length, y = Predicted)) +

## Extract and format group-level random effects

- **Problem**: You have a mixed model and you would like to easily
access the random part, i.e., the group-level effects (e.g., the
individuals scores).
- **Solution**: You can apply `estimate_grouplevel` on a mixed model.
- **Problem**: You have a mixed model and you would like to easily
access the random part, i.e., the group-level effects (e.g., the
individuals scores).
- **Solution**: You can apply `estimate_grouplevel` on a mixed model.

See [**this
vignette**](https://easystats.github.io/modelbased/articles/estimate_grouplevel.html)
Expand Down Expand Up @@ -362,11 +364,11 @@ plot(random)

## Estimate derivative of non-linear relationships (e.g., in GAMs)

- **Problem**: You model a non-linear relationship using polynomials,
splines or GAMs. You want to know which parts of the curve are
significant positive or negative trends.
- **Solution**: You can estimate the *derivative* of smooth using
`estimate_slopes`.
- **Problem**: You model a non-linear relationship using polynomials,
splines or GAMs. You want to know which parts of the curve are
significant positive or negative trends.
- **Solution**: You can estimate the *derivative* of smooth using
`estimate_slopes`.

The two plots below represent the modeled (non-linear) effect estimated
by the model, i.e., the relationship between the outcome and the
Expand Down Expand Up @@ -403,12 +405,12 @@ see::plots(

## Describe the smooth term by its linear parts

- **Problem**: You model a non-linear relationship using polynomials,
splines or GAMs. You want to describe it in terms of linear parts:
where does it decrease, how much, where does it increase, etc.
- **Solution**: You can apply `describe_nonlinear` on a predicted
relationship that will return the different parts of increase and
decrease.
- **Problem**: You model a non-linear relationship using polynomials,
splines or GAMs. You want to describe it in terms of linear parts:
where does it decrease, how much, where does it increase, etc.
- **Solution**: You can apply `describe_nonlinear` on a predicted
relationship that will return the different parts of increase and
decrease.

See [**this
vignette**](https://easystats.github.io/modelbased/articles/describe_nonlinear.html)
Expand Down
Binary file modified man/figures/unnamed-chunk-10-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/unnamed-chunk-12-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/unnamed-chunk-14-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/unnamed-chunk-15-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/unnamed-chunk-16-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/unnamed-chunk-17-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/unnamed-chunk-3-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/unnamed-chunk-4-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/unnamed-chunk-6-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/unnamed-chunk-8-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/unnamed-chunk-9-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions tests/testthat/test-estimate_means.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
if (require("testthat") &&
require("modelbased") &&
require("rstanarm") &&
require("insight") &&
require("emmeans")) {
require("modelbased") &&
require("rstanarm") &&
require("insight") &&
require("emmeans")) {
test_that("estimate_means", {
data <- mtcars
data$gear <- as.factor(data$gear)
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-estimate_slopes.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
if (require("testthat") &&
require("modelbased") &&
require("rstanarm") &&
require("insight") &&
require("emmeans")) {
require("modelbased") &&
require("rstanarm") &&
require("insight") &&
require("emmeans")) {
test_that("estimate_slopes", {
model <- lm(Sepal.Width ~ Species * Petal.Length, data = iris)

Expand Down

0 comments on commit 74a79c6

Please sign in to comment.