Title: | Multivariate Cauchy Distribution |
---|---|
Description: | The Cauchy distribution is a special case of the t distribution when the degrees of freedom are equal to 1. The functions are related to the multivariate Cauchy distribution and include simulation, computation of the density, maximum likelihood estimation, contour plot of the bivariate Cauchy distribution, and discriminant analysis. References include: Nadarajah S. and Kotz S. (2008). "Estimation methods for the multivariate t distribution". Acta Applicandae Mathematicae, 102(1): 99--118. <doi:10.1007/s10440-008-9212-8>, and Kanti V. Mardia, John T. Kent and John M. Bibby (1979). "Multivariate analysis", ISBN:978-0124712522. Academic Press, London. |
Authors: | Michail Tsagris [aut, cre], Christos Adam [ctb] |
Maintainer: | Michail Tsagris <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.1 |
Built: | 2024-12-02 06:39:44 UTC |
Source: | CRAN |
The Cauchy distribution is a special case of the t distribution when the degrees of freedom are equal to 1. The functions are related to the multivariate Cauchy distribution and include simulation, computation of the density, maximum likelihood estimation, contour plot of the bivariate Cauchy distribution, and discriminant analysis.
Package: | mvcauchy |
Type: | Package |
Version: | 1.1 |
Date: | 2024-06-03 |
License: | GPL-2 |
Michail Tsagris <[email protected]>.
Michail Tsagris [email protected] and Christos Adam [email protected].
Nadarajah S. and Kotz S. (2008). Estimation methods for the multivariate t distribution. Acta Applicandae Mathematicae, 102(1): 99–118.
Kanti V. Mardia, John T. Kent and John M. Bibby (1979). Multivariate analysis. Academic Press, London.
Cauchy naive Bayes classifier.
cauchy.nb(xnew = NULL, x, ina)
cauchy.nb(xnew = NULL, x, ina)
xnew |
A numerical matrix with new predictor variables whose group is to be predicted. This is set to NUUL, as you might want just the model and not to predict the membership of new observations. |
x |
A numerical matrix with the observed predictor variable values. |
ina |
A numerical vector with strictly positive numbers, i.e. 1,2,3 indicating the groups of the dataset. Alternatively this can be a factor variable. |
Depending on the classifier a list including (the ni and est are common for all classifiers):
location |
A matrix with the location parameters (medians). |
scale |
A matrix with the scale parameters. |
ni |
The sample size of each group in the dataset. |
est |
The estimated group of the xnew observations. It returns a numerical value back regardless of the target variable being numerical as well or factor. Hence, it is suggested that you do \"as.numeric(ina)\" in order to see what is the predicted class of the new data. |
Michail Tsagris.
R implementation and documentation: Michail Tsagris [email protected].
x <- as.matrix(iris[, 1:4]) ina <- as.numeric(iris[, 5]) a <- mvcauchy::cauchy.nb(x, x, ina = ina)
x <- as.matrix(iris[, 1:4]) ina <- as.numeric(iris[, 5]) a <- mvcauchy::cauchy.nb(x, x, ina = ina)
Contour plot of the bivariate Cauchy distribution.
bivcauchy.contour(x, m = NULL, s = NULL, cont.lines = TRUE, add.points = TRUE)
bivcauchy.contour(x, m = NULL, s = NULL, cont.lines = TRUE, add.points = TRUE)
x |
A matrix with two columns containing the data. |
m |
If you know the location vector place it here. In this case the function still needs the argument with the data. |
s |
If you know the scatter matrix place it here. In this case the function still needs the argument with the data. |
cont.lines |
Do you want the contour lines to appear? |
add.points |
Do you want the data points to appear? |
The function plots the contours of the bivariate Cauchy distribution whose parameters are either estimated from some data or they are given as inputs. If you want the contour plot of the bivariate Cauchy distribution with some pre-specified location and scatter matrix, then provide some cleverly specified data "x" so that you receive what you want. See the examples.
The contour plot.
Michail Tsagris and Christos Adam.
R implementation and documentation: Michail Tsagris [email protected] and Christos Adam [email protected].
## not specified location and scatter x <- as.matrix(iris[, 1:2]) bivcauchy.contour(x) ## with specified location and scatter m <- colMeans(x) s <- cov(x) ## in this case you may need to adjust the data points youself ## "play"" with minimum and maximum values of the two axes y <- rbind( apply(x, 2, min) - 1, apply(x, 2, max) + 2 ) bivcauchy.contour(y, m = m, s = s, add.points = FALSE)
## not specified location and scatter x <- as.matrix(iris[, 1:2]) bivcauchy.contour(x) ## with specified location and scatter m <- colMeans(x) s <- cov(x) ## in this case you may need to adjust the data points youself ## "play"" with minimum and maximum values of the two axes y <- rbind( apply(x, 2, min) - 1, apply(x, 2, max) + 2 ) bivcauchy.contour(y, m = m, s = s, add.points = FALSE)
Cross-validation for the Cauchy discriminant analysis.
cv.mvcauchyda(x, ina, nfolds = 10, folds = NULL, stratified = TRUE, seed = NULL)
cv.mvcauchyda(x, ina, nfolds = 10, folds = NULL, stratified = TRUE, seed = NULL)
x |
A matrix with the data. |
ina |
A group indicator variable for the avaiable data. |
nfolds |
The number of folds in the cross validation. |
folds |
If you have the list with the folds supply it here. You can also leave it NULL and it will create folds. |
stratified |
Do you want the folds to be created in a stratified way? TRUE or FALSE. |
seed |
You can specify your own seed number here or leave it NULL. |
Cross validation is performed to select the optimal parameters for the maximum likelihood Cauchy discriminant analysis and also estimate the rate of accuracy.
A list including:
perf |
The estimated rate of correct classification. |
runtime |
The time required by the cross-validation procedure. |
Michail Tsagris.
R implementation and documentation: Michail Tsagris [email protected].
Friedman Jerome, Trevor Hastie and Robert Tibshirani (2017). The elements of statistical learning. New York: Springer.
mod <- cv.mvcauchyda(as.matrix(iris[, 1:4]), iris[, 5]) mod
mod <- cv.mvcauchyda(as.matrix(iris[, 1:4]), iris[, 5]) mod
Cross-validation for the maximum likelihood discriminant analysis using the multivariate Cauchy distribution.
cv.cauchynb(x, ina, folds = NULL, nfolds = 10, stratified = TRUE, seed = FALSE, pred.ret = FALSE)
cv.cauchynb(x, ina, folds = NULL, nfolds = 10, stratified = TRUE, seed = FALSE, pred.ret = FALSE)
x |
A matrix with the available data, the predictor variables. |
ina |
A vector of data. The response variable, which is categorical (factor is acceptable). |
folds |
A list with the indices of the folds. |
nfolds |
The number of folds to be used. This is taken into consideration only if "folds" is NULL. |
stratified |
Do you want the folds to be selected using stratified random sampling? This preserves the analogy of the samples of each group. Make this TRUE if you wish. |
seed |
If you set this to TRUE, the same folds will be created every time. |
pred.ret |
If you want the predicted values returned set this to TRUE. |
A list including:
preds |
If pred.ret is TRUE the predicted values for each fold are returned as elements in a list. |
crit |
A vector whose length is equal to the number of k and is the accuracy metric for each k. For the classification case it is the percentage of correct classification. If you want to compute other metrics of accuracy we suggest you choose "pred.ret = TRUE" when running the function and then write a simple function to compute more metrics, offered in the package Rfast2. |
Michail Tsagris.
R implementation and documentation: Michail Tsagris [email protected].
Friedman J., Hastie T. and Tibshirani R. (2017). The elements of statistical learning. New York: Springer.
x <- as.matrix(iris[, 1:4]) mod <- cv.cauchynb(x = x, ina = iris[, 5])
x <- as.matrix(iris[, 1:4]) mod <- cv.cauchynb(x = x, ina = iris[, 5])
Density of the multivariate Cauchy distribution.
dmvcauchy(x, mu, sigma, logged = FALSE)
dmvcauchy(x, mu, sigma, logged = FALSE)
x |
A numerical matrix with the data. The rows correspond to observations and the columns to variables. |
mu |
The mean vector. |
sigma |
The scatter matrix. |
logged |
Should the logarithm of the density be returned (TRUE) or not (FALSE)? |
The (log) density of the multivariate Cauchy distribution is calculated for given mean vector and covariance matrix.
A numerical vector with the density values calculated at each vector (row of the matrix x).
Michail Tsagris.
R implementation and documentation: Michail Tsagris [email protected].
Kanti V. Mardia, John T. Kent and John M. Bibby (1979). Multivariate analysis. Academic Press, London.
x <- as.matrix(iris[, 1:4]) mod <- mvcauchy.mle(x) m <- mod$location s <- mod$scatter a <- dmvcauchy(x, m, s)
x <- as.matrix(iris[, 1:4]) mod <- mvcauchy.mle(x) m <- mod$location s <- mod$scatter a <- dmvcauchy(x, m, s)
Maximum likelihood discriminant analysis using the multivariate Cauchy distribution.
mvcauchy.da(xnew, x, ina, mod = NULL)
mvcauchy.da(xnew, x, ina, mod = NULL)
xnew |
A numerical matrix with the new data whose class is to predicted. The rows correspond to observations and the columns to variables. |
x |
A numerical matrix with the data. The rows correspond to observations and the columns to variables. |
ina |
Should the logarithm of the density be returned (TRUE) or not (FALSE)? |
mod |
This is a list with the estimated parameters of each class obtained from the function |
Maximum likelihood discriminant analysis using the multivariate Cauchy distribution is performed.
A list including:
mod |
A list with the output produced by |
prob |
The estimated probabilities of the new data of belonging to each group. |
est |
he estimated group membership of the new data. |
Michail Tsagris.
R implementation and documentation: Michail Tsagris [email protected].
Kanti V. Mardia, John T. Kent and John M. Bibby (1979). Multivariate analysis. Academic Press, London.
x <- as.matrix(iris[, 1:4]) ina <- iris[, 5] a <- mvcauchy.da(x, x, ina)
x <- as.matrix(iris[, 1:4]) ina <- iris[, 5] a <- mvcauchy.da(x, x, ina)
MLE of the multivariate Cauchy distribution.
mvcauchy.mle(x, tol = 1e-07)
mvcauchy.mle(x, tol = 1e-07)
x |
A matrix with numerical data. |
tol |
The tolerance value to terminate the EM algorithm. |
The location vector, scatter matrix and the value of the log-likelihood is calculated.
A list including:
iters |
The number of iterations required for the EM algorihm to converge. |
loglik |
The value of the maximised log-likelihood. |
location |
The location vector. |
scatter |
The scatter matrix. |
Michail Tsagris.
R implementation and documentation: Michail Tsagris [email protected].
Nadarajah S. and Kotz S. (2008). Estimation methods for the multivariate t distribution. Acta Applicandae Mathematicae, 102(1): 99–118.
x <- as.matrix(iris[, 1:2]) res <- mvcauchy.mle(x)
x <- as.matrix(iris[, 1:2]) res <- mvcauchy.mle(x)
Prediction with Cauchy naive Bayes classifier.
cauchynb.pred(xnew, location, scale, ni)
cauchynb.pred(xnew, location, scale, ni)
xnew |
A numerical matrix with new predictor variables whose group is to be predicted. |
location |
A matrix with the group location parameters of the Cauchy distribution. Each row corresponds to a group. |
scale |
A matrix with the group scale parameters of the Cauchy distribution. Each row corresponds to a group. |
ni |
A vector with the frequencies of each group. |
A numerical vector with 1, 2, ... denoting the predicted group.
Michail Tsagris.
R implementation and documentation: Michail Tsagris [email protected].
Friedman J., Hastie T. and Tibshirani R. (2017). The elements of statistical learning. New York: Springer.
x <- as.matrix(iris[, 1:4]) ina <- as.numeric(iris[, 5]) a <- mvcauchy::cauchy.nb(x, x, ina = ina) est <- mvcauchy::cauchynb.pred(x, a$location, a$scale, a$ni) table(ina, est)
x <- as.matrix(iris[, 1:4]) ina <- as.numeric(iris[, 5]) a <- mvcauchy::cauchy.nb(x, x, ina = ina) est <- mvcauchy::cauchynb.pred(x, a$location, a$scale, a$ni) table(ina, est)
Random values simulation from the multivariate Cauchy distribution.
rmvcauchy(n, mu, sigma)
rmvcauchy(n, mu, sigma)
n |
The sample size, a numerical value. |
mu |
The mean vector in |
sigma |
The scatter matrix in |
A matrix with the simulated data.
Michail Tsagris.
R implementation and documentation: Michail Tsagris [email protected].
Aitchison J. (1986). The statistical analysis of compositional data. Chapman & Hall.
x <- as.matrix(iris[, 1:4]) mod <- mvcauchy.mle(x) m <- mod$location s <- mod$scatter y <- rmvcauchy(1000, m, s) mvcauchy.mle(y)
x <- as.matrix(iris[, 1:4]) mod <- mvcauchy.mle(x) m <- mod$location s <- mod$scatter y <- rmvcauchy(1000, m, s) mvcauchy.mle(y)