This question is basically an extention of something I asked before: How to only print (adjusted) R-squared of regression model?
I want to make a linear regression model to predict concentrations with 150 potential predictors. I want to perform a manual stepwise forward procedure. The dataset looks more or less like this:
df = data.frame(
Site = c("A", "B", "C", "D"),
Concentration = c(2983, 9848, 2894, 8384),
Var1 = c(12, 23, 34, 45),
Var2 = c(23, 34, 45, 56))
I use the following code to make a univariate model for every possible predictor and check the adjusted R-squared.
for (j in names(df)){
model <- lm(Concentration ~ df[[j]], data = df)
print(j)
print(summary(model)$adj.r.squared)
[1] "site"
r.squared adj.r.squared
1 0.02132635 -0.9573473
It is however, a lot of work to check the adjusted R-squared for 150 variables.
Is it possible to either make a dataframe with all adjusted R-squared values and each corresponding variable name?
Or to rank the adjusted R-squared values, so the highest value is first (and corresponding variable name printed with it)?
I am very curious to hear if something like this is possible. It would help me enormously.
Thanks in advance!