predict.graper: Predict response on new data

Description Usage Arguments Value Examples

View source: R/predict.graper.R

Description

Function to predict the response on a new data set using a fitted graper model.

Usage

1
2
3
## S3 method for class 'graper'
predict(object, newX, type = c("inRange", "response",
  "link"), ...)

Arguments

object

fitted graper model as obtained from graper

newX

Predictor matrix of size n_test (number of new test samples) x p (number of predictors) (same feature structure as used in graper)

type

type of prediction returned, either:

  • response:returns the linear predictions for linear regression and class probabilities for logistic regression

  • link:returns the linear predictions

  • inRange:returns linear predictions for linear and class memberships for logistic regression

...

other arguments

Value

A vector with predictions.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# create data
dat <- makeExampleData()
# split data into train and test sets of equal size
ntrain <- dat$n / 2
# fit the model to the train data
fit <- graper(dat$X[seq_len(ntrain), ],
              dat$y[seq_len(ntrain)], dat$annot)
# make predictions on the test data
ypred <- predict(fit, dat$X[seq_len(ntrain) + dat$n / 2, ])

# create data for logistic regression
dat <- makeExampleData(response="bernoulli")
# split data into train and test sets of equal size
ntrain <- dat$n / 2
# fit the graper model for a logistic model
fit <- graper(dat$X[seq_len(ntrain), ],
              dat$y[seq_len(ntrain)],
              dat$annot, family="binomial")
# make predictions on the test data
ypred <- predict(fit, dat$X[seq_len(ntrain) + dat$n / 2, ], type = "inRange")

graper documentation built on Nov. 8, 2020, 5:45 p.m.