This function takes user inputs, creates a data frame, fits a linear model, and plots the output. The function can take 4 optional arguments that adjust the relationship between x and y. The purpose of this function is to help teach the linear model.
lm_ex(
n = 100,
intercept = 50,
slope = 10,
sigma = 0.5,
custAxis = FALSE,
xlim = NULL,
ylim = NULL,
base_size = 20,
text_size = 5
)
Number of observations
The y-intercept
The slope the line
Spread around the mean
Logical. Set to true to use custom xlim/ylim
Vector for x axis, 'custAxis' must be TRUE.
Vector for y axis, 'custAxis' must be TRUE.
Numeric value to adjust plot text size
Numeric value to adjust annotation text size
# 'y' as a function of 'x' with 100 observations, intercept
# of 50, slope of 10, and sigma at 0.5
lm_ex()
# Negative slope
lm_ex(n = 55, intercept = 25, slope = -5, sigma = 0.75)