rsquaredacademy / olsrr

Tools for developing OLS regression models
https://olsrr.rsquaredacademy.com/
Other
102 stars 23 forks source link

Retrieving 'F' and 'Sig.' values when using 'ols_stepwise' function #50

Closed elielw closed 6 years ago

elielw commented 6 years ago

Is it possible to retrieve these values? I can only find R-square, AIC, etc, but not F and Sig.

aravindhebbali commented 6 years ago

hi @elielw , are you suggesting something similar to this issue. May be ols_stepwise() can return a tibble with F and Sig. for each predictor after each step.

elielw commented 6 years ago

Yes I think it's similar to this issue

aravindhebbali commented 6 years ago

hi @elielw, let me know if the below fix works.

library(olsrr)
#> 
#> Attaching package: 'olsrr'
#> The following object is masked from 'package:datasets':
#> 
#>     rivers

# model
fit1 <- lm(y ~ ., olsrr::stepdata)

# stepwise
k <- ols_stepwise(fit1)
#> Stepwise Selection Method   
#> ---------------------------
#> 
#> Candidate Terms: 
#> 
#> 1. x1 
#> 2. x2 
#> 3. x3 
#> 4. x4 
#> 5. x5 
#> 6. x6 
#> 
#> We are selecting variables based on p value...
#> 
#> Variables Entered/Removed: 
#> 
#> - x6 added 
#> - x1 added 
#> - x3 added 
#> - x2 added 
#> - x6 added 
#> - x4 added 
#> 
#> No more variables to be added/removed.
#> 
#> 
#> Final Model Output 
#> ------------------
#> 
#>                          Model Summary                           
#> ----------------------------------------------------------------
#> R                       0.866       RMSE                  0.503 
#> R-Squared               0.750       Coef. Var          6430.859 
#> Adj. R-Squared          0.750       MSE                   0.253 
#> Pred R-Squared          0.749       MAE                   0.402 
#> ----------------------------------------------------------------
#>  RMSE: Root Mean Square Error 
#>  MSE: Mean Square Error 
#>  MAE: Mean Absolute Error 
#> 
#>                                    ANOVA                                    
#> ---------------------------------------------------------------------------
#>                  Sum of                                                    
#>                 Squares           DF    Mean Square        F          Sig. 
#> ---------------------------------------------------------------------------
#> Regression    15163.528            4       3790.882    14966.061    0.0000 
#> Residual       5064.705        19995          0.253                        
#> Total         20228.233        19999                                       
#> ---------------------------------------------------------------------------
#> 
#>                                   Parameter Estimates                                   
#> ---------------------------------------------------------------------------------------
#>       model      Beta    Std. Error    Std. Beta      t        Sig      lower    upper 
#> ---------------------------------------------------------------------------------------
#> (Intercept)    -0.005         0.004                 -1.496    0.135    -0.012    0.002 
#>          x1     0.255         0.003        0.362    84.140    0.000     0.249    0.261 
#>          x3     0.253         0.003        0.356    82.604    0.000     0.247    0.259 
#>          x2     0.249         0.003        0.346    80.544    0.000     0.243    0.255 
#>          x4    -0.007         0.004       -0.007    -1.872    0.061    -0.014    0.000 
#> ---------------------------------------------------------------------------------------

# betas and pvalues for each step
k$beta_pval
#> # A tibble: 23 x 4
#>    model predictor       beta                                         pval
#>    <int> <chr>          <dbl>                                        <dbl>
#>  1     1 (Intercept) -0.00365                                    3.56e-  1
#>  2     1 x6           0.233                                      0        
#>  3     2 (Intercept) -0.00418                                    2.83e-  1
#>  4     2 x6           0.201                                      0        
#>  5     2 x1           0.103                                      3.36e-120
#>  6     3 (Intercept) -0.00465                                    2.21e-  1
#>  7     3 x6           0.142                                      0        
#>  8     3 x1           0.148                                      4.41e-230
#>  9     3 x3           0.146                                      5.39e-224
#> 10     4 (Intercept) -0.00535                                    1.33e-  1
#> # ... with 13 more rows
elielw commented 6 years ago

thank you!