From ad10b5c67864202ebb0b10e79f300553409d1906 Mon Sep 17 00:00:00 2001 From: "Daniel P. Palomar" Date: Sat, 16 Apr 2022 15:03:27 +0800 Subject: [PATCH] Final touches before submitting to CRAN. --- DESCRIPTION | 8 ++++---- NAMESPACE | 2 ++ NEWS.md | 2 +- R/fit_mvt.R | 8 ++++++-- R_buildignore/developer_commands.R | 4 ++-- cran-comments.md | 4 ++-- inst/CITATION | 30 +++++++++++++++++++++++++----- man/fit_mvt.Rd | 5 +++++ tests/testthat/test-fit_mvst.R | 4 +++- tests/testthat/test-fit_mvt.R | 2 +- 10 files changed, 51 insertions(+), 18 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f2a25cd..4e1c700 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,12 +1,13 @@ Package: fitHeavyTail Title: Mean and Covariance Matrix Estimation under Heavy Tails -Version: 0.1.2.9000 -Date: 2020-1-7 +Version: 0.1.3 +Date: 2022-4-14 Description: Robust estimation methods for the mean vector, scatter matrix, and covariance matrix (if it exists) from data (possibly containing NAs) under multivariate heavy-tailed distributions such as angular Gaussian (via Tyler's method), Cauchy, and Student's t distributions. Additionally, - a factor model structure can be specified for the covariance matrix. + a factor model structure can be specified for the covariance matrix. The + latest revision also includes the multivariate skewed t distribution. The package is based on the papers: Sun, Babu, and Palomar (2014), Sun, Babu, and Palomar (2015), Liu and Rubin (1995), and Zhou, Liu, Kumar, and Palomar (2019). @@ -24,7 +25,6 @@ URL: https://CRAN.R-project.org/package=fitHeavyTail, BugReports: https://github.com/dppalomar/fitHeavyTail/issues License: GPL-3 Encoding: UTF-8 -LazyData: true RoxygenNote: 7.1.1 Depends: Imports: diff --git a/NAMESPACE b/NAMESPACE index 0482398..6629f6e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,6 +11,8 @@ importFrom(mvtnorm,dmvt) importFrom(numDeriv,grad) importFrom(stats,cov) importFrom(stats,median) +importFrom(stats,na.omit) importFrom(stats,optimize) +importFrom(stats,uniroot) importFrom(stats,var) importFrom(utils,tail) diff --git a/NEWS.md b/NEWS.md index 931590b..b53b8fe 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -## Changes in fitHeavyTail version 0.1.2.9000 +## Changes in fitHeavyTail version 0.1.3 (2022-4-14) * New method for skewed t distributions: fit_mvst() diff --git a/R/fit_mvt.R b/R/fit_mvt.R index 1ba2474..1e168dc 100644 --- a/R/fit_mvt.R +++ b/R/fit_mvt.R @@ -57,6 +57,7 @@ #' \item{\code{psi}: default is #' \code{diag(initial$cov - initial$B \%*\% t(initial$B)).}}} #' @param optimize_mu Boolean indicating whether to optimize \code{mu} (default is \code{TRUE}). +#' @param weights Optional weights for each of the observations (the length should be equal to the number of rows of X). #' @param factors Integer indicating number of factors (default is \code{ncol(X)}, so no factor model assumption). #' @param max_iter Integer indicating the maximum number of iterations for the iterative estimation #' method (default is \code{100}). @@ -104,6 +105,9 @@ #' Rui Zhou, Junyan Liu, Sandeep Kumar, and Daniel P. Palomar, "Robust factor analysis parameter estimation," #' Lecture Notes in Computer Science (LNCS), 2019. #' +#' Esa Ollila, Daniel P. Palomar, and Frédéric Pascal, "Shrinking the Eigenvalues of M-estimators of Covariance Matrix," +#' IEEE Trans. on Signal Processing, vol. 69, pp. 256-269, Jan. 2021. +#' #' @examples #' library(mvtnorm) # to generate heavy-tailed data #' library(fitHeavyTail) @@ -115,7 +119,7 @@ #' options(nu_min = 4.01) #' fit_mvt(X, nu = "iterative") #' -#' @importFrom stats optimize +#' @importFrom stats optimize na.omit uniroot #' @export fit_mvt <- function(X, na_rm = TRUE, nu = c("kurtosis", "MLE-diag", "MLE-diag-resampled", "iterative"), @@ -330,7 +334,7 @@ fit_mvt <- function(X, na_rm = TRUE, theta <- (1 - N/T) * sum(r2i)/T/N # correction with sigma T_ <- 10000 - X_ <- mvtnorm::rmvt(n = T_, delta = rep(0, N), sigma = diag(N), df = nu_true) # heavy-tailed data + X_ <- mvtnorm::rmvt(n = T_, delta = rep(0, N), sigma = diag(N), df = nu) # heavy-tailed data r2 <- rowSums(X_^2) u <- (N + nu)/(nu + r2) r2i <- r2/(1 - r2*u/T_) diff --git a/R_buildignore/developer_commands.R b/R_buildignore/developer_commands.R index 6b14776..0921978 100644 --- a/R_buildignore/developer_commands.R +++ b/R_buildignore/developer_commands.R @@ -39,6 +39,6 @@ devtools::build() #devtools::revdep(pkg = "fitHeavyTail") # to check reverse dependencies #devtools::check_win_release() #to check under windows #R CMD build . # this is to generate tarball -#R CMD check fitHeavyTail_0.1.2.9000.tar.gz --as-cran --run-donttest # this is before submission to CRAN -#R CMD install fitHeavyTail_0.1.2.9000.tar.gz +#R CMD check fitHeavyTail_0.1.3.tar.gz --as-cran --run-donttest # this is before submission to CRAN +#R CMD install fitHeavyTail_0.1.3.tar.gz #submit the tarball directly via the webform: https://cran.r-project.org/submit.html diff --git a/cran-comments.md b/cran-comments.md index 3a17b66..aa2ed79 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,9 +1,9 @@ -This is version 0.1.2 (2020-1-7) in CRAN (package also available in GitHub). +This is version 0.1.3 (2022-4-14) in CRAN (package also available in GitHub). --- ## Test environments -* OS X, R 3.6.0 +* OS X, R 4.1.2 * Windows at https://win-builder.r-project.org/ ## R CMD check results diff --git a/inst/CITATION b/inst/CITATION index bcdc80a..f4ac3f0 100644 --- a/inst/CITATION +++ b/inst/CITATION @@ -3,14 +3,15 @@ citHeader("To cite 'fitHeavyTail' in publications, please use:") citEntry(entry = "Manual", title = "{fitHeavyTail: Mean and Covariance Matrix Estimation under Heavy Tails}", author = personList(as.person("D. P. Palomar"), - as.person("Rui ZHOU")), - note = "R package version 0.1.2", - year = "2020", + as.person("Rui Zhou"), + as.person("Xiwen Wang")), + note = "R package version 0.1.3", + year = "2022", url = "https://CRAN.R-project.org/package=fitHeavyTail", textVersion = - paste("D. P. Palomar and Rui Zhou (2020).", + paste("D. P. Palomar, Rui Zhou, and Xiwen Wang (2022).", "fitHeavyTail: Mean and Covariance Matrix Estimation under Heavy Tails.", - "R package version 0.1.2.", + "R package version 0.1.3.", "https://CRAN.R-project.org/package=fitHeavyTail") ) @@ -51,3 +52,22 @@ citEntry(entry = "Article", "vol. 63, no. 12, pp. 3096-3109.", "https://doi.org/10.1109/TSP.2015.2417513") ) + +citEntry(entry = "Article", + title = "Shrinking the Eigenvalues of M-estimators of Covariance Matrix", + author = personList(as.person("E. Ollila"), + as.person("D. P. Palomar"), + as.person("F. Pascal")), + journal = "IEEE Transactions on Signal Processing", + volume = "69", + pages = "256--269", + year = "2021", + url = "https://doi.org/10.1109/TSP.2020.3043952", + textVersion = + paste("E. Ollila, D. P. Palomar, and F. Pascal (2021).", + "Shrinking the Eigenvalues of M-estimators of Covariance Matrix.", + "IEEE Transactions on Signal Processing,", + "vol. 69, pp. 256-269.", + "https://doi.org/10.1109/TSP.2020.3043952") +) + diff --git a/man/fit_mvt.Rd b/man/fit_mvt.Rd index 399efcd..46e9cc5 100644 --- a/man/fit_mvt.Rd +++ b/man/fit_mvt.Rd @@ -55,6 +55,8 @@ Possible elements include: \item{optimize_mu}{Boolean indicating whether to optimize \code{mu} (default is \code{TRUE}).} +\item{weights}{Optional weights for each of the observations (the length should be equal to the number of rows of X).} + \item{scale_minMSE}{Logical value indicating whether to scale the scatter and covariance matrices to minimize the MSE estimation error by introducing bias (default is \code{FALSE}).} @@ -135,6 +137,9 @@ Biometrika, Vol. 85, No. 4, pp. 755-770, Dec., 1998 Rui Zhou, Junyan Liu, Sandeep Kumar, and Daniel P. Palomar, "Robust factor analysis parameter estimation," Lecture Notes in Computer Science (LNCS), 2019. + +Esa Ollila, Daniel P. Palomar, and Frédéric Pascal, "Shrinking the Eigenvalues of M-estimators of Covariance Matrix," +IEEE Trans. on Signal Processing, vol. 69, pp. 256-269, Jan. 2021. } \seealso{ \code{\link{fit_Tyler}}, \code{\link{fit_Cauchy}}, and \code{\link{fit_mvst}} diff --git a/tests/testthat/test-fit_mvst.R b/tests/testthat/test-fit_mvst.R index 3b3c840..5e3793c 100644 --- a/tests/testthat/test-fit_mvst.R +++ b/tests/testthat/test-fit_mvst.R @@ -39,8 +39,10 @@ test_that("default mode works", { load("fitted_mvst_check.RData") mvst_model <- fit_mvst(X, ptol = 1e-4) + expect_equal(mvst_model[c("mu", "gamma", "scatter", "nu", "mean", "cov", "converged", "num_iterations")], - mvst_model_check[c("mu", "gamma", "scatter", "nu", "mean", "cov", "converged", "num_iterations")]) #, tolerance = 0.1) + mvst_model_check[c("mu", "gamma", "scatter", "nu", "mean", "cov", "converged", "num_iterations")], + tolerance = 1e-5) # test for xts mvst_model <- fit_mvst(X) diff --git a/tests/testthat/test-fit_mvt.R b/tests/testthat/test-fit_mvt.R index b3bb6e7..a390984 100644 --- a/tests/testthat/test-fit_mvt.R +++ b/tests/testthat/test-fit_mvt.R @@ -22,7 +22,7 @@ test_that("error control works", { "Cannot deal with T <= N (after removing NAs), too few samples.", fixed = TRUE) expect_error(fit_mvt(X = X, max_iter = -1), "\"max_iter\" must be greater than 1.") expect_error(fit_mvt(X = X, factors = -1), "\"factors\" must be no less than 1 and no more than column number of \"X\".") - expect_error(fit_mvt(X = X, nu = "lala"), "'arg' should be one of “kurtosis”, “MLE-diag”, “MLE-diag-resampled”, “iterative”") + expect_error(fit_mvt(X = X, nu = "lala"), "'arg' should be one of \"kurtosis\", \"MLE-diag\", \"MLE-diag-resampled\", \"iterative\"") expect_error(fit_mvt(X = X, nu = 1), "Non-valid value for nu.") })