Giter VIP home page Giter VIP logo

Comments (3)

DominiqueMakowski avatar DominiqueMakowski commented on June 8, 2024

That'd be great, but while we have a cor_to_ci method, I am not sure that it is appropriate for Kendall/Spearman methods! And I am not aware of other methods to get the ci, do you know how to compute them?

Best would be to have bootstrapped CI #14 but I am not an expert of these methods 😕

from correlation.

IndrajeetPatil avatar IndrajeetPatil commented on June 8, 2024

Yeah, most of the other packages that do this indeed rely on bootstrapped CIs.

For example,

library(rcompanion)

spearmanRho(formula = wt ~ mpg, data = mtcars, ci = TRUE)
#>      rho lower.ci upper.ci
#> 1 -0.886    -0.95    -0.75

rcompanion::spearmanRho
#> function (formula = NULL, data = NULL, x = NULL, y = NULL, method = "spearman", 
#>     ci = FALSE, conf = 0.95, type = "perc", R = 1000, histogram = FALSE, 
#>     digits = 3, reportIncomplete = FALSE, ...) 
#> {
#>     if (!is.null(formula)) {
#>         x = eval(parse(text = paste0("data", "$", all.vars(formula)[1])))
#>         y = eval(parse(text = paste0("data", "$", all.vars(formula)[2])))
#>     }
#>     if (is.null(formula)) {
#>         x = x
#>         y = y
#>     }
#>     Rho = signif(cor(x, y, method = method), digits = digits)
#>     if (ci == TRUE) {
#>         Data = data.frame(x, y)
#>         Function = function(input, index) {
#>             Input = input[index, ]
#>             if (sd(Input$x) == 0 | sd(Input$y) == 0) {
#>                 FLAG = 1
#>                 return(c(NA, FLAG))
#>             }
#>             if (sd(Input$x) > 0 & sd(Input$y) > 0) {
#>                 RHO = cor(Input$x, Input$y, method = method)
#>                 FLAG = 0
#>                 return(c(RHO, FLAG))
#>             }
#>         }
#>         Boot = boot(Data, Function, R = R)
#>         BCI = boot.ci(Boot, conf = conf, type = type)
#>         if (type == "norm") {
#>             CI1 = BCI$normal[2]
#>             CI2 = BCI$normal[3]
#>         }
#>         if (type == "basic") {
#>             CI1 = BCI$basic[4]
#>             CI2 = BCI$basic[5]
#>         }
#>         if (type == "perc") {
#>             CI1 = BCI$percent[4]
#>             CI2 = BCI$percent[5]
#>         }
#>         if (type == "bca") {
#>             CI1 = BCI$bca[4]
#>             CI2 = BCI$bca[5]
#>         }
#>         if (sum(Boot$t[, 2]) > 0 & reportIncomplete == FALSE) {
#>             CI1 = NA
#>             CI2 = NA
#>         }
#>         CI1 = signif(CI1, digits = digits)
#>         CI2 = signif(CI2, digits = digits)
#>         if (histogram == TRUE & method == "spearman") {
#>             hist(Boot$t[, 1], col = "darkgray", main = "", xlab = "rho")
#>         }
#>         if (histogram == TRUE & method == "kendall") {
#>             hist(Boot$t[, 1], col = "darkgray", main = "", xlab = "tau")
#>         }
#>         if (histogram == TRUE & method == "pearson") {
#>             hist(Boot$t[, 1], col = "darkgray", main = "", xlab = "r")
#>         }
#>     }
#>     if (ci == FALSE) {
#>         names(Rho) = "rho"
#>     }
#>     if (ci == FALSE & method == "kendall") {
#>         names(Rho) = "tau"
#>     }
#>     if (ci == FALSE & method == "pearson") {
#>         names(Rho) = "r"
#>     }
#>     if (ci == FALSE) {
#>         return(Rho)
#>     }
#>     if (ci == TRUE) {
#>         names(Rho) = ""
#>     }
#>     if (ci == TRUE & method == "spearman") {
#>         return(data.frame(rho = Rho, lower.ci = CI1, upper.ci = CI2))
#>     }
#>     if (ci == TRUE & method == "kendall") {
#>         return(data.frame(tau = Rho, lower.ci = CI1, upper.ci = CI2))
#>     }
#>     if (ci == TRUE & method == "pearson") {
#>         return(data.frame(r = Rho, lower.ci = CI1, upper.ci = CI2))
#>     }
#> }
#> <bytecode: 0x0000000021b77910>
#> <environment: namespace:rcompanion>

from correlation.

DominiqueMakowski avatar DominiqueMakowski commented on June 8, 2024

Not sure how/where to add it... Should we add a method to cor_to_ci(), and then allow for every cor_test_* to get the bootstrapped version?

from correlation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.