Code
install.packages("olsrr")Aravind Hebbali
November 19, 2026

olsrr 0.7.1 is on CRAN. olsrr provides tools for building and checking ordinary least squares regression models in R: regression summaries, variable selection, heteroskedasticity and normality tests, collinearity diagnostics, influence measures and residual plots, all built around lm() objects.
We don’t usually write about patch releases, but this one deserves a post:
car, lmtest and nortest) for this release.olsrr post since our introduction in 2019, so it also covers what has been added since then.Who should read what: if you report Holm-adjusted Breusch-Pagan \(p\)-values, Cramér–von Mises normality tests or MSE/RMSE from olsrr, read Behaviour changes first. Everyone else can skip to What’s new since 2019.
You can install it from CRAN with:
You can see a full list of changes in the release notes.
These fixes change numbers you may already have in reports. In each case 0.7.1 now agrees with the base R or reference implementation, so the new values are the ones to use.
How we checked: every number in this post was re-run on CRAN olsrr 0.7.0 and 0.7.1, and the release passed an independent audit against base R, car, lmtest and nortest before it was submitted.
With ols_test_breusch_pagan(..., rhs = TRUE, multiple = TRUE, p.adj = "holm"), version 0.7.0 sorted the raw \(p\)-values and multiplied them by reversed ranks without the cumulative-maximum step of Holm’s procedure. A predictor could keep an adjusted \(p\)-value that was too small and be wrongly flagged at \(lpha = 0.05\). Version 0.7.1 uses stats::p.adjust(p, "holm"). In this three-predictor example the raw \(p\)-values are 0.0465, 1.07e-05 and 0.0410:
Breusch Pagan Test for Heteroskedasticity
-----------------------------------------
Ho: the variance is constant
Ha: the variance is not constant
Data
-------------------
Response : y
Variables: x1 x2 x3
Test Summary (Holm's p values)
-------------------------------------------------
Variable chi2 df p
-------------------------------------------------
x1 3.962893 1 8.192284e-02
x2 19.381555 1 3.211077e-05
x3 4.177610 1 8.192284e-02
-------------------------------------------------
simultaneous 21.479644 3 8.369002e-05
-------------------------------------------------
| x1 | 0.0465 |
| x2 | 3.21e-05 |
| x3 | 0.0819 |
| x1 | 0.0819 |
| x2 | 3.21e-05 |
| x3 | 0.0819 |
Same call on both CRAN versions: ols_test_breusch_pagan(m_bp, rhs = TRUE, multiple = TRUE, p.adj = "holm"). Changed values are highlighted.
# Run once with each version, e.g. in two sessions:
# remotes::install_version("olsrr", "0.7.0") # then
# install.packages("olsrr") # 0.7.1
library(olsrr)
set.seed(15)
n <- 60
z <- rnorm(n)
d <- data.frame(x1 = z + rnorm(n), x2 = z + rnorm(n), x3 = z + rnorm(n))
d$y <- rnorm(n) * exp(0.55 * z)
m_bp <- lm(y ~ x1 + x2 + x3, data = d)
ols_test_breusch_pagan(m_bp, rhs = TRUE, multiple = TRUE, p.adj = "holm")$pIn 0.7.0, x1 remained below 0.05 (0.0465) even though x3 had a smaller raw \(p\)-value and adjusted to 0.0819. In 0.7.1, x1 is 0.0819, matching stats::p.adjust().
What to do: re-run any Holm-adjusted Breusch-Pagan tests; the 0.7.1 values match stats::p.adjust().
In 0.7.0, ols_test_normality() compared the Cramér–von Mises statistic with a standard uniform distribution instead of a normal distribution with mean and standard deviation estimated from the residuals, so it rejected normality for almost any regression. Version 0.7.1 calls nortest::cvm.test():
-----------------------------------------------
Test Statistic pvalue
-----------------------------------------------
Shapiro-Wilk 0.9366 0.0600
Kolmogorov-Smirnov 0.1152 0.7464
Cramer-von Mises 0.0764 0.2230
Anderson-Darling 0.5859 0.1188
-----------------------------------------------
| Cramér–von Mises W | 2.8122 |
| p-value | 0.0000 |
| Cramér–von Mises W | 0.0764 |
| p-value | 0.2230 |
Same call on both CRAN versions: ols_test_normality(lm(mpg ~ disp + hp + wt + qsec, mtcars)). Changed values are highlighted.
In 0.7.1, the Cramér–von Mises result (p = 0.2230) agrees with nortest::cvm.test(residuals(model)) and aligns qualitatively with the Shapiro-Wilk (0.0600) and Anderson-Darling (0.1188) tests on the same residuals. (See What’s next about the Kolmogorov-Smirnov row.)
What to do: treat earlier Cramér–von Mises rejections from olsrr as unreliable and re-run the test.
In 0.7.0, ols_regress() and ols_model_performance() divided the residual sum of squares by \(n\) rather than by the residual degrees of freedom (#221, reported by @viqule11). For lm(mpg ~ disp + hp + wt + qsec, data = mtcars) (\(n = 32\), 27 residual degrees of freedom) that gave MSE = 5.8011 and RMSE = 2.4085. Version 0.7.1 reports MSE = 6.8754 and RMSE = 2.6221, matching the ANOVA residual mean square and summary(model)$sigma.
| MSE | 5.8011 |
| RMSE | 2.4085 |
| MSE | 6.8754 |
| RMSE | 2.6221 |
Same call on both CRAN versions: ols_regress(lm(mpg ~ disp + hp + wt + qsec, mtcars)). Changed values are highlighted.
What to do: expect slightly larger MSE and RMSE values; they now match base R.
Between versions 0.6.0 and 0.7.1, the variable selection family expanded to cover \(p\)-values, AIC, SBC (BIC), Sawa’s BIC (sbic), \(R^2\), and adjusted \(R^2\). All forward, backward, and both-direction selectors now accept include and exclude arguments (by name or column index) so baseline covariates or confounders stay in the model throughout selection.
On the surgical dataset, locking age and alc_heavy via include keeps both predictors in the base model (Step 0, AIC = 795.956) and through every subsequent addition and removal step, even though age itself has \(p = 0.473\) in the final fit:
Stepwise Summary
------------------------------------------------------------------------------
Step Variable AIC SBC SBIC R2 Adj. R2
------------------------------------------------------------------------------
0 Base Model 795.956 803.912 637.696 0.17900 0.14680
1 liver_test (+) 763.110 773.055 606.421 0.56938 0.54354
2 enzyme_test (+) 752.416 764.350 596.755 0.65959 0.63180
3 pindex (+) 737.680 751.603 585.012 0.75030 0.72429
4 bcs (+) 732.494 748.406 581.938 0.78142 0.75351
5 liver_test (-) 732.339 746.262 580.934 0.77382 0.75026
------------------------------------------------------------------------------
Final Model Output
------------------
Model Summary
-------------------------------------------------------------------
R 0.880 RMSE 198.590
R-Squared 0.774 MSE 39438.163
Adj. R-Squared 0.750 Coef. Var 28.286
Pred R-Squared 0.688 AIC 732.339
MAE 140.528 SBC 746.262
-------------------------------------------------------------------
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 6476488.730 5 1295297.746 32.844 0.0000
Residual 1893031.807 48 39438.163
Total 8369520.537 53
-----------------------------------------------------------------------
Parameter Estimates
------------------------------------------------------------------------------------------------
model Beta Std. Error Std. Beta t Sig lower upper
------------------------------------------------------------------------------------------------
(Intercept) -1237.653 225.517 -5.488 0.000 -1691.085 -784.221
age -1.787 2.473 -0.050 -0.723 0.473 -6.759 3.184
alc_heavy 306.655 73.188 0.303 4.190 0.000 159.500 453.809
enzyme_test 11.244 1.314 0.601 8.555 0.000 8.601 13.887
pindex 10.062 1.633 0.428 6.163 0.000 6.779 13.344
bcs 81.587 17.870 0.329 4.566 0.000 45.657 117.516
------------------------------------------------------------------------------------------------
ols_plot_diagnostics() gathers ten residual, fit, leverage, and influence views for an lm object: residuals vs fitted values, deleted studentized residuals vs predicted values, studentized residuals vs leverage, normal Q-Q plot, actual vs fitted values, Cook’s D chart, centered fit spread, residual spread, residual histogram, and residual box plot.
Calling ols_plot_diagnostics(model) directly pages the panels in 2×2 grids (and in 0.7.1 draws cleanly inside scripts, functions, and loops as well as at the top level). Setting print_plot = FALSE returns the ten ggplot objects without drawing them first, so they can be arranged in a single layout:
Added in 0.7.0 and refined in 0.7.1, ols_model_performance() reports fit metrics for a single model, while ols_compare_model_performance() places competing models side by side across \(R^2\), adjusted \(R^2\), predicted \(R^2\), AIC, SBC, SBIC, RMSE, and residual standard error (sigma):
name r2 r2_adj r2_pred aic sbc sbic rmse
1 m1 0.8267855 0.8148396 0.7810871 156.6523 162.5153 66.43956 2.593412
2 m2 0.8347678 0.8170643 0.7819955 157.1426 164.4713 67.43259 2.577785
3 m3 0.8351443 0.8107212 0.7710297 159.0696 167.8640 70.04081 2.622095
sigma
1 2.593412
2 2.577785
3 2.622095
ols_regress()In 0.7.1, ols_regress() supports weighted linear models fitted with lm(..., weights = ...), matching base R’s summary(), anova(), and confint() for coefficient estimates, standard errors, \(t\)-statistics, confidence intervals, \(R^2\), residual standard error, the ANOVA table, standardized betas, and weighted predicted \(R^2\):
Model Summary
---------------------------------------------------------------
R 0.917 RMSE 3.876
R-Squared 0.841 MSE 15.027
Adj. R-Squared 0.830 Coef. Var 19.295
Pred R-Squared 0.786 AIC 167.360
MAE 1.953 SBC 173.223
---------------------------------------------------------------
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 2308.267 2 1154.134 76.806 0.0000
Residual 435.769 29 15.027
Total 2744.036 31
--------------------------------------------------------------------
Parameter Estimates
----------------------------------------------------------------------------------------
model Beta Std. Error Std. Beta t Sig lower upper
----------------------------------------------------------------------------------------
(Intercept) 37.938 1.545 24.560 0.000 34.779 41.098
wt -4.102 0.613 -0.666 -6.691 0.000 -5.355 -2.848
hp -0.030 0.008 -0.345 -3.678 0.001 -0.047 -0.013
----------------------------------------------------------------------------------------
ols_press() weights the squared deleted residuals for weighted models, so ols_pred_rsq() no longer moves towards 1 when the weights are rescaled. For the weighted model shown above, multiplying the weights by 10 changed predicted \(R^2\) from 0.9077 to 0.9908 in 0.7.0; in 0.7.1 both are 0.7859.ols_plot_resid_hist() draws the bars with the same breaks as the normal curve. Previously the curve could be drawn at about half its correct height (0.54 of the expected peak for lm(hwy ~ displ + cty + year, data = ggplot2::mpg)).ols_plot_comp_plus_resid() keeps every predictor for single-predictor and no-intercept models; 0.7.0 dropped a column and plotted a single point.ols_test_outlier() caps Bonferroni-adjusted \(p\)-values at 1 (0.7.0 could report values such as 6.62).ols_aic(corrected = TRUE) matches the AICc formula (#224, #170, reported by @comatrion), and Mallows’ \(C_p\) is correct for factor predictors (#92, reported by @cccfran) and in ols_step_all_possible() (#215, reported by @LSantanaZA).na.action = na.exclude or with weights are handled consistently across plots and tests; diagnostics whose formulas assume unweighted least squares now stop with a clear error for weighted fits (#236).Two issues remain open and will be fixed in 0.7.2. The Kolmogorov-Smirnov row of ols_test_normality() is not Lilliefors-corrected, so its \(p\)-value is too large when the mean and standard deviation are estimated from the residuals (#254). Until then, use the Shapiro-Wilk, Cramér–von Mises or Anderson-Darling rows, or call nortest::lillie.test(residuals(model)). Two panels of ols_plot_diagnostics() also share the title “Residual Fit Spread Plot” (#253); the plotted values and axis labels are correct.
A big thank you to everyone who contributed to olsrr since 2019 by opening issues, reporting bugs and sending pull requests: @AminHP, @aravindhebbali, @ashimkapoor, @bappa10085, @ButlerMSDA, @CarlosJara72, @comatrion, @davidreilly007, @DrMondesire, @grantbrown, @hirscht, @hkincaid, @iankelk, @jmberros, @jorgevallejo, @jst04004, @jtheog, @kaygmz, @linusjf, @LSantanaZA, @modche, @Molina-Valero, @mwm-cbus, @njrockwood, @paleolimbot, @PsychlytxTD, @qwertytam, @sblanco74, @sckott, @SunsetBlvd, @tikuma-lsuhsc, @vasili111, @viqule11, @williamlai2, and @yayyb.
About the author: Aravind Hebbali runs Rsquared Academy — courses, ebooks, and R packages for learning R and data science.