LS: Least Squares Estimation for Grouped Data with Ridge...

View source: R/LS.R

LSR Documentation

Least Squares Estimation for Grouped Data with Ridge Regularization

Description

This function implements the least squares estimation for grouped data, supporting ridge regression regularization. It can handle missing data and returns regression coefficients and the sum of squared residuals for each group.

Usage

LS(d, yidx, Xidx, n, lam = 0.005)

Arguments

d

A data frame containing dependent and independent variables.

yidx

The column index of the dependent variable.

Xidx

The column indices of the independent variables.

n

A vector of starting indices for the groups.

lam

Regularization parameter for ridge regression, default is 0.005.

Value

A list containing the following elements:

beta

A matrix of regression coefficients for each group.

SSE

The sum of squared residuals for each group.

df

The sample size for each group.

gram

The Gram matrix for each group.

cgram

The Cholesky decomposition result for each group.

comm

An unused variable (reserved for future expansion).

Examples

# Example data
set.seed(123)
n <- 1000
p <- 5
d <- list(all = cbind(rnorm(n), matrix(rnorm(n*p), ncol=p)))

# Call the LS function
result <- LS(d, yidx = 1, Xidx = 2:(p + 1), n = c(1, 300, 600, 1000))

# View the results
print(result$beta)  # Regression coefficients
print(result$SSE)   # Sum of squared residuals


DLMRMV documentation built on April 12, 2025, 1:25 a.m.

Related to LS in DLMRMV...