Closed aravindhebbali closed 3 years ago
# load libraries
library(readxl)
library(olsrr)
#>
#> Attaching package: 'olsrr'
#> The following object is masked from 'package:datasets':
#>
#> rivers
# data
ccpp <- read_excel("J:/R/blog_research/data.xlsx")
# model
model <- lm(PE ~ AT + V + AP + RH, data = ccpp)
# variable selection
# forward selection
ols_step_forward_p(model, penter = 0.3)
#>
#> Selection Summary
#> -----------------------------------------------------------------------------
#> Variable Adj.
#> Step Entered R-Square R-Square C(p) AIC RMSE
#> -----------------------------------------------------------------------------
#> 1 AT 0.8989 0.8989 3988.7509 59518.4764 5.4251
#> 2 RH 0.9209 0.9209 1040.1331 57171.2040 4.7983
#> 3 V 0.9284 0.9284 46.0872 56229.2420 4.5674
#> 4 AP 0.9287 0.9287 5.0000 56188.2290 4.5571
#> -----------------------------------------------------------------------------
# both direction
ols_step_both_p(model, pent = 0.05, prem = 0.1)
#>
#> Stepwise Selection Summary
#> -----------------------------------------------------------------------------------------
#> Added/ Adj.
#> Step Variable Removed R-Square R-Square C(p) AIC RMSE
#> -----------------------------------------------------------------------------------------
#> 1 AT addition 0.899 0.899 3988.7510 59518.4764 5.4251
#> 2 RH addition 0.921 0.921 1040.1330 57171.2040 4.7983
#> 3 V addition 0.928 0.928 46.0870 56229.2420 4.5674
#> 4 AP addition 0.929 0.929 5.0000 56188.2290 4.5571
#> -----------------------------------------------------------------------------------------
# backward selection
ols_step_backward_p(model)
#> [1] "No variables have been removed from the model."
Created on 2020-12-31 by the reprex package (v0.3.0)
Thanks to Serhat Akay for sharing the below reprex and bringing this issue to our notice.