Learn R Programming

transreg (version 1.0.5)

predict.transreg: Make Predictions

Description

Predicts outcome

Usage

# S3 method for transreg
predict(object, newx, stack = NULL, ...)

Value

Returns predicted values or predicted probabilities. The output is a column vector with one entry for each sample.

Arguments

object

object of class `transreg`

newx

features: matrix with \(n\) rows (samples) and \(p\) columns (variables)

stack

character "sta" (standard stacking) or "sim" (simultaneous stacking)

...

(not applicable)

References

Armin Rauschenberger, Zied Landoulsi, Mark A. van de Wiel, and Enrico Glaab (2023). "Penalised regression with multiple sets of prior effects". Bioinformatics 39(12):btad680. tools:::Rd_expr_doi("10.1093/bioinformatics/btad680"). (Click here to access PDF.)

See Also

Methods for objects of class [transreg] include coef and predict.

Examples

Run this code
#--- simulation ---
set.seed(1)
n0 <- 100; n1 <- 10000; n <- n0 + n1; p <- 500
X <- matrix(rnorm(n=n*p),nrow=n,ncol=p)
beta <- rnorm(p)
prior <- beta + rnorm(p)
y <- X %*% beta

#--- train-test split ---
foldid <- rep(c(0,1),times=c(n0,n1))
y0 <- y[foldid==0]
X0 <- X[foldid==0,]
y1 <- y[foldid==1]
X1 <- X[foldid==1,]

#--- glmnet (without prior effects) ---
object <- glmnet::cv.glmnet(y=y0,x=X0)
y_hat <- predict(object,newx=X1,s="lambda.min")
mean((y1-y_hat)^2)

#--- transreg (with prior effects) ---
object <- transreg(y=y0,X=X0,prior=prior)
y_hat <- predict(object,newx=X1)
mean((y1-y_hat)^2) # decrease in MSE?

Run the code above in your browser using DataLab