lm_plot: Create a Plot with Linear Regression and...

View source: R/lm_plot.R

lm_plotR Documentation

Create a Plot with Linear Regression and Confidence/Prediction Intervals

Description

Generates a ggplot2 plot that includes the observed data, a simple linear regression line, and both confidence and prediction interval bands.

Arguments

lm_model

A simple linear regression model object created by lm().

conf.level

A numeric value indicating the confidence level for the confidence interval bands and prediction interval bands. Default is 0.95.

install_packages

Logical, indicating whether required packages should be automatically installed if not already available. Default is TRUE.

Value

A ggplot2 plot object featuring the observations, the simple linear regression line, the confidence interval bands, and the prediction interval bands.

Examples

# Example dataset
data <- data.frame(
  x = rnorm(100, mean = 50, sd = 10),
  y = 3 + 0.5 * rnorm(100, mean = 50, sd = 10) + rnorm(100)
)

# Run a regression model
my_model <- lm(y~x, data)

# Create plot with regression line, confidence limits, and prediction limits
lm_plot(my_model)

# Customize plot labels
lm_plot(my_model) + xlab("Your x-axis label") + ylab("Your y-axis label")

biostats101 documentation built on Sept. 13, 2024, 1:11 a.m.