knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
The olsrr package provides following tools for building OLS regression models using R:
# Install release version from CRAN install.packages("olsrr") # Install development version from GitHub # install.packages("devtools") devtools::install_github("rsquaredacademy/olsrr")
olsrr uses consistent prefix ols_
for easy tab completion.
library(olsrr) library(dplyr) library(ggplot2) library(gridExtra) library(purrr) library(tibble) library(nortest) library(goftest)
olsrr is built with the aim of helping those users who are new to the R language. 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:
ols_regress(mpg ~ disp + hp + wt + qsec, data = mtcars)
Build regression model from a set of candidate predictor variables by entering and removing predictors based on p values, in a stepwise manner until there is no variable left to enter or remove any more.
# stepwise regression model <- lm(y ~ ., data = surgical) ols_step_both_p(model)
Build regression model from a set of candidate predictor variables by removing predictors based on Akaike Information Criteria, in a stepwise manner until there is no variable left to remove any more.
# stepwise aic backward regression model <- lm(y ~ ., data = surgical) k <- ols_step_backward_aic(model) k
Breusch Pagan test is used to test for herteroskedasticity (non-constant error variance). It tests whether the variance of the errors from a regression is dependent on the values of the independent variables. It is a $\chi^{2}$ test.
model <- lm(mpg ~ disp + hp + wt + drat, data = mtcars) ols_test_breusch_pagan(model)
model <- lm(mpg ~ disp + hp + wt + qsec, data = mtcars) ols_coll_diag(model)
If you encounter a bug, please file a minimal reproducible example using reprex on github. For questions and clarifications, use StackOverflow.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.