Learn R Programming

olsrr

Overview

The olsrr package provides following tools for building OLS regression models using R:

  • Comprehensive Regression Output
  • Variable Selection Procedures
  • Heteroskedasticity Tests
  • Collinearity Diagnostics
  • Model Fit Assessment
  • Measures of Influence
  • Residual Diagnostics
  • Variable Contribution Assessment

Installation

# Install release version from CRAN
install.packages("olsrr")

# Install development version from GitHub
# install.packages("pak")
pak::pak("rsquaredacademy/olsrr")

Articles

Usage

olsrr uses consistent prefix ols_ for easy tab completion. If you know how to write a formula or build models using lm, you will find olsrr very useful. Most of the functions use an object of class lm as input. So you just need to build a model using lm and then pass it onto the functions in olsrr. Below is a quick demo:

Regression

model <- lm(mpg ~ disp + hp + wt + qsec, data = mtcars)
ols_regress(model)
#>                          Model Summary                          
#> ---------------------------------------------------------------
#> R                       0.914       RMSE                 2.409 
#> R-Squared               0.835       MSE                  6.875 
#> Adj. R-Squared          0.811       Coef. Var           13.051 
#> Pred R-Squared          0.771       AIC                159.070 
#> MAE                     1.858       SBC                167.864 
#> ---------------------------------------------------------------
#>  RMSE: Root Mean Square Error 
#>  MSE: Mean Square Error 
#>  MAE: Mean Absolute Error 
#>  AIC: Akaike Information Criteria 
#>  SBC: Schwarz Bayesian Criteria 
#> 
#>                                ANOVA                                 
#> --------------------------------------------------------------------
#>                 Sum of                                              
#>                Squares        DF    Mean Square      F         Sig. 
#> --------------------------------------------------------------------
#> Regression     940.412         4        235.103    34.195    0.0000 
#> Residual       185.635        27          6.875                     
#> Total         1126.047        31                                    
#> --------------------------------------------------------------------
#> 
#>                                   Parameter Estimates                                    
#> ----------------------------------------------------------------------------------------
#>       model      Beta    Std. Error    Std. Beta      t        Sig      lower     upper 
#> ----------------------------------------------------------------------------------------
#> (Intercept)    27.330         8.639                  3.164    0.004     9.604    45.055 
#>        disp     0.003         0.011        0.055     0.248    0.806    -0.019     0.025 
#>          hp    -0.019         0.016       -0.212    -1.196    0.242    -0.051     0.013 
#>          wt    -4.609         1.266       -0.748    -3.641    0.001    -7.206    -2.012 
#>        qsec     0.544         0.466        0.161     1.166    0.254    -0.413     1.501 
#> ----------------------------------------------------------------------------------------

Getting Help

If you encounter a bug, please file a minimal reproducible example using reprex on github. For questions and clarifications, use StackOverflow.

Code of Conduct

Please note that the olsrr project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Copy Link

Version

Install

install.packages('olsrr')

Monthly Downloads

15,116

Version

0.6.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

February 12th, 2024

Functions in olsrr (0.6.0)

auto

Test Data Set
fitness

Test Data Set
ols_hsp

Hocking's Sp
cement

Test Data Set
ols_msep

MSEP
hsb

Test Data Set
ols_plot_added_variable

Added variable plots
ols_plot_hadi

Hadi plot
ols_plot_cooksd_chart

Cooks' D chart
ols_plot_dfbetas

DFBETAs panel
ols_plot_obs_fit

Observed vs fitted values plot
ols_launch_app

Launch shiny app
ols_plot_reg_line

Simple linear regression line
ols_plot_resid_pot

Potential residual plot
ols_plot_resid_qq

Residual QQ plot
ols_aic

Akaike information criterion
ols_coll_diag

Collinearity diagnostics
ols_plot_resid_box

Residual box plot
ols_correlations

Part and partial correlations
ols_prep_regress_y

Regress y on other predictors
ols_apc

Amemiya's prediction criterion
ols_prep_rfsplot_fmdata

Residual fit spread plot data
ols_plot_comp_plus_resid

Residual plus component plot
ols_plot_dffits

DFFITS plot
ols_plot_cooksd_bar

Cooks' D bar plot
ols_prep_rstudlev_data

Studentized residual vs leverage plot data
ols_plot_diagnostics

Diagnostics panel
ols_plot_resid_hist

Residual histogram
ols_plot_response

Response variable profile
ols_pred_rsq

Predicted rsquare
ols_step_all_possible_betas

All possible regression variable coefficients
ols_prep_rvsrplot_data

Residual vs regressor plot data
ols_regress

Ordinary least squares regression
ols_plot_resid_regressor

Residual vs regressor plot
ols_step_backward_adj_r2

Stepwise Adjusted R-Squared backward regression
ols_plot_resid_lev

Studentized residuals vs leverage plot
ols_plot_resid_stud

Studentized residual plot
ols_sbc

Bayesian information criterion
ols_fpe

Final prediction error
ols_plot_resid_stand

Standardized residual chart
ols_step_both_adj_r2

Stepwise Adjusted R-Squared regression
ols_plot_resid_stud_fit

Deleted studentized residual vs fitted values plot
ols_prep_cdplot_outliers

Cooks' d outlier data
ols_prep_dfbeta_data

DFBETAs plot data
ols_prep_srchart_data

Standardized residual chart data
ols_step_both_aic

Stepwise AIC regression
ols_test_bartlett

Bartlett test
ols_hadi

Hadi's influence measure
ols_press

PRESS
ols_pure_error_anova

Lack of fit F test
ols_step_backward_r2

Stepwise R-Squared backward regression
ols_prep_dfbeta_outliers

DFBETAs plot outliers
ols_step_backward_sbc

Stepwise SBC backward regression
ols_step_forward_p

Stepwise forward regression
ols_step_forward_r2

Stepwise R-Squared forward regression
ols_leverage

Leverage
ols_prep_srplot_data

Studentized residual plot data
rivers

Test Data Set
ols_mallows_cp

Mallow's Cp
ols_prep_dsrvf_data

Deleted studentized residual plot data
ols_plot_resid_fit

Residual vs fitted plot
ols_plot_resid_fit_spread

Residual fit spread plot
rvsr_plot_shiny

Residual vs regressors plot for shiny app
ols_prep_avplot_data

Added variable plot data
ols_prep_cdplot_data

Cooks' D plot data
ols_step_backward_sbic

Stepwise SBIC backward regression
ols_step_both_p

Stepwise regression
ols_step_best_subset

Best subsets regression
ols_step_forward_adj_r2

Stepwise Adjusted R-Squared forward regression
ols_step_forward_aic

Stepwise AIC forward regression
ols_test_breusch_pagan

Breusch pagan test
ols_test_normality

Test for normality
ols_test_score

Score test
ols_step_both_r2

Stepwise R-Squared regression
olsrr

olsrr package
ols_step_forward_sbc

Stepwise SBC forward regression
ols_step_forward_sbic

Stepwise SBIC forward regression
stepdata

Test Data Set
surgical

Surgical Unit Data Set
ols_prep_outlier_obs

Cooks' D outlier observations
ols_prep_regress_x

Regress predictor on other predictors
ols_sbic

Sawa's bayesian information criterion
ols_step_all_possible

All possible regression
ols_test_outlier

Bonferroni Outlier Test
ols_step_backward_aic

Stepwise AIC backward regression
ols_step_backward_p

Stepwise backward regression
ols_step_both_sbc

Stepwise SBC regression
ols_step_both_sbic

Stepwise SBIC regression
ols_test_correlation

Correlation test for normality
ols_test_f

F test