Learn R Programming

RAMP (version 1.0)

predict.RAMP: Model prediction based on a fitted RAMP object.

Description

Similar to the usual predict methods, this function returns predictions from a fitted "RAMP" object.

Usage

## S3 method for class 'RAMP':
predict(object, newdata = NULL, type = c("link", "response", "class"), 
allpath = FALSE,...)

Arguments

object
Fitted "RAMP" model object.
newdata
Matrix of new values for x at which predictions are to be made, without the intercept term.
type
Type of prediction required. Type "response" gives the fitted values for "gaussian", fitted probabilities for "binomial", fitted mean for "poisson", and the fitted relative risk for "cox"<
allpath
allpath = T will output all the predictions on the solution path. allpath = FALSE will only output the one the criterion selected in the "RAMP" object.
...
Not used. Other arguments to predict.

Value

  • The object returned depends on type.

See Also

RAMP

Examples

Run this code
set.seed(0)
n = 500
p = 100 #Can be changed to a much larger number say 100000
x = matrix(rnorm(2*n*p),2*n,p)
eta = 1 * x[,1] + 2 * x[,3]  + 3*x[,6]  + 4*x[,1]*x[,3] + 5*x[,1]*x[,6]
y =  eta + rnorm(2*n)
xtr = x[1:n, ]
ytr = y[1:n]

xte = x[(n+1):(2*n), ]
yte = y[(n+1):(2*n)]

				
fit1 = RAMP(xtr, ytr)
ypred = predict(fit1,xte)


####binary prediction 
y = rbinom(2*n, 1, 1/(1+exp(-eta)))
xtr = x[1:n, ]
ytr = y[1:n]

xte = x[(n+1):(2*n), ]
yte = y[(n+1):(2*n)]
				
fit2 = RAMP(xtr, ytr,family='binomial')
ypred = predict(fit2,xte,type='class')
mean(ypred!=yte) ##classification error on the test set

ypred = predict(fit2,type='class')
mean(ypred!=ytr) ##classification error on the training set

Run the code above in your browser using DataLab