Skip to content

Commit

Permalink
add more useful indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
huizezhang-sherry committed May 24, 2024
1 parent 096e620 commit fa7c546
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 26 deletions.
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
67 changes: 63 additions & 4 deletions R/interesting-indices.r
Original file line number Diff line number Diff line change
@@ -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]))
Expand All @@ -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) {
Expand All @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ reference:
- slice_index
- norm_bin
- norm_kol
- stringy
- MIC
- title: Search functions
desc: >
Functions for index optimisation in guided tour
Expand Down
17 changes: 17 additions & 0 deletions man/dcor.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions man/dcor2d.Rd

This file was deleted.

6 changes: 3 additions & 3 deletions man/guided_tour.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions man/indexes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/search_jellyfish.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions man/splines2d.Rd → man/spline-loess.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions man/stringy.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fa7c546

Please sign in to comment.