Learn R Programming

modelbased (version 0.7.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, ...)

# 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

Run this code
# NOT RUN {
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_matrix(data, target = "Sepal.Length", length = 3)
visualisation_matrix(data, target = "Sepal.Length", range = "ci", ci = 0.90)
visualisation_matrix(data, target = "Sepal.Length", factors = "mode")

# Multiple variables are of interest, creating a combination
visualisation_matrix(data, target = c("Sepal.Length", "Species"), length = 3)
visualisation_matrix(data, target = c(1, 3), length = 3)
visualisation_matrix(data, target = c("Sepal.Length", "Species"), preserve_range = TRUE)
visualisation_matrix(data, target = c("Sepal.Length", "Species"), numerics = 0)
visualisation_matrix(data, target = c("Sepal.Length = 3", "Species"))
visualisation_matrix(data, target = c("Sepal.Length = c(3, 1)", "Species = 'setosa'"))

# Standardize
vizdata <- visualisation_matrix(data, target = "Sepal.Length")
effectsize::standardize(vizdata)
# }

Run the code above in your browser using DataLab