Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rmflight/45f53a49678c1da610f161190065de6e to your computer and use it in GitHub Desktop.
Save rmflight/45f53a49678c1da610f161190065de6e to your computer and use it in GitHub Desktop.
    if (!requireNamespace("piececor")) remotes::install_github('brshallo/piececor')

    ## Loading required namespace: piececor

    library(dplyr)

    set.seed(1234)
    x <- seq(.01, 3*pi, pi/100)
    y <- sin(x) + rnorm(length(x), sd = 0.25)
    xy <- tibble::tibble(x = x, y = y)
    xy_dist <- infotheo::discretize(xy)

    pcor_value <- function(data){
      piececor::piecewise_cors(data, .target = y, x) %>% 
        piececor::weighted_abs_mean_cors() %>% 
        {.$value}
    }

    bench::mark(
      mutinfo = infotheo::multiinformation(xy_dist),
      distcor = correlation::correlation(xy, method = "distance"),
      # nns = NNS::NNS.dep(x, y)$Dependence,
      nlcor = nlcor::nlcor(x, y, plt = FALSE),
      piececor = pcor_value(xy),
      ici_kendall = ICIKendallTau::ici_kt(x, y),
      
      # Predictive power score is the most different from notions of correlation
      # ... maybe shouldn't be on this list
      pps = ppsr::score(xy, x = "x", y = "y", algorithm = "tree")$pps,
      check = FALSE,
      iterations = 10
    )

    ## Warning: Some expressions had a GC in every iteration; so filtering
    ## is disabled.

    ## # A tibble: 6 × 6
    ##   expression       min   median `itr/sec` mem_alloc `gc/sec`
    ##   <bch:expr>  <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
    ## 1 mutinfo      329.2µs 352.94µs  2554.           NA     0   
    ## 2 distcor       14.7ms  23.25ms    20.0          NA     9.99
    ## 3 nlcor        190.5ms 197.71ms     5.02         NA     6.02
    ## 4 piececor     280.4ms 301.43ms     2.32         NA     1.16
    ## 5 ici_kendall   92.4µs  98.03µs  1994.           NA     0   
    ## 6 pps             1.1s    1.15s     0.873        NA     0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment