Learn R Programming

ipred (version 0.4-6)

predict.inclass: Predictions from an Inclass Object

Description

Predicts the class membership of new observations through indirect classification.

Usage

## S3 method for class 'inclass':
predict(object, cFUN, intbag=NULL, newdata, ...)

Arguments

object
object of class inclass, see inclass.
cFUN
fixed function which classifies the predicted intermediates.
intbag
logical. If pFUN = bagging bagging either stabilises the prediction of the intermediate variables or the classifications. If intbag = TRUE intermediates are bagged, the whole classifying procedure is bagged otherwise.
newdata
data frame to be classified.
...
additional arguments corresponding to the predictive models specified in inclass. If the intermediate is nominal and pFUN = rpart or bagging one argument has to be type = "c

Value

  • The vector of predicted classes is returned.

Details

Predictions of class memberships are calculated. i.e. values of the intermediate variables are predicted and classified following cFUN, see inclass.

References

David J. Hand, Hua Gui Li, Niall M. Adams (2001), Supervised classification with structured class definitions. Computational Statistics & Data Analysis 36, 209--225.

See Also

inclass

Examples

Run this code
# Simulation model, classification rule following Hand et al. (2001)

theta90 <- varset(N = 1000, sigma = 0.1, theta = 90, threshold = 0)

dataset <- as.data.frame(cbind(theta90$explanatory, theta90$intermediate))
names(dataset) <- c(colnames(theta90$explanatory), colnames(theta90$intermediate))

classi <- function(Y, threshold = 0) {
  z <- (Y > threshold)
  resp <- as.factor(ifelse((z[,1] + z[,2]) > 1, 1, 0))
  return(resp)
}

formula <- flist(y1+y2~x1+x2)

fit <- inclass(formula, pFUN = lm, data = dataset)

predict.inclass(object = fit, cFUN = classi, newdata = dataset)


data(smoking)

# explanatory variables are: TarY, NicY, COY, Sex, Age
# intermediate variables are: TVPS, BPNL, COHB
# reponse (resp) ist defined by:

resp <- function(data){
  res <- t(t(data) > c(4438, 232.5, 58))
  res <- as.factor(ifelse(apply(res, 1, sum) > 2, 1, 0))
  res
}

response <- resp(smoking[ ,c("TVPS", "BPNL", "COHB")])
smoking <- cbind(smoking, response)

formula <- TVPS+BPNL+COHB~TarY+NicY+COY+Sex+Age

fit <- inclass(formula, pFUN = lm, data = smoking)

predict.inclass(object = fit, cFUN = resp, newdata = smoking)

Run the code above in your browser using DataLab