daprob | R Documentation |
For each observation to predict, the function calculates the posterior probability that the observation belongs to a given class, using the Bayes' formula. For each of the classes, the posterior probability is computed from given priors (proportional or uniform) for the class membership and an estimate (parametric or not) of the probability density at the point of the observation conditionnally to the class. The final predicted class corresponds to the class with the highest posterior probability.
daprob(Xr, Yr, Xu, Yu = NULL, dens = dmnorm,
lda = TRUE, prior = c("uniform", "proportional"), ...)
Xr |
A |
Yr |
A vector of length |
Xu |
A |
Yu |
A vector of length |
dens |
A function returning the probability density of the observation conditionnally to the class. Default to |
lda |
Logical, only considered if |
prior |
The prior probabilities of class membership. Possible values are "uniform" (default; probabilities are set equal for all the classes), "proportional" (probabilities are set equal to the observed proportions of the classes in |
... |
Optionnal arguments to pass in function defined in |
A list of outputs, such as:
y |
Responses for the test data. |
fit |
Predictions for the test data. |
r |
Residuals for the test data. |
Saporta, G., 2011. Probabilités analyse des données et statistique. Editions Technip, Paris, France.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.
data(iris)
X <- iris[, 1:4]
y <- iris[, 5]
N <- nrow(X)
m <- round(.25 * N) # Test
n <- N - m # Training
s <- sample(1:N, m)
Xr <- X[-s, ]
yr <- y[-s]
Xu <- X[s, ]
yu <- y[s]
##### LDA (homogeneous covariances)
fm <- daprob(Xr, yr, Xu, yu, dens = dmnorm)
names(fm)
headm(fm$y)
headm(fm$fit)
headm(fm$r)
fm$ni
err(fm)
##### QDA (heterogeneous covariances)
fm <- daprob(Xr, yr, Xu, yu, dens = dmnorm, lda = FALSE)
err(fm)
##### Nonparametric DA
fm <- daprob(Xr, yr, Xu, yu, dens = dkerngauss, h = .2)
err(fm)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.