interval_groups {dvmisc} | R Documentation |
Split Continuous Variable into Equal-Width Groups
Description
Splits a continuous variable into equal-width groups. Useful for assessing linearity in regression models.
Usage
interval_groups(x, groups = 5, ...)
Arguments
x |
Numeric vector. |
groups |
Numeric value specifying number of groups to create. |
... |
Arguments to pass to |
Value
Factor variable.
See Also
Examples
# Convert values from N(0, 1) into 6 equal-width groups
x <- rnorm(1000)
groups <- interval_groups(x, 6)
table(groups)
# Use interval_groups to detect non-linearity
set.seed(123)
x <- rnorm(1000)
y <- 1.5 + 1.25 * x + 0.25 * x^2 + rnorm(1000)
plot(tapply(y, interval_groups(x), mean))
[Package dvmisc version 1.1.4 Index]