This function is an alias (another name) for the insight::get_datagrid()
function. Same arguments apply.
Usage
visualisation_matrix(x, ...)
# S3 method for data.frame
visualisation_matrix(
x,
at = "all",
target = NULL,
factors = "reference",
numerics = "mean",
preserve_range = FALSE,
reference = x,
...
)
# S3 method for numeric
visualisation_matrix(x, ...)
# S3 method for factor
visualisation_matrix(x, ...)
Arguments
- x
An object from which to construct the reference grid.
- ...
Arguments passed to or from other methods (for instance,
length
orrange
to control the spread of numeric variables.).- at
Can be
"all"
, a character vector or list of named elements, indicating the predictors of interest (focal predictors). Can also contain assignments (as named list, e.g.at = list(c(Sepal.Length = c(2, 4), Species = "setosa"))
, or as string, e.g.at = "Sepal.Length = 2"
orat = c("Sepal.Length = 2", "Species = 'setosa'")
- note the usage of single and double quotes to assign strings within strings). The remaining variables will be fixed.- target
Deprecated name. Please use
at
instead.- factors
Type of summary for factors. Can be
"reference"
(set at the reference level),"mode"
(set at the most common level) or"all"
to keep all levels.- numerics
Type of summary for numeric values. Can be
"all"
(will duplicate the grid for all unique values), any function ("mean"
,"median"
, ...) or a value (e.g.,numerics = 0
).- preserve_range
In the case of combinations between numeric variables and factors, setting
preserve_range = TRUE
will drop the observations where the value of the numeric variable is originally not present in the range of its factor level. This leads to an unbalanced grid. Also, if you want the minimum and the maximum to closely match the actual ranges, you should increase thelength
argument.- reference
The reference vector from which to compute the mean and SD. Used when standardizing or unstandardizing the grid using
effectsize::standardize
.
Examples
library(modelbased)
# Add one row to change the "mode" of Species
data <- rbind(iris, iris[149, ], make.row.names = FALSE)
# Single variable is of interest; all others are "fixed"
visualisation_matrix(data, at = "Sepal.Length")
#> Visualisation Grid
#>
#> Sepal.Length | Sepal.Width | Petal.Length | Petal.Width | Species
#> -----------------------------------------------------------------
#> 4.30 | 3.06 | 3.77 | 1.21 | setosa
#> 4.70 | 3.06 | 3.77 | 1.21 | setosa
#> 5.10 | 3.06 | 3.77 | 1.21 | setosa
#> 5.50 | 3.06 | 3.77 | 1.21 | setosa
#> 5.90 | 3.06 | 3.77 | 1.21 | setosa
#> 6.30 | 3.06 | 3.77 | 1.21 | setosa
#> 6.70 | 3.06 | 3.77 | 1.21 | setosa
#> 7.10 | 3.06 | 3.77 | 1.21 | setosa
#> 7.50 | 3.06 | 3.77 | 1.21 | setosa
#> 7.90 | 3.06 | 3.77 | 1.21 | setosa
#>
#> Maintained constant: Sepal.Width, Petal.Length, Petal.Width, Species
visualisation_matrix(data, at = "Sepal.Length", length = 3)
#> Visualisation Grid
#>
#> Sepal.Length | Sepal.Width | Petal.Length | Petal.Width | Species
#> -----------------------------------------------------------------
#> 4.30 | 3.06 | 3.77 | 1.21 | setosa
#> 6.10 | 3.06 | 3.77 | 1.21 | setosa
#> 7.90 | 3.06 | 3.77 | 1.21 | setosa
#>
#> Maintained constant: Sepal.Width, Petal.Length, Petal.Width, Species
visualisation_matrix(data, at = "Sepal.Length", range = "ci", ci = 0.90)
#> Visualisation Grid
#>
#> Sepal.Length | Sepal.Width | Petal.Length | Petal.Width | Species
#> -----------------------------------------------------------------
#> 4.60 | 3.06 | 3.77 | 1.21 | setosa
#> 4.89 | 3.06 | 3.77 | 1.21 | setosa
#> 5.19 | 3.06 | 3.77 | 1.21 | setosa
#> 5.48 | 3.06 | 3.77 | 1.21 | setosa
#> 5.78 | 3.06 | 3.77 | 1.21 | setosa
#> 6.07 | 3.06 | 3.77 | 1.21 | setosa
#> 6.37 | 3.06 | 3.77 | 1.21 | setosa
#> 6.66 | 3.06 | 3.77 | 1.21 | setosa
#> 6.96 | 3.06 | 3.77 | 1.21 | setosa
#> 7.25 | 3.06 | 3.77 | 1.21 | setosa
#>
#> Maintained constant: Sepal.Width, Petal.Length, Petal.Width, Species
visualisation_matrix(data, at = "Sepal.Length", factors = "mode")
#> Visualisation Grid
#>
#> Sepal.Length | Sepal.Width | Petal.Length | Petal.Width | Species
#> -------------------------------------------------------------------
#> 4.30 | 3.06 | 3.77 | 1.21 | virginica
#> 4.70 | 3.06 | 3.77 | 1.21 | virginica
#> 5.10 | 3.06 | 3.77 | 1.21 | virginica
#> 5.50 | 3.06 | 3.77 | 1.21 | virginica
#> 5.90 | 3.06 | 3.77 | 1.21 | virginica
#> 6.30 | 3.06 | 3.77 | 1.21 | virginica
#> 6.70 | 3.06 | 3.77 | 1.21 | virginica
#> 7.10 | 3.06 | 3.77 | 1.21 | virginica
#> 7.50 | 3.06 | 3.77 | 1.21 | virginica
#> 7.90 | 3.06 | 3.77 | 1.21 | virginica
#>
#> Maintained constant: Sepal.Width, Petal.Length, Petal.Width, Species
# Multiple variables are of interest, creating a combination
visualisation_matrix(data, at = c("Sepal.Length", "Species"), length = 3)
#> Visualisation Grid
#>
#> Sepal.Length | Species | Sepal.Width | Petal.Length | Petal.Width
#> --------------------------------------------------------------------
#> 4.30 | setosa | 3.06 | 3.77 | 1.21
#> 6.10 | setosa | 3.06 | 3.77 | 1.21
#> 7.90 | setosa | 3.06 | 3.77 | 1.21
#> 4.30 | versicolor | 3.06 | 3.77 | 1.21
#> 6.10 | versicolor | 3.06 | 3.77 | 1.21
#> 7.90 | versicolor | 3.06 | 3.77 | 1.21
#> 4.30 | virginica | 3.06 | 3.77 | 1.21
#> 6.10 | virginica | 3.06 | 3.77 | 1.21
#> 7.90 | virginica | 3.06 | 3.77 | 1.21
#>
#> Maintained constant: Sepal.Width, Petal.Length, Petal.Width
visualisation_matrix(data, at = c(1, 3), length = 3)
#> Visualisation Grid
#>
#> Sepal.Length | Petal.Length | Sepal.Width | Petal.Width | Species
#> -----------------------------------------------------------------
#> 4.30 | 1.00 | 3.06 | 1.21 | setosa
#> 6.10 | 1.00 | 3.06 | 1.21 | setosa
#> 7.90 | 1.00 | 3.06 | 1.21 | setosa
#> 4.30 | 3.95 | 3.06 | 1.21 | setosa
#> 6.10 | 3.95 | 3.06 | 1.21 | setosa
#> 7.90 | 3.95 | 3.06 | 1.21 | setosa
#> 4.30 | 6.90 | 3.06 | 1.21 | setosa
#> 6.10 | 6.90 | 3.06 | 1.21 | setosa
#> 7.90 | 6.90 | 3.06 | 1.21 | setosa
#>
#> Maintained constant: Sepal.Width, Petal.Width, Species
visualisation_matrix(data, at = c("Sepal.Length", "Species"), preserve_range = TRUE)
#> Visualisation Grid
#>
#> Sepal.Length | Species | Sepal.Width | Petal.Length | Petal.Width
#> --------------------------------------------------------------------
#> 4.30 | setosa | 3.06 | 3.77 | 1.21
#> 4.70 | setosa | 3.06 | 3.77 | 1.21
#> 5.10 | setosa | 3.06 | 3.77 | 1.21
#> 5.50 | setosa | 3.06 | 3.77 | 1.21
#> 5.10 | versicolor | 3.06 | 3.77 | 1.21
#> 5.50 | versicolor | 3.06 | 3.77 | 1.21
#> 5.90 | versicolor | 3.06 | 3.77 | 1.21
#> 6.30 | versicolor | 3.06 | 3.77 | 1.21
#> 6.70 | versicolor | 3.06 | 3.77 | 1.21
#> 5.10 | virginica | 3.06 | 3.77 | 1.21
#> 5.50 | virginica | 3.06 | 3.77 | 1.21
#> 5.90 | virginica | 3.06 | 3.77 | 1.21
#> 6.30 | virginica | 3.06 | 3.77 | 1.21
#> 6.70 | virginica | 3.06 | 3.77 | 1.21
#> 7.10 | virginica | 3.06 | 3.77 | 1.21
#> 7.50 | virginica | 3.06 | 3.77 | 1.21
#> 7.90 | virginica | 3.06 | 3.77 | 1.21
#>
#> Maintained constant: Sepal.Width, Petal.Length, Petal.Width
visualisation_matrix(data, at = c("Sepal.Length", "Species"), numerics = 0)
#> Visualisation Grid
#>
#> Sepal.Length | Species | Sepal.Width | Petal.Length | Petal.Width
#> --------------------------------------------------------------------
#> 4.30 | setosa | 0 | 0 | 0
#> 4.70 | setosa | 0 | 0 | 0
#> 5.10 | setosa | 0 | 0 | 0
#> 5.50 | setosa | 0 | 0 | 0
#> 5.90 | setosa | 0 | 0 | 0
#> 6.30 | setosa | 0 | 0 | 0
#> 6.70 | setosa | 0 | 0 | 0
#> 7.10 | setosa | 0 | 0 | 0
#> 7.50 | setosa | 0 | 0 | 0
#> 7.90 | setosa | 0 | 0 | 0
#> 4.30 | versicolor | 0 | 0 | 0
#> 4.70 | versicolor | 0 | 0 | 0
#> 5.10 | versicolor | 0 | 0 | 0
#> 5.50 | versicolor | 0 | 0 | 0
#> 5.90 | versicolor | 0 | 0 | 0
#> 6.30 | versicolor | 0 | 0 | 0
#> 6.70 | versicolor | 0 | 0 | 0
#> 7.10 | versicolor | 0 | 0 | 0
#> 7.50 | versicolor | 0 | 0 | 0
#> 7.90 | versicolor | 0 | 0 | 0
#> 4.30 | virginica | 0 | 0 | 0
#> 4.70 | virginica | 0 | 0 | 0
#> 5.10 | virginica | 0 | 0 | 0
#> 5.50 | virginica | 0 | 0 | 0
#> 5.90 | virginica | 0 | 0 | 0
#> 6.30 | virginica | 0 | 0 | 0
#> 6.70 | virginica | 0 | 0 | 0
#> 7.10 | virginica | 0 | 0 | 0
#> 7.50 | virginica | 0 | 0 | 0
#> 7.90 | virginica | 0 | 0 | 0
#>
#> Maintained constant: Sepal.Width, Petal.Length, Petal.Width
visualisation_matrix(data, at = c("Sepal.Length = 3", "Species"))
#> Visualisation Grid
#>
#> Sepal.Length | Species | Sepal.Width | Petal.Length | Petal.Width
#> --------------------------------------------------------------------
#> 3 | setosa | 3.06 | 3.77 | 1.21
#> 3 | versicolor | 3.06 | 3.77 | 1.21
#> 3 | virginica | 3.06 | 3.77 | 1.21
#>
#> Maintained constant: Sepal.Width, Petal.Length, Petal.Width
visualisation_matrix(data, at = c("Sepal.Length = c(3, 1)", "Species = 'setosa'"))
#> Visualisation Grid
#>
#> Sepal.Length | Species | Sepal.Width | Petal.Length | Petal.Width
#> -----------------------------------------------------------------
#> 3 | setosa | 3.06 | 3.77 | 1.21
#> 1 | setosa | 3.06 | 3.77 | 1.21
#>
#> Maintained constant: Sepal.Width, Petal.Length, Petal.Width
# with list-style at-argument
visualisation_matrix(data, at = list(Sepal.Length = c(1, 3), Species = "setosa"))
#> Visualisation Grid
#>
#> Sepal.Length | Species | Sepal.Width | Petal.Length | Petal.Width
#> -----------------------------------------------------------------
#> 1 | setosa | 3.06 | 3.77 | 1.21
#> 3 | setosa | 3.06 | 3.77 | 1.21
#>
#> Maintained constant: Sepal.Width, Petal.Length, Petal.Width
# Standardize
vizdata <- visualisation_matrix(data, at = "Sepal.Length")
standardize(vizdata)
#> Visualisation Grid
#>
#> Sepal.Length | Sepal.Width | Petal.Length | Petal.Width | Species
#> -----------------------------------------------------------------
#> -1.87 | 0 | 0 | 0 | setosa
#> -1.39 | 0 | 0 | 0 | setosa
#> -0.90 | 0 | 0 | 0 | setosa
#> -0.42 | 0 | 0 | 0 | setosa
#> 0.07 | 0 | 0 | 0 | setosa
#> 0.55 | 0 | 0 | 0 | setosa
#> 1.03 | 0 | 0 | 0 | setosa
#> 1.52 | 0 | 0 | 0 | setosa
#> 2.00 | 0 | 0 | 0 | setosa
#> 2.49 | 0 | 0 | 0 | setosa
#>
#> Maintained constant: Sepal.Width, Petal.Length, Petal.Width, Species