Type: | Package |
Title: | Multivariate Cauchy Distribution |
Version: | 1.1 |
Date: | 2024-06-03 |
Author: | Michail Tsagris [aut, cre], Christos Adam [ctb] |
Maintainer: | Michail Tsagris <mtsagris@uoc.gr> |
Depends: | R (≥ 4.0) |
Imports: | graphics, grDevices, Rfast, Rfast2 |
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. |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
NeedsCompilation: | no |
Packaged: | 2024-06-03 08:55:31 UTC; mtsag |
Repository: | CRAN |
Date/Publication: | 2024-06-04 09:45:23 UTC |
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.
Details
Package: | mvcauchy |
Type: | Package |
Version: | 1.1 |
Date: | 2024-06-03 |
License: | GPL-2 |
Maintainers
Michail Tsagris <mtsagris@uoc.gr>.
Author(s)
Michail Tsagris mtsagris@uoc.gr and Christos Adam pada4m4@gmail.com.
References
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
Description
Cauchy naive Bayes classifier.
Usage
cauchy.nb(xnew = NULL, x, ina)
Arguments
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. |
Value
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. |
Author(s)
Michail Tsagris.
R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.
See Also
Examples
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
Description
Contour plot of the bivariate Cauchy distribution.
Usage
bivcauchy.contour(x, m = NULL, s = NULL, cont.lines = TRUE, add.points = TRUE)
Arguments
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? |
Details
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.
Value
The contour plot.
Author(s)
Michail Tsagris and Christos Adam.
R implementation and documentation: Michail Tsagris mtsagris@uoc.gr and Christos Adam pada4m4@gmail.com.
See Also
Examples
## 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
Description
Cross-validation for the Cauchy discriminant analysis.
Usage
cv.mvcauchyda(x, ina, nfolds = 10, folds = NULL, stratified = TRUE, seed = NULL)
Arguments
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. |
Details
Cross validation is performed to select the optimal parameters for the maximum likelihood Cauchy discriminant analysis and also estimate the rate of accuracy.
Value
A list including:
perf |
The estimated rate of correct classification. |
runtime |
The time required by the cross-validation procedure. |
Author(s)
Michail Tsagris.
R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.
References
Friedman Jerome, Trevor Hastie and Robert Tibshirani (2017). The elements of statistical learning. New York: Springer.
See Also
Examples
mod <- cv.mvcauchyda(as.matrix(iris[, 1:4]), iris[, 5])
mod
Cross-validation for the maximum likelihood discriminant analysis using the multivariate Cauchy distribution
Description
Cross-validation for the maximum likelihood discriminant analysis using the multivariate Cauchy distribution.
Usage
cv.cauchynb(x, ina, folds = NULL, nfolds = 10,
stratified = TRUE, seed = FALSE, pred.ret = FALSE)
Arguments
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. |
Value
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. |
Author(s)
Michail Tsagris.
R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.
References
Friedman J., Hastie T. and Tibshirani R. (2017). The elements of statistical learning. New York: Springer.
See Also
Examples
x <- as.matrix(iris[, 1:4])
mod <- cv.cauchynb(x = x, ina = iris[, 5])
Density of the multivariate Cauchy distribution
Description
Density of the multivariate Cauchy distribution.
Usage
dmvcauchy(x, mu, sigma, logged = FALSE)
Arguments
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)? |
Details
The (log) density of the multivariate Cauchy distribution is calculated for given mean vector and covariance matrix.
Value
A numerical vector with the density values calculated at each vector (row of the matrix x).
Author(s)
Michail Tsagris.
R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.
References
Kanti V. Mardia, John T. Kent and John M. Bibby (1979). Multivariate analysis. Academic Press, London.
See Also
Examples
x <- as.matrix(iris[, 1:4])
mod <- mvcauchy.mle(x)
m <- mod$location
s <- mod$scatter
a <- dmvcauchy(x, m, s)
MLE of the multivariate Cauchy distribution
Description
MLE of the multivariate Cauchy distribution.
Usage
mvcauchy.mle(x, tol = 1e-07)
Arguments
x |
A matrix with numerical data. |
tol |
The tolerance value to terminate the EM algorithm. |
Details
The location vector, scatter matrix and the value of the log-likelihood is calculated.
Value
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. |
Author(s)
Michail Tsagris.
R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.
References
Nadarajah S. and Kotz S. (2008). Estimation methods for the multivariate t distribution. Acta Applicandae Mathematicae, 102(1): 99–118.
See Also
Examples
x <- as.matrix(iris[, 1:2])
res <- mvcauchy.mle(x)
Maximum likelihood discriminant analysis using the multivariate Cauchy distribution
Description
Maximum likelihood discriminant analysis using the multivariate Cauchy distribution.
Usage
mvcauchy.da(xnew, x, ina, mod = NULL)
Arguments
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 |
Details
Maximum likelihood discriminant analysis using the multivariate Cauchy distribution is performed.
Value
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. |
Author(s)
Michail Tsagris.
R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.
References
Kanti V. Mardia, John T. Kent and John M. Bibby (1979). Multivariate analysis. Academic Press, London.
See Also
Examples
x <- as.matrix(iris[, 1:4])
ina <- iris[, 5]
a <- mvcauchy.da(x, x, ina)
Prediction with Cauchy naive Bayes classifier
Description
Prediction with Cauchy naive Bayes classifier.
Usage
cauchynb.pred(xnew, location, scale, ni)
Arguments
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. |
Value
A numerical vector with 1, 2, ... denoting the predicted group.
Author(s)
Michail Tsagris.
R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.
References
Friedman J., Hastie T. and Tibshirani R. (2017). The elements of statistical learning. New York: Springer.
See Also
Examples
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
Description
Random values simulation from the multivariate Cauchy distribution.
Usage
rmvcauchy(n, mu, sigma)
Arguments
n |
The sample size, a numerical value. |
mu |
The mean vector in |
sigma |
The scatter matrix in |
Value
A matrix with the simulated data.
Author(s)
Michail Tsagris.
R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.
References
Aitchison J. (1986). The statistical analysis of compositional data. Chapman & Hall.
See Also
Examples
x <- as.matrix(iris[, 1:4])
mod <- mvcauchy.mle(x)
m <- mod$location
s <- mod$scatter
y <- rmvcauchy(1000, m, s)
mvcauchy.mle(y)