predict.ordPen: Predict method for ordPen objects

View source: R/predict.ordPen.R

predict.ordPenR Documentation

Predict method for ordPen objects

Description

Obtains predictions from an ordPen object.

Usage

## S3 method for class 'ordPen'
predict(object, newx, newu = NULL, newz = NULL,
  offset = rep(0,nrow(as.matrix(newx))), 
  type = c("link", "response", "class"), ...)

Arguments

object

an ordPen object.

newx

the matrix (or data.frame) of new observations of the considered ordinal predictors, with each column corresponding to one predictor and containing numeric values from {1,2,...}.

newu

a matrix (or data.frame) of new observations of the additional categorical (nominal) predictors, with each column corresponding to one (additional) predictor and containing numeric values {1,2,...}.

newz

a matrix (or data.frame) of new observations of the additional metric predictors, with each column corresponding to one (additional) predictor.

offset

potential offset values.

type

the type of prediction; type = "link" is on the scale of linear predictors, whereas type = "response" is on the scale of the response variable, i.e., type = "response" applies the inverse link function to the linear predictors. type = "class" is only available for cumulative logit models and returns the class number with the highest fitted probability.

...

additional arguments (not supported at this time).

Value

A matrix of predictions whose columns correspond to the different values of the penalty parameter lambda of the ordPen object.

Author(s)

Jan Gertheiss, Aisouda Hoshiyar

See Also

ordSelect, ordSmooth, ordFusion

Examples

# the training data
set.seed(123)

# generate (ordinal) predictors
x1 <- sample(1:8,100,replace=TRUE)
x2 <- sample(1:6,100,replace=TRUE)
x3 <- sample(1:7,100,replace=TRUE)

# the response
y <- -1 + log(x1) + sin(3*(x2-1)/pi) + rnorm(100)

# x matrix
x <- cbind(x1,x2,x3)

# lambda values
lambda <- c(1000,500,200,100,50,30,20,10,1)

# selecting and/or smoothing/fusing
o1 <- ordSmooth(x = x, y = y, lambda = lambda)
o2 <- ordSelect(x = x, y = y, lambda = lambda)
o3 <- ordFusion(x = x, y = y, lambda = lambda)

# new data
x1 <- sample(1:8,10,replace=TRUE)
x2 <- sample(1:6,10,replace=TRUE)
x3 <- sample(1:7,10,replace=TRUE)
newx <- cbind(x1,x2,x3)

# prediction
round(predict(o1, newx), digits=3)
round(predict(o2, newx), digits=3)
round(predict(o3, newx), digits=3)

ahoshiyar/ordPens documentation built on May 7, 2024, 5:43 a.m.