predict.dalr: Classify Multivariate Observations Based on Discriminant...

Description Usage Arguments Value References See Also Examples

View source: R/dalr.R

Description

Obtains predicted class labels and posterior probabilities from a locally fitted logistic regression model.

Usage

1
predict.dalr(object, newdata = NULL, ...)

Arguments

object

An object of class "dalr" inheriting from "glm".

newdata

Optionally, a data.frame in which to look for variables with which to predict. If omitted, the fitted linear predictors are used.

...

Further arguments to be passed from or to other methods, especially to predict.glm???. See also the Details section.

Value

A list with components:

class

The predicted class labels (a factor).

posterior

Matrix of class posterior probabilities.

References

Hand, D. J., Vinciotti, V. (2003), Local versus global models for classification problems: Fitting models where it matters, The American Statistician, 57(2) 124–130.

See Also

dalr, predict.glm, glm.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# generate data set:
x1 <- runif(500, min = 0, max = 1)              
x2 <- runif(500, min = 0, max = 1)              
x <- data.frame(x1 = x1, x2 = x2)
prob <- x$x2/(x$x1 + x$x2)
y <- as.factor(sapply(prob, function(x) sample(0:1, size = 1, 
    prob = c(1-x,x))))
x <- data.frame(x, y = y)

# fit dalr on training set and predict on test set:
train <- sample(500, 300)
fit <- dalr(y ~ ., data = x, thr = 0.3, wf = "rectangular", bw = 100, 
    subset = train)
pred <- predict(fit, newdata = x[-train,])
mean(y[-train] != pred$class)

schiffner/locClass documentation built on May 29, 2019, 3:39 p.m.