Description Usage Arguments Details Value References See Also Examples
Classify multivariate observations in conjunction with dalda
.
1 | predict.dalda(object, newdata, ...)
|
object |
Object of class |
newdata |
A |
... |
Further arguments. |
This function is a method for the generic function predict()
for class
"dalda"
.
It can be invoked by calling predict(x)
for an object x
of the
appropriate class, or directly by calling predict.dalda(x)
regardless of
the class of the object.
A list
with components:
class |
The predicted class labels (a |
posterior |
Matrix of class posterior probabilities. |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ## comparison with lda:
library(MASS)
fit1 <- lda(Species ~ Sepal.Length + Sepal.Width, data = iris)
pred <- predict(fit1)
mean(pred$class != iris$Species)
fit2 <- dalda(Species ~ Sepal.Length + Sepal.Width, data = iris,
wf = "gaussian", bw = 0.5)
pred <- predict(fit2)
mean(pred$class != iris$Species)
## plot of decision boundary (maximum posterior probabilities):
grid <- expand.grid(Sepal.Length = seq(4,8,0.1), Sepal.Width = seq(2,5,0.1))
predgrid1 <- predict(fit1, newdata = grid)$posterior
predgrid2 <- predict(fit2, newdata = grid)$posterior
par(mfrow = c(1,2))
contour(seq(4,8,0.1), seq(2,5,0.1),
matrix(as.numeric(apply(predgrid1, 1, max)), nrow = length(seq(4,8,0.1))))
contour(seq(4,8,0.1), seq(2,5,0.1),
matrix(as.numeric(apply(predgrid2, 1, max)), nrow = length(seq(4,8,0.1))))
points(iris$Sepal.Length, iris$Sepal.Width, pch = 19,
cex = fit2$weights[[3]]*2, col = as.numeric(iris$Species))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.