Learn R Programming

EstemPMM (version 0.1.1)

lm_pmm2: PMM2: Main function for PMM2 (S=2)

Description

Fits a linear model using the Polynomial Maximization Method (order 2), which is robust to non-Gaussian errors.

Usage

lm_pmm2(
  formula,
  data,
  max_iter = 50,
  tol = 1e-06,
  regularize = TRUE,
  reg_lambda = 1e-08,
  na.action = na.fail,
  weights = NULL,
  verbose = FALSE
)

Value

S4 object of class PMM2fit

Arguments

formula

R formula for the model

data

data.frame containing variables in the formula

max_iter

integer: maximum number of iterations for the algorithm

tol

numeric: tolerance for convergence

regularize

logical: add small value to diagonal for numerical stability

reg_lambda

numeric: regularization parameter (if regularize=TRUE)

na.action

function for handling missing values, default is na.fail

weights

optional weight vector (not yet implemented)

verbose

logical: whether to print progress information

Details

The PMM2 algorithm works as follows:

  1. Fits ordinary least squares (OLS) regression to obtain initial estimates

  2. Computes central moments (m2, m3, m4) from OLS residuals

  3. Iteratively improves parameter estimates using a gradient-based approach

PMM2 is especially useful when error terms are not Gaussian.

Examples

Run this code
set.seed(123)
n <- 80
x <- rnorm(n)
y <- 2 + 3 * x + rt(n, df = 3)
dat <- data.frame(y = y, x = x)

fit <- lm_pmm2(y ~ x, data = dat)
summary(fit, formula = y ~ x, data = dat)

Run the code above in your browser using DataLab