ols {MLBC}R Documentation

Ordinary Least Squares (OLS) regression

Description

Ordinary Least Squares regression with support for both formula and array-based interfaces. This function provides a unified interface for fitting linear models using either R formulas with data frames or raw matrices.

Usage

ols(Y, X = NULL, data = parent.frame(), se = TRUE, intercept = FALSE, ...)

## Default S3 method:
ols(Y, X, data = parent.frame(), se = TRUE, intercept = FALSE, ...)

## S3 method for class 'formula'
ols(Y, X = NULL, data = parent.frame(), se = TRUE, intercept = TRUE, ...)

Arguments

Y

numeric response vector, or a one-sided formula

X

numeric design matrix (if Y is numeric)

data

data frame (if Y is a formula)

se

logical; return heteroskedastic-robust standard errors?

intercept

logical; include an intercept term?

...

unused

Value

An object of class mlbc_fit and mlbc_ols with:

Usage Options

Option 1: Formula Interface

Option 2: Array Interface

Examples

# Load the remote work dataset
data(SD_data)

# Formula interface
fit1 <- ols(log(salary) ~ wfh_wham + soc_2021_2 + employment_type_name,
            data = SD_data)
summary(fit1)

# Array interface
Y <- log(SD_data$salary)
X <- model.matrix(~ wfh_wham + soc_2021_2, data = SD_data)
fit2 <- ols(Y, X[, -1], intercept = TRUE)  # exclude intercept column
summary(fit2)


[Package MLBC version 0.2.2 Index]