LS | R Documentation |
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.
LS(d, yidx, Xidx, n, lam = 0.005)
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. |
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). |
# 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.