values_at: Calculate representative values of a vector

View source: R/moderator_pattern.R

values_atR Documentation

Calculate representative values of a vector

Description

This function calculates representative values of a vector, like minimum/maximum values or lower, median and upper quartile etc., which can be used for numeric vectors to plot adjusted predictions at these representative values.

Usage

values_at(x, values = "meansd")

representative_values(x, values = "meansd")

Arguments

x

A numeric vector.

values

Character vector, naming a pattern for which representative values should be calculcated.

  • ⁠"minmax": ⁠(default) minimum and maximum values (lower and upper bounds) of the moderator are used to plot the interaction between independent variable and moderator.

  • "meansd": uses the mean value of the moderator as well as one standard deviation below and above mean value to plot the effect of the moderator on the independent variable.

  • "zeromax": is similar to the "minmax" option, however, 0 is always used as minimum value for the moderator. This may be useful for predictors that don't have an empirical zero-value, but absence of moderation should be simulated by using 0 as minimum.

  • ⁠"fivenum": ⁠calculates and uses the Tukey's five number summary (minimum, lower-hinge, median, upper-hinge, maximum) of the moderator value.

  • "quart": calculates and uses the quartiles (lower, median and upper) of the moderator value, including minimum and maximum value.

  • "quart2": calculates and uses the quartiles (lower, median and upper) of the moderator value, excluding minimum and maximum value.

  • "terciles": calculates and uses the terciles (lower and upper third) of the moderator value, including minimum and maximum value.

  • "terciles2": calculates and uses the terciles (lower and upper third) of the moderator value, excluding minimum and maximum value.

  • an option to compute a range of percentiles is also possible, using "percentile", followed by the percentage of the range. For example, "percentile95" will calculate the 95% range of the variable.

  • "all": uses all values of the moderator variable.

Value

A numeric vector of length two or three, representing the required values from x, like minimum/maximum value or mean and +/- 1 SD. If x is missing, a function, pre-programmed with n and length is returned. See examples.

Examples

data(efc)
values_at(efc$c12hour)
values_at(efc$c12hour, "quart2")

mean_sd <- values_at(values = "meansd")
mean_sd(efc$c12hour)

ggeffects documentation built on Sept. 12, 2024, 7:41 a.m.