| autoreg | R Documentation |
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.
autoreg(data, threshold = 0.1)
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) |
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.
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
{
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
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.