1
$\begingroup$

I have a dataset with 6 features and build simple linear regression with one feature at a time. I considered Adjusted R-squared values and p-values to compare and determine the best simple linear regression model among those models.

# Model-1
M1X1 <- lm(YHousePriceOfUnitArea ~ X1TransactionDate, 
              data=rev_data_clean)
summary(M1X1)

M1X2 <- lm(YHousePriceOfUnitArea ~ X2HouseAge, data=rev_data_clean)
summary(M1X2)

M1X3 <- lm(YHousePriceOfUnitArea ~ X3distanceToTheNearestMRTstation, 
            data=rev_data_clean)
summary(M1X3)

M1X4 <- lm(YHousePriceOfUnitArea ~ X4NumberOfConvenienceStores, 
            data=rev_data_clean)
summary(M1X4)

M1X5 <- lm(YHousePriceOfUnitArea ~ X5Latitude, data=rev_data_clean)
summary(M1X5)

M1X6 <- lm(YHousePriceOfUnitArea ~ X6Longitude, data=rev_data_clean)
summary(M1X6)

# Comparing the best version of model-1
summary(M1X1)$adj.r.squared
summary(M1X2)$adj.r.squared
summary(M1X3)$adj.r.squared
summary(M1X4)$adj.r.squared
summary(M1X5)$adj.r.squared
summary(M1X6)$adj.r.squared

# p-values for versions of model-1
summary(M1X1)$coefficients[2, 4]
summary(M1X2)$coefficients[2, 4]
summary(M1X3)$coefficients[2, 4]
summary(M1X4)$coefficients[2, 4]
summary(M1X5)$coefficients[2, 4]
summary(M1X6)$coefficients[2, 4]

Console output:

# Comparing the best version of model-1
> summary(M1X1)$adj.r.squared
[1] 0.005246001
> summary(M1X2)$adj.r.squared
[1] 0.04201891
> summary(M1X3)$adj.r.squared
[1] 0.4524284
> summary(M1X4)$adj.r.squared
[1] 0.3244108
> summary(M1X5)$adj.r.squared
[1] 0.2967482
> summary(M1X6)$adj.r.squared
[1] 0.2720662
> 
> # p-values for versions of model-1
> summary(M1X1)$coefficients[2, 4]
[1] 0.07537113
> summary(M1X2)$coefficients[2, 4]
[1] 1.560426e-05
> summary(M1X3)$coefficients[2, 4]
[1] 4.639825e-56
> summary(M1X4)$coefficients[2, 4]
[1] 3.413483e-37
> summary(M1X5)$coefficients[2, 4]
[1] 1.387761e-33
> summary(M1X6)$coefficients[2, 4]
[1] 1.765191e-30

My comparison: If the Adjusted R-squared value is more and p-value is less, then that model is the better one. I this case, with higher Adjusted R-squared value and lower p-value M1X3 model seems to be the best one.

I want to confirm, whether my comparison is wright or wrong.

$\endgroup$
0

2 Answers 2

3
$\begingroup$

G_Grothendieck showed a better way to code this, if this is really what you want to do.

$R^2$ is certainly a reasonable measure of how good a model is. If all your models have the same number of variables, then you don't need to adjust, and the original $R^2$ has some nice intuition. It is also directly inversely related to p value, so, if you look at one, you don't need to look at the other.

Why only one variable? If your end-goal is a multiple regression, then this is not the way to get there.

$\endgroup$
2
$\begingroup$

This can be formulated as a best subsets problem with size 1. There are a number of R packages on CRAN for that including abess and olsrr. Both have vignettes and a reference manual (help files) for more info.

library(abess)
ab <- abess(mpg ~ ., data = mtcars, support.size = 1)
ab
coef(ab)

library(olsrr)
fm <- lm(mpg ~., data = mtcars)
ols_step_best_subset(fm, max_order = 1)
$\endgroup$
2
  • $\begingroup$ That's certainly a better way to code this. But I think the OP is asking if this is the right thing to do. $\endgroup$
    – Peter Flom
    Commented Sep 22 at 11:38
  • 3
    $\begingroup$ That may be literally what is being asked but that begs the question of how one really should proceed. abess solves a constrained least squares problem that forces the number of non-zero non-intercept coefficients to be that specified. olsrr supports multiple metrics and in any case reports on them all. Both can handle more than one predictor if one wants to go further as well as certain plots. Also note that this was originally posted on stackoverflow, not here, and someone else, not the poster, migrated it here. $\endgroup$ Commented Sep 22 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.