Learn R Programming

HiGarrote (version 2.0.0)

nnGarrote: Nonnegative Garrote Method with Hierarchical Structures

Description

`nnGarrote()` implements the nonnegative garrote method, as described in Yuan et al. (2009), for selecting important variables while preserving hierarchical structures. The method begins by obtaining the least squares estimates of the regression parameters under a linear model. These initial estimates are then used in the nonnegative garrote to perform variable selection. Note that this method is suitable only when the number of observations is much larger than the number of variables, ensuring that the least squares estimation remains reliable.

Usage

nnGarrote(X, y, heredity = "weak", model_type = 1)

Value

The function returns a list with:

nng_estimate

A vector for the nonnegative garrote estimates of the identified variables.

U

A scaled model matrix.

pred_info

A list of information required for further prediction.

Arguments

X

An \(n \times p\) input matrix, where \(n\) is the number of data and \(p\) is the number of variables.

y

A vector for the responses.

heredity

Specifies the heredity principles to be used. Supported options are "weak" and "strong". The default is "weak".

model_type

Integer indicating the type of model to construct.

model_type = 1

The model matrix includes linear effects, two-factor interactions, and quadratic effects.

model_type = 2

The model matrix includes linear effects and two-factor interactions.

The default is model_type = 1.

References

Yuan, M., Joseph, V. R., and Zou H. (2009). Structured Variable Selection and Estimation. The Annals of Applied Statistics, 3(4), 1738–1757. tools:::Rd_expr_doi("10.1214/09-AOAS254").

Examples

Run this code
# Generate data
x1 <- runif(100)
x2 <- runif(100)
x3 <- runif(100)
error <- rnorm(100)
X <- data.frame(x1, x2, x3)
U <- model.matrix(~. + x1:x2 + x1:x3 + x2:x3 + I(x1^2) + I(x2^2) + I(x3^2) - 1, X)
U <- data.frame(scale(U))
colnames(U) <- c("x1", "x2", "x3", "x1:x1", "x2:x2", "x3:x3", "x1:x2", "x1:x3", "x2:x3")
y <- 3 + 3*U$x1 + 3*U$`x1:x1` + 3*U$`x1:x2`+ 3*U$`x1:x3` + error

# Fit nnGarrote
fit_nng <- HiGarrote::nnGarrote(X, y)
fit_nng$nng_estimate

Run the code above in your browser using DataLab