Learn R Programming

modelbased (version 0.6.0)

visualisation_matrix: Create a reference grid

Description

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

Usage

visualisation_matrix(
  x,
  target = "all",
  length = 10,
  factors = "reference",
  numerics = "mean",
  preserve_range = FALSE,
  standardize = FALSE,
  standardize_robust = FALSE,
  reference = x,
  na.rm = TRUE,
  ...
)

Arguments

x

An object from which to construct the reference grid.

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.

length

Length of numeric target variables.

factors

Type of summary for factors. Can be "combination" (include all unique values), "reference" (set at the reference level) or "mode" (set at the most common level).

numerics

Type of summary for numeric values. Can be "combination" (include 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 removes observations where the value of the numeric variable is originally not present in the range of its factor level.

standardize

The numeric target value is spread as deviations from the mean, with the central value being the mean (or the median if standardize_robust is TRUE). For instance, if x is a vector of mean 1 and SD 2.5, and a standardized grid is required of length 3, the result will be c(Mean-1*SD, Mean, Mean+1*SD), i.e., c(-1.5, 1, 3.5). Each value represents deviations (in terms of SD or MAD) from the central value. This needs the length argument to be an even integer, so that the central value represent the mean.

standardize_robust

Standardization based on median and MAD (a robust equivalent of the SD).

reference

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

na.rm

Remove NaNs.

...

Arguments passed to or from other methods.

Value

Reference grid data frame.

Examples

Run this code
# NOT RUN {
library(modelbased)

visualisation_matrix(iris, target = "Sepal.Length")
visualisation_matrix(iris, target = "Sepal.Length", factors = "combinations")
visualisation_matrix(iris, target = c("Sepal.Length", "Species"), length = 3)
visualisation_matrix(iris, target = c("Sepal.Length", "Species"), numerics = 0)
visualisation_matrix(iris, target = c("Sepal.Length = 3", "Species"))
visualisation_matrix(iris, target = c("Sepal.Length = c(3, 1)", "Species = 'setosa'"))
visualisation_matrix(iris, target = "Sepal.Length", standardize = TRUE, length = 3)
# }

Run the code above in your browser using DataLab