ols_calc: ols_calc

View source: R/ols_calc.R

ols_calcR Documentation

ols_calc

Description

Function computes linear OLS regression parameter estimates

The function requires a data frame with columns for observed response and predictors, and a formula object (class = "formula") that describes the OLS model of interest. Alternatively, the function will accept a matrix 'X_mt' and one column matrix 'Y_mt' for the predictor and response values respectively.

Usage

ols_calc(
  df = NULL,
  X_mt = NULL,
  Y_mt = NULL,
  formula_obj = NULL,
  confid_level = 0.95,
  na_omit = FALSE,
  print_detail = FALSE
)

Arguments

df

A data frame with columns for observed response and predictors.

X_mt

In lieu of both 'df' and 'formula_obj', a matrix of predictor values can be submitted along with 'Y_mt'. Note that 'X_mt' must have column names. Also, to include an intercept, 'X_mt' should have a column of 1's.

Y_mt

In lieu of both 'df' and 'formula_obj', a single column matrix of response values can be submitted along with 'X_mt'.

formula_obj

A formula object following the rules of stats::lm() construction. (e.g y ~ log(a) + b + I(b^2)). A constant parameter is implicitly added.

confid_level

A numeric that defines the confidence level for estimating confidence intervals. The default is 0.95.

na_omit

A logical which if TRUE will omit rows that have NA values.

print_detail

A logical which if TRUE will print a few statistics on the model. The default is FALSE.

Value

Returning a named list of dataframes with OLS coefficient estimates, residual statistics, ANOVA of the regression along with residuals, fitted values, and R^2.

Examples

library(wooldridge)
library(data.table)
library(RregressPkg)

gpa1_dt <- data.table::as.data.table(wooldridge::gpa1) |>
_[, skipped := -skipped] |>
  _[, .(colGPA, hsGPA, ACT, skipped)]

ols_ls <- RregressPkg::ols_calc(
  df = gpa1_dt,
  formula_obj = colGPA ~ hsGPA + ACT + skipped
)


deandevl/RregressPkg documentation built on Feb. 5, 2025, 12:11 p.m.