autoreg: Multiple Linear Regression with Backward Elimination

View source: R/Autoreg.R

autoregR Documentation

Multiple Linear Regression with Backward Elimination

Description

Performs multiple linear regression using backward elimination based on p-value threshold and provides full model diagnostics including ANOVA, multicollinearity, heteroscedasticity, normality test, and plots.

Usage

autoreg(data, threshold = 0.1)

Arguments

data

A data frame containing dependent variable (y) in the first column and independent variables (x's) in remaining columns

threshold

Significance level for variable removal (default = 0.10)

Details

The function starts with a full model and iteratively removes the variable with the highest p-value greater than the specified threshold until all variables are significant.

Value

A list containing:

  • final_model: Final regression model

  • model_summary: Summary of final model

  • selected_variables: Variables retained in final model

  • anova_table: ANOVA table for final model

  • vif: Variance Inflation Factor values (if applicable)

  • gq_test: Goldfeld-Quandt test result

  • shapiro_test: Shapiro-Wilk normality test result

  • actual_vs_fitted: Data frame of actual vs fitted values

Examples

{
library(car)
library(lmtest)

set.seed(123)
n <- 40

x1 <- rnorm(n, 50, 10)
x2 <- rnorm(n, 30, 5)
x3 <- rnorm(n, 70, 15)
x4 <- rnorm(n, 20, 7)
x5 <- rnorm(n, 100, 20)
x6 <- rnorm(n, 10, 3)

y <- 0.5*x1 - 0.3*x2 + 0.2*x3 +
     0.1*x4 - 0.05*x5 + 0.3*x6 +
     rnorm(n, 0, 15)

df <- data.frame(y, x1, x2, x3, x4, x5, x6)

result <- autoreg(df, threshold = 0.10)
result$selected_variables
}

linreg documentation built on April 17, 2026, 1:07 a.m.

Related to autoreg in linreg...