fit_glmnet_lm {ARTtransfer}R Documentation

fit_glmnet_lm: Sparse Linear Regression Wrapper for the ARTtransfer package

Description

This function fits a sparse linear regression model using 'glmnet()' from the R package glmnet for regression. It returns the coefficients, deviance on a validation set, and predictions on a test set. It is designed for use in the 'ART' adaptive and robust transfer learning framework.

Usage

fit_glmnet_lm(
  X,
  y,
  X_val,
  y_val,
  X_test,
  min_prod = 1e-05,
  max_prod = 1 - 1e-05,
  nfolds = 5,
  ...
)

Arguments

X

A matrix of predictors for the training set.

y

A vector of responses for the training set.

X_val

A matrix of predictors for the validation set. If 'NULL', deviance is not calculated.

y_val

A vector of responses for the validation set. If 'NULL', deviance is not calculated.

X_test

A matrix of predictors for the test set. If 'NULL', predictions are not generated.

min_prod

A numeric value indicating the minimum probability bound for predictions (not used in this function but passed for compatibility). Default is '1e-5'.

max_prod

A numeric value indicating the maximum probability bound for predictions (not used in this function but passed for compatibility). Default is '1-1e-5'.

nfolds

An integer specifying the number of folds for cross-validation. Default is 5.

...

Additional arguments passed to the function.

Value

A list containing:

dev

The mean squared error (deviance) on the validation set if provided, otherwise 'NULL'.

pred

The predictions on the test set if 'X_test' is provided, otherwise 'NULL'.

coef

The fitted coefficients of the sparse linear model.

Examples

# Fit a sparse linear model with validation and test data
X_train <- matrix(rnorm(100 * 5), 100, 5)
y_train <- X_train %*% rnorm(5) + rnorm(100)
X_val <- matrix(rnorm(50 * 5), 50, 5)
y_val <- X_val %*% rnorm(5) + rnorm(50)
X_test <- matrix(rnorm(20 * 5), 20, 5)

fit <- fit_glmnet_lm(X_train, y_train, X_val, y_val, X_test)


[Package ARTtransfer version 1.0.0 Index]