Learn R Programming

LSTbook (version 0.6)

random_terms: Create columns with random numbers for modeling

Description

For demonstration purposes, add the specified number of random columns to a model matrix. This is intended to be used in modeling functions, e.g. model_train(), lm(), and so on to explore the extent to which random columns "explain" the response variable.

Usage

random_terms(df = 1, rdist = rnorm, args = list(), n, seed = NULL)

Arguments

df

How many columns to add

rdist

Function to generate each column's numbers (default: rnorm)

args

A list holding the parameters (if any) to be used for the rdist argument

n

OPTIONALLY, dictate the number of rows in the output

seed

Integer seed for the random-number generator

Details

random_terms() will try to guess a suitable value for n based on the calling function.

Examples

Run this code
 mtcars |> model_train(mpg ~ wt + random_terms(4)) |> conf_interval()
 mtcars |> model_train(mpg ~ wt + random_terms(4)) |> anova_summary()
 head(mtcars) |> select(wt, mpg) |> mutate(r = random_terms(3))

Run the code above in your browser using DataLab