Description Usage Arguments Details Value See Also Examples
A version of Quadratic Discriminant Analysis that can deal with observation weights.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | wqda(x, ...)
## S3 method for class 'formula'
wqda(formula, data, weights = rep(1, nrow(data)), ...,
  subset, na.action)
## S3 method for class 'data.frame'
wqda(x, ...)
## S3 method for class 'matrix'
wqda(x, grouping, weights = rep(1, nrow(x)), ..., subset,
  na.action = na.fail)
## Default S3 method:
wqda(x, grouping, weights = rep(1, nrow(x)),
  method = c("unbiased", "ML"), ...)
 | 
| x | (Required if no  | 
| ... | Further arguments. | 
| formula | A  | 
| data | A  | 
| weights | Observation weights to be used in the fitting process, must be non-negative. | 
| subset | An index vector specifying the cases to be used in the training sample. (NOTE: If given, this argument must be named.) | 
| na.action | A function to specify the action to be taken if NAs are found. The default action is first
the  | 
| grouping | (Required if no  | 
| method | Method for scaling the pooled weighted covariance matrix, either  | 
The formulas for the weighted estimates of the class means, the covariance matrices and the class priors are as follows:
Normalized weights:
w_n* = w_n/(sum_{m:y_m=y_n} w_m)
Weighted class means:
bar x_g = sum_{n:y_n=g} w_n* x_i
Weighted class covariance matrices: 
method = "ML":
S_g = sum_{n:y_n=g} w_n* (x_n - bar x_g)(x_n - bar x_g)'
method = "unbiased":
S_g = sum_{n:y_n=g} w_n* (x_n - bar x_g)(x_n - bar x_g)'/(1 - sum_{n:y_n=g} (w_n*)^2)
Weighted prior probabilities:
p_g = ∑_{n:y_n=g} w_n/(∑_n w_n)
If the predictor variables include factors, the formula interface must be used in order to get a correct model matrix.
An object of class "wqda", a list containing the following components:
| prior | Weighted class prior probabilities. | 
| counts | The number of observations per class. | 
| means | Weighted estimates of class means. | 
| covs | Weighted estimates of the class covariance matrices. | 
| lev | The class labels (levels of  | 
| N | The number of observations. | 
| weights | The observation weights used in the fitting process. | 
| method | The method used for scaling the weighted covariance matrix estimates. | 
| call | The (matched) function call. | 
Other qda: predict.wqda
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | library(mlbench)
data(PimaIndiansDiabetes)
train <- sample(nrow(PimaIndiansDiabetes), 500)
# weighting observations from classes pos and neg according to their 
# frequency in the data set:
ws <- as.numeric(1/table(PimaIndiansDiabetes$diabetes)
    [PimaIndiansDiabetes$diabetes])
fit <- wqda(diabetes ~ ., data = PimaIndiansDiabetes, weights = ws, 
    subset = train)
pred <- predict(fit, newdata = PimaIndiansDiabetes[-train,])
mean(pred$class != PimaIndiansDiabetes$diabetes[-train])
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.