Description Usage Arguments Value References Examples
View source: R/hvQuadraticData.R
Create a modified version of the artificial data set of Hand and Vinciotti (2003).
1 2 3 4 5 6 7 | hvQuadraticData(n, d = 2, k = 2)
hvQuadraticLabels(data, k = 2)
hvQuadraticPosterior(data, k = 2)
hvQuadraticBayesClass(data, k = 2)
|
n |
Number of observations. |
d |
The dimensionality. |
k |
Parameter to adjust the class prior probabilities. |
data |
A |
hvQuadraticData
returns an object of class
"locClass"
, a list with components:
x |
(A matrix.) The explanatory variables. |
y |
(A factor.) The class labels. |
hvQuadraticLabels
returns a factor of class
labels.
hvQuadraticPosterior
returns a matrix of posterior
probabilities.
hvQuadraticBayesClass
returns a factor of Bayes
predictions.
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 25 26 27 28 29 30 31 | # Generate a training and a test set
train <- hvQuadraticData(1000)
test <- hvQuadraticData(1000)
# Generate a grid of points
x.1 <- x.2 <- seq(0.01,1,0.01)
grid <- expand.grid(x.1 = x.1, x.2 = x.2)
# Calculate the posterior probablities for all grid points
gridPosterior <- hvQuadraticPosterior(grid)
# Draw contour lines of posterior probabilities and plot training observations
contour(x.1, x.2, matrix(gridPosterior[,1], length(x.1)), col = "gray")
points(train$x, col = train$y)
# Calculate Bayes error
ybayes <- hvQuadraticBayesClass(test$x)
mean(ybayes != test$y)
if (require(MASS)) {
# Fit a QDA model and calculate misclassification rate on the test data set
tr <- qda(y ~ ., data = as.data.frame(train))
pred <- predict(tr, as.data.frame(test))
mean(pred$class != test$y)
# Draw decision boundary
gridPred <- predict(tr, grid)
contour(x.1, x.2, matrix(gridPred$posterior[,1], length(x.1)), col = "red", levels = 0.5, add = TRUE)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.