I tried to create linear regression model with multiple variable, this is my sample data and code:
set.seed(1234421234)
x1 <- round(rnorm(1500), 2)
x2 <- round(rnorm(1500) - 0.1 * x1, 2)
x3 <- round(rnorm(1500) + 0.1 * x1 - 0.5 * x2, 2)
x4 <- round(rnorm(1500) - 0.4 * x2 - 0.1 * x3, 2)
x5 <- round(rnorm(1500) + 0.1 * x1 - 0.2 * x3, 2)
x6 <- round(rnorm(1500) - 0.3 * x4 - 0.1 * x5, 2)
y <- round(rnorm(1500) + 0.5 * x1 + 0.5 * x2 + 0.15 * x3 - 0.4 * x4 - 0.25 * x5 - 0.1 * x6, 2)
data <- data.frame(y, x1, x2, x3, x4, x5, x6)
mod_summary <- summary(lm(y ~ ., data))
mod_summary
Is there any way that we can extract and print important coefficients (predictors) name automatically based on condition : Pr(>|t|) < 0.01 and sort the top n of coefficients (predictors)?
thank you