Coder Social home page Coder Social logo

Comments (8)

andresimi avatar andresimi commented on May 30, 2024 1

Perfect!!

from cutpointr.

andresimi avatar andresimi commented on May 30, 2024

I discovered what is missing: is the argument boot_runs

opt_cut <- cutpointr(suicide, dsi, suicide,boot_runs = 50)
plot_sensitivity_specificity(opt_cut)

As I extracted this example from the documentation, maybe it needs to be corrected.
Thanx!

from cutpointr.

Thie1e avatar Thie1e commented on May 30, 2024

Hi, thanks for the report. I'll look into it tomorrow. It should actually run with and without the boot_runs argument.

from cutpointr.

Thie1e avatar Thie1e commented on May 30, 2024

This was a bug in plot_sensitivity_specificity. I pushed a new version of cutpointr (0.7.4) to Github that should fix the problem. You can install it using devtools::install_github("thie1e/cutpointr"). (By the way, it also includes the add_metric function.) Can you give the new version a try?

from cutpointr.

andresimi avatar andresimi commented on May 30, 2024

Sure, I tested and it worked beautifully.
I have another suggestion for plot_sensitivity_specificity. It would be nice if we could build an output with diverses outcomes in one graph only. Maybe using facet_wrap from ggplot2.

Thanks for the wonderfull package!

from cutpointr.

Thie1e avatar Thie1e commented on May 30, 2024

Good to hear that it works now and thanks again for the report. The fix will make it to CRAN soon.

Regarding the graphing suggestion: You mean plotting different subgroups on different facets instead of with different shapes / colors? So basically like this:

library(tidyverse)
library(cutpointr)
cp <- cutpointr(suicide, dsi, suicide, gender)
cp %>% 
    select(subgroup, roc_curve) %>% 
    unnest %>% 
    ggplot(aes(x = fpr, y = tpr)) +
    geom_step() +
    facet_wrap(~ subgroup) + 
    ggtitle("ROC curve")

from cutpointr.

andresimi avatar andresimi commented on May 30, 2024

Hummm, actually, if it is possible, I was trying to find a way of doing the graphic below in facet_wrap style. I think this way it is too polluted.

# librarys
library(tidyverse); library(cutpointr)

# random data
data <- data_frame(test = runif(1000, min=0, max=10),
                   out1 = c(rep(1,400),rep(0,600)),
                   out2 = c(rep(1,200),rep(0,800)),
                   out3 = c(rep(1,100),rep(0,900)),
                   out4 = c(rep(1,500),rep(0,500))) %>% 
  sample_n(300) %>% 
  mutate_at(vars(starts_with("out")),factor)
data
#> # A tibble: 300 x 5
#>     test out1  out2  out3  out4 
#>    <dbl> <fct> <fct> <fct> <fct>
#>  1  1.02 0     0     0     0    
#>  2  3.64 0     0     0     0    
#>  3  5.27 0     0     0     0    
#>  4  4.62 0     0     0     0    
#>  5  4.16 0     0     0     0    
#>  6  2.88 1     1     0     1    
#>  7  4.40 1     1     1     1    
#>  8  6.46 0     0     0     0    
#>  9  3.82 1     1     0     1    
#> 10  4.04 0     0     0     0    
#> # ... with 290 more rows

# loop and plots
out <- c("out1","out2","out3","out4")
plot <- out %>%
  map(~cutpointr(data = data, x = test, class = pull(data, .), pos_class = 1, neg_class = 0, method = oc_youden_normal,  metric = ppv) %>%
        plot_sensitivity_specificity +
        geom_vline(xintercept = c(1,5, 7.5), col="dodgerblue2") +
        xlab(paste("cutpoint for",.))) %>% 
  set_names(out)
#> Assuming the positive class has lower x values
#> Assuming the positive class has lower x values
#> Assuming the positive class has lower x values
#> Assuming the positive class has higher x values
#> Warning in method(data = dat$data[[1]], x = predictor, class = outcome, :
#> Cutpoint -3.40934500415604 was restricted to range of independent variable

cowplot::plot_grid(plot$out1, plot$out2, plot$out3, plot$out4)

Created on 2018-08-25 by the reprex package (v0.2.0).

from cutpointr.

Thie1e avatar Thie1e commented on May 30, 2024

You can do it manually as below. The problem is IMO that data is not tidy which makes it harder (gather it first and treat the out columns as subgroups).

Actually, this might also be a good addition to the package. We could just offer the option to make facets instead of different shapes for the subgroups - but this would take some work. I'll open an issue.

library(cutpointr); library(tidyverse)
data <- data_frame(test = runif(1000, min=0, max=10),
                   out1 = c(rep(1,400),rep(0,600)),
                   out2 = c(rep(1,200),rep(0,800)),
                   out3 = c(rep(1,100),rep(0,900)),
                   out4 = c(rep(1,500),rep(0,500))) %>% 
    sample_n(300) %>% 
    mutate_at(vars(starts_with("out")),factor)

# 
# This would be the "cutpointr way" of doing it. Gather the data first.
# 
cp <- data %>% 
    gather(key, value, -test) %>% 
    cutpointr(test, value, key) 
#> Assuming the positive class is 1
#> Assuming the positive class has higher x values
plot_sensitivity_specificity(cp)

# Facet wrap:
res_unnested <- cp %>% 
    select(roc_curve, subgroup, optimal_cutpoint) %>% 
    unnest(roc_curve) %>% 
    mutate(Sensitivity = sensitivity(tp = tp, fn = fn),
           Specificity = specificity(fp = fp, tn = tn)) %>% 
    gather(metric, value, Sensitivity, Specificity) %>% 
    filter(is.finite(x.sorted))  
#> Warning: attributes are not identical across measure variables;
#> they will be dropped
ggplot(res_unnested, aes(x = x.sorted, y = value, color = metric)) + 
    geom_line() +
    geom_vline(aes(xintercept = optimal_cutpoint)) +
    facet_wrap(~subgroup)

Created on 2018-09-03 by the reprex
package
(v0.2.0).

from cutpointr.

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.