Create a reference matrix, useful for visualisation, with evenly spread and combined values.

visualisation_matrix(x, ...)

# S3 method for data.frame
visualisation_matrix(
  x,
  target = "all",
  factors = "reference",
  numerics = "mean",
  preserve_range = FALSE,
  reference = x,
  ...
)

# S3 method for numeric
visualisation_matrix(x, length = 10, range = "range", ...)

# 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 or range to control the spread of numeric variables.).

target

Can be "all" or list of characters indicating columns of interest. Can also contain assignments (e.g., target = "Sepal.Length = 2" or target = 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.

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 the length argument.

reference

The reference vector from which to compute the mean and SD.

length

Length of numeric target variables.

range

Can be one of c("range", "iqr", "ci", "hdi", "eti"). If "range" (default), will use the min and max of the original vector as end-points. If any other interval, will spread within the range (the default CI width is 95% but this can be changed by setting something else, e.g., ci = 0.90). See IQR and ci.

Value

Reference grid data frame.

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, target = "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, target = "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, target = "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, target = "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, target = 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, target = 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, target = 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, target = 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, target = 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, target = 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

# Standardize
vizdata <- visualisation_matrix(data, target = "Sepal.Length")
effectsize::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