predict.marge: predict.marge

View source: R/predict.marge.R

predict.margeR Documentation

predict.marge

Description

S3 generic for predict.marge function for fitted MARS and MARGE objects when using the marge package.

Usage

## S3 method for class 'marge'
predict(object, newdata, is.marge = TRUE, pen = c("2", "logN"), ...)

Arguments

object

: the final selected MARS/MARGE model. Only works for mars_ls and marge model objects.

newdata

: the new set of predictor variables to make predictions on (test data). Must contain all predictors supplied within the original model formula.

is.marge

: a logical argument, is this a MARGE model? The default is FALSE.

pen

: the penalty used for the MARGE model (only applicable if marge was used). The default is pen = "2".

...

: further arguments passed to or from other methods.

Value

predict.marge returns a list of calculated values consisting of:

eta.p : the fitted linear predictor using the new (test) data.

basis_new : the model matrix for the new (test) data.

Author(s)

Jakub Stoklosa and David I. Warton.

References

Stoklosa, J. and Warton, D.I. (2018). A generalized estimating equation approach to multivariate adaptive regression splines. Journal of Computational and Graphical Statistics, 27, 245–253.

Examples

# Load the "leptrine" presence-absence data.

data(leptrine)

dat1 <- leptrine[[1]]   # Training data.
dat1_t <- leptrine[[2]] # Test data.

Y <- dat1$Y             # Response variable.
N <- length(Y)          # Sample size (number of clusters).
n <- 1                  # Cluster size.
id <- rep(1:N, each = n)   # The ID of each cluster.

X_pred <- dat1[, -c(3:10)]    # Design matrix using only two (of nine) predictors.
X_predt <- dat1_t[, -c(4:11)]

# Set MARGE tuning parameters.

family <- "binomial"    # The selected "exponential" family for the GLM/GEE.
is.gee <- FALSE         # Is the model a GEE?
nb <- FALSE             # Is this a negative binomial model?
tols_score <- 0.0001    # A set tolerance (stopping condition) in forward pass for MARGE.
M <- 21                 # A set threshold for the maximum number of basis functions to be used.
print.disp <- FALSE     # Print ALL the output?
pen <- 2                # Penalty to be used in GCV.
minspan <- NULL         # A set minimum span value.

# Fit the MARGE models (about ~ 30 secs.)

model_marge <- marge(X_pred, Y, N, n, id, family, corstr, pen, tols_score,
                     M, minspan, print.disp, nb, is.gee)

# Predict on training data.

pred_marge_2_y <- predict(model_marge, X_predt, X_pred, TRUE, "2")

pred_marge_log_y <- predict(model_marge, X_predt, X_pred, TRUE, "logN")

JakubStats/marge documentation built on Feb. 25, 2024, 9:38 p.m.