From fa7c546b507bf601da2f232f583660654a3d935e Mon Sep 17 00:00:00 2001 From: huizezhang-sherry Date: Thu, 23 May 2024 23:44:59 -0500 Subject: [PATCH] add more useful indexes --- DESCRIPTION | 6 ++- NAMESPACE | 5 ++ R/interesting-indices.r | 67 +++++++++++++++++++++++++-- _pkgdown.yml | 2 + man/dcor.Rd | 17 +++++++ man/dcor2d.Rd | 13 ------ man/guided_tour.Rd | 6 +-- man/indexes.Rd | 15 ++++++ man/search_jellyfish.Rd | 4 +- man/{splines2d.Rd => spline-loess.Rd} | 7 ++- man/stringy.Rd | 11 +++++ 11 files changed, 127 insertions(+), 26 deletions(-) create mode 100644 man/dcor.Rd delete mode 100644 man/dcor2d.Rd create mode 100644 man/indexes.Rd rename man/{splines2d.Rd => spline-loess.Rd} (72%) create mode 100644 man/stringy.Rd diff --git a/DESCRIPTION b/DESCRIPTION index d28ebb9f..ba51f602 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -41,11 +41,13 @@ Suggests: rmarkdown, tidyr, covr, - plotly + plotly, + cassowaryr, + minerva License: MIT + file LICENSE LazyData: true URL: https://github.com/ggobi/tourr BugReports: https://github.com/ggobi/tourr/issues -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Encoding: UTF-8 VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index 47466dc0..bb145d3f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -12,6 +12,8 @@ S3method(plot,path_index) S3method(print,history_array) S3method(print,tour_path) S3method(str,history_array) +export(MIC) +export(TIC) export(anchored_orthogonal_distance) export(andrews) export(angular_breaks) @@ -40,6 +42,7 @@ export(center) export(cmass) export(cumulative_radial) export(dcor2d) +export(dcor2d_2) export(dependence_tour) export(display_andrews) export(display_density2d) @@ -75,6 +78,7 @@ export(lda_pp) export(linear_breaks) export(little_tour) export(local_tour) +export(loess2d) export(manual_slice) export(mapColors) export(mapShapes) @@ -109,6 +113,7 @@ export(search_posse) export(slice_index) export(sphere_data) export(splines2d) +export(stringy) export(thaw) importFrom(grDevices,dev.cur) importFrom(grDevices,dev.flush) diff --git a/R/interesting-indices.r b/R/interesting-indices.r index 49f6d234..462f0314 100644 --- a/R/interesting-indices.r +++ b/R/interesting-indices.r @@ -1,11 +1,45 @@ +#' Scagnostic indexes. +#' +#' Compute the scagnostic measures from the cassowaryr package +#' @export +stringy <- function(){ + function(mat){ + cassowaryr::sc_stringy(mat[,1], mat[,2]) + } +} + + +#' Maximum and total information coefficient index. +#' +#' Compute the maximum and total information coefficient indexes, +#' see \code{minerva::mine}. +#' +#' @rdname indexes +#' @export +MIC <- function(){ + function(mat){ + minerva::mine(mat[,1], mat[,2], alpha = 0.3, est = "mic_e")$MIC + } +} + +#' @rdname indexes +#' @export +TIC <- function(){ + function(mat){ + minerva::mine(mat[,1], mat[,2], est = "mic_e", alpha = 0.3)$TIC + } +} + #' Distance correlation index. #' -#' Computes the distance correlation based index on -#' 2D projections of the data. +#' Computes the distance correlation based index on 2D projections of the data. +#' \code{dcor2d_2} uses the faster implementation of the distance correlation +#' for bivariate data, see \code{energy::dcor2d}. #' #' @keywords hplot #' @importFrom stats na.omit #' @export +#' @rdname dcor dcor2d <- function() { function(mat) { xy <- na.omit(data.frame(x = mat[, 1], y = mat[, 2])) @@ -14,15 +48,26 @@ dcor2d <- function() { } } -#' Spline based index. +#' @rdname dcor +#' @export +dcor2d_2 <- function() { + function(mat) { + xy <- na.omit(data.frame(x = mat[, 1], y = mat[, 2])) + measure <- with(xy, energy::dcor2d(x, y, type = "U")) + return(measure) + } +} + +#' Spline/loess based index. #' #' Compares the variance in residuals of a fitted -#' spline model to the overall variance to find +#' spline/loess model to the overall variance to find #' functional dependence in 2D projections #' of the data. #' #' @keywords hplot #' @importFrom stats residuals var +#' @rdname spline-loess #' @export splines2d <- function() { function(mat) { @@ -38,6 +83,20 @@ splines2d <- function() { } } +#' @rdname spline-loess +#' @export +loess2d <- function() { + function(mat) { + mat <- as.data.frame(mat) + colnames(mat) <- c("x", "y") + loess_fit <- loess(y ~ x, data = mat, span = 0.05) + loess_fit2 <- loess(x ~ y, data = mat, span = 0.05) + measure <- max(1 - var(residuals(loess_fit), na.rm = T) / var(mat$y, na.rm = T), + 1 - var(residuals(loess_fit2), na.rm = T) / var(mat$y, na.rm = T) + ) + return(measure) + } +} #' Normality index. diff --git a/_pkgdown.yml b/_pkgdown.yml index eb873103..ee29c591 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -52,6 +52,8 @@ reference: - slice_index - norm_bin - norm_kol + - stringy + - MIC - title: Search functions desc: > Functions for index optimisation in guided tour diff --git a/man/dcor.Rd b/man/dcor.Rd new file mode 100644 index 00000000..6f9f9669 --- /dev/null +++ b/man/dcor.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/interesting-indices.r +\name{dcor2d} +\alias{dcor2d} +\alias{dcor2d_2} +\title{Distance correlation index.} +\usage{ +dcor2d() + +dcor2d_2() +} +\description{ +Computes the distance correlation based index on 2D projections of the data. +\code{dcor2d_2} uses the faster implementation of the distance correlation +for bivariate data, see \code{energy::dcor2d}. +} +\keyword{hplot} diff --git a/man/dcor2d.Rd b/man/dcor2d.Rd deleted file mode 100644 index 9c5e68d4..00000000 --- a/man/dcor2d.Rd +++ /dev/null @@ -1,13 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/interesting-indices.r -\name{dcor2d} -\alias{dcor2d} -\title{Distance correlation index.} -\usage{ -dcor2d() -} -\description{ -Computes the distance correlation based index on -2D projections of the data. -} -\keyword{hplot} diff --git a/man/guided_tour.Rd b/man/guided_tour.Rd index ba99114b..83375437 100644 --- a/man/guided_tour.Rd +++ b/man/guided_tour.Rd @@ -7,13 +7,13 @@ guided_tour( index_f, d = 2, - alpha = 0.5, cooling = 0.99, max.tries = 25, max.i = Inf, search_f = search_geodesic, n_jellies = 30, n_sample = 100, + alpha = 0.5, ... ) } @@ -22,8 +22,6 @@ guided_tour( \item{d}{target dimensionality} -\item{alpha}{the initial size of the search window, in radians} - \item{cooling}{the amount the size of the search window should be adjusted by after each step} @@ -37,6 +35,8 @@ a better projection before giving up} \item{n_sample}{number of samples to generate if \code{search_f} is \code{\link{search_polish}}} +\item{alpha}{the initial size of the search window, in radians} + \item{...}{arguments sent to the search_f} } \description{ diff --git a/man/indexes.Rd b/man/indexes.Rd new file mode 100644 index 00000000..3549b6bc --- /dev/null +++ b/man/indexes.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/interesting-indices.r +\name{MIC} +\alias{MIC} +\alias{TIC} +\title{Maximum and total information coefficient index.} +\usage{ +MIC() + +TIC() +} +\description{ +Compute the maximum and total information coefficient indexes, +see \code{minerva::mine}. +} diff --git a/man/search_jellyfish.Rd b/man/search_jellyfish.Rd index 68037ebf..c4fec8d1 100644 --- a/man/search_jellyfish.Rd +++ b/man/search_jellyfish.Rd @@ -4,7 +4,7 @@ \alias{search_jellyfish} \title{An jellyfish optimisers for the projection pursuit guided tour} \usage{ -search_jellyfish(current, index, tries, max.tries = Inf, min.tries = 30, ...) +search_jellyfish(current, index, tries, max.tries = 50, ...) } \arguments{ \item{current}{starting projection, a list of basis of class "multi-bases"} @@ -13,7 +13,7 @@ search_jellyfish(current, index, tries, max.tries = Inf, min.tries = 30, ...) \item{tries}{the counter of the outer loop of the opotimiser} -\item{max.tries, min.tries}{the maximum/minimum number of iteration before giving up} +\item{max.tries}{the maximum number of iteration before giving up} \item{...}{other arguments being passed into the \code{search_jellyfish()}} } diff --git a/man/splines2d.Rd b/man/spline-loess.Rd similarity index 72% rename from man/splines2d.Rd rename to man/spline-loess.Rd index 05cf368e..760ce288 100644 --- a/man/splines2d.Rd +++ b/man/spline-loess.Rd @@ -2,13 +2,16 @@ % Please edit documentation in R/interesting-indices.r \name{splines2d} \alias{splines2d} -\title{Spline based index.} +\alias{loess2d} +\title{Spline/loess based index.} \usage{ splines2d() + +loess2d() } \description{ Compares the variance in residuals of a fitted -spline model to the overall variance to find +spline/loess model to the overall variance to find functional dependence in 2D projections of the data. } diff --git a/man/stringy.Rd b/man/stringy.Rd new file mode 100644 index 00000000..fbfe7313 --- /dev/null +++ b/man/stringy.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/interesting-indices.r +\name{stringy} +\alias{stringy} +\title{Scagnostic indexes.} +\usage{ +stringy() +} +\description{ +Compute the scagnostic measures from the cassowaryr package +}