predict.ModelMatrixModel {ModelMatrixModel}R Documentation

predict() function

Description

This function transforms new data based on transforming parameters from a ModelMatrixModel object

Usage

## S3 method for class 'ModelMatrixModel'
predict(object, data, handleInvalid = "keep", verbose = FALSE, ...)

Arguments

object

a ModelMatrixModel object.

data

a data.frame.

handleInvalid

a string,'keep' or 'error'. In dummy variable transformation, if categorical variable has a factor level that is unseen before, 'keep' will keep the record, output dummy variables will be all zero.

verbose

boolean, if print out progress.

...

other parameters.

Value

A ModelMatrixModel class,which includes the transformed matrix and the necessary transforming parameters copied from input object.

Examples

library(ModelMatrixModel)
traindf= data.frame(x1 = sample(LETTERS[1:5], replace = TRUE, 20),
                    x2 = rnorm(20, 100, 5),
                    y = rnorm(20, 10, 2))
newdf=data.frame(x1 = sample(LETTERS[1:5], replace = TRUE, 3),
                 x2 = rnorm(3, 100, 5))
mm=ModelMatrixModel(~x1+x2,traindf,remove_1st_dummy = FALSE)
mm_pred=predict(mm,newdf)
data.frame(as.matrix(head(mm_pred$x,2)))

[Package ModelMatrixModel version 0.1.0 Index]