Learn R Programming

HiGarrote (version 2.0.0)

predict.nnGarrote: Make Predictions from a "nnGarrote" Object

Description

This function makes predictions from a linear model constructed using the important effects selected by nnGarrote.

Usage

# S3 method for nnGarrote
predict(object, new_X, ...)

Value

The function returns a list with:

new_U

A model matrix of new_X.

prediction_nng

Predictions for new_X. The coefficients of the predictive equation are based on nonnegative garrote estimates.

prediction_lm

Predictions for new_X. The coefficients of the predictive equation are estimated via ordinary least squares.

Arguments

object

An nnGarrote object.

new_X

A new input matrix where predictions are to be made.

...

Additional arguments passed to `predict`. Not used in this function.

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

# training and testing set
train_idx <- sample(1:100, 80)
X_train <- X[train_idx,]
y_train <- y[train_idx]
X_test <- X[-train_idx,]
y_test <- y[-train_idx]

# fit nnGarrote
fit_nng <- HiGarrote::nnGarrote(X_train, y_train)

# predict
pred_nng <- predict(fit_nng, X_test)

Run the code above in your browser using DataLab