Learn R Programming

DLMRMV (version 1.0.0)

LS: 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)

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).

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.

Examples

Run this code
# 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

Run the code above in your browser using DataLab