Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/cran/cutpointr
12 May 2022, 17:57:39 UTC
  • Code
  • Branches (12)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/master
    • refs/tags/0.7.2
    • refs/tags/0.7.3
    • refs/tags/0.7.4
    • refs/tags/0.7.6
    • refs/tags/1.0.0
    • refs/tags/1.0.1
    • refs/tags/1.0.2
    • refs/tags/1.0.32
    • refs/tags/1.1.0
    • refs/tags/1.1.1
    • refs/tags/1.1.2
    No releases to show
  • 8191cef
  • /
  • vignettes
  • /
  • cutpointr_plotting.Rmd
Raw File Download Save again
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge
swh:1:cnt:45b22caefc7f8a16aa296c5ee07050b35568e70a
origin badgedirectory badge
swh:1:dir:f6e218e063eadacdbea06f271645f8f9ecdebca3
origin badgerevision badge
swh:1:rev:4408233eb8624dea85ecf18e86d50c296165c3f2
origin badgesnapshot badge
swh:1:snp:59fa548f9fdef2e9cfbec66f8a33531d45433c4b

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
Tip revision: 4408233eb8624dea85ecf18e86d50c296165c3f2 authored by Christian Thiele on 13 April 2022, 17:12:29 UTC
version 1.1.2
Tip revision: 4408233
cutpointr_plotting.Rmd
---
title: "Plotting with cutpointr"
author: "Christian Thiele"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Plotting with cutpointr}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(fig.width = 6, fig.height = 5, fig.align = "center")
options(rmarkdown.html_vignette.check_title = FALSE)
load("vignettedata/vignettedata.Rdata")
```


**cutpointr** includes several convenience functions for plotting data from a 
`cutpointr` object. These include:

- `plot_cutpointr`: General purpose plotting function for cutpointr or roc_cutpointr objects
- `plot_cut_boot`: Plot the bootstrapped distribution of optimal cutpoints
- `plot_metric`: If `maximize_metric` or `minimize_metric` was used this function
plots all possible cutoffs on the x-axis vs. the respective metric values on
the y-axis. If bootstrapping was run, a confidence interval based on the 
bootstrapped distribution of metric values at each cutpoint can be displayed. 
To display no confidence interval set `conf_lvl = 0`.
- `plot_metric_boot`: Plot the distribution of out-of-bag metric values
- `plot_precision_recall`: Plot the precision recall curve
- `plot_sensitivity_specificity`: Plot all cutpoints vs. sensitivity and specificity
- `plot_roc`: Plot the ROC curve
- `plot_x`: Plot the distribution of the predictor variable

```{r, fig.width=4, fig.height=3}
library(cutpointr)

set.seed(123)
opt_cut_b_g <- cutpointr(suicide, dsi, suicide, gender, boot_runs = 500)

plot_cut_boot(opt_cut_b_g)
plot_metric(opt_cut_b_g, conf_lvl = 0.9)
plot_metric_boot(opt_cut_b_g)
plot_precision_recall(opt_cut_b_g)
plot_sensitivity_specificity(opt_cut_b_g)
plot_roc(opt_cut_b_g)
```

All plot functions, except for the standard plot method that returns
a composed plot, return `ggplot` objects
than can be further modified. For example, changing labels, title, and the theme
can be achieved this way:

```{r, fig.width=4, fig.height=3}
library(ggplot2)
p <- plot_x(opt_cut_b_g)
p + ggtitle("Distribution of dsi") + 
    theme_minimal() + 
    xlab("Depression score")
```

## Flexible plotting function

Using `plot_cutpointr` any metric can be chosen to be plotted on the x- or
y-axis and results of `cutpointr()` as well as `roc()` can be plotted.
If a `cutpointr` object is to be plotted, it is thus irrelevant which `metric` 
function was chosen for cutpoint estimation. Any metric that can be calculated
based on the ROC curve can be subsequently plotted as only the true / false
positives / negatives over all cutpoints are needed.
That way, not only the above plots can be produced, but also any 
combination of two metrics (or metric functions) and / or cutpoints. The built-in
metric functions as well as user-defined functions or anonymous functions can
be supplied to `xvar` and `yvar`. If bootstrapping was run, confidence intervals
can be plotted around the y-variable. This is especially useful if the cutpoints,
available in the `cutpoints` function, are placed on the x-axis. 
Note that confidence intervals can only be correctly plotted if the values of 
`xvar` are constant across bootstrap samples. For example, confidence intervals 
for TPR by FPR (a ROC curve) cannot be plotted easily, as the values of the false 
positive rate vary per bootstrap sample.

```{r, fig.width=4, fig.height=3, cache=FALSE}
set.seed(1234)
opt_cut_b <- cutpointr(suicide, dsi, suicide, boot_runs = 500)

plot_cutpointr(opt_cut_b, xvar = cutpoints, yvar = sum_sens_spec, conf_lvl = 0.9)
plot_cutpointr(opt_cut_b, xvar = fpr, yvar = tpr, aspect_ratio = 1, conf_lvl = 0)
plot_cutpointr(opt_cut_b, xvar = cutpoint, yvar = tp, conf_lvl = 0.9) + 
    geom_point()
```


## Manual plotting

Since `cutpointr` returns a `data.frame` with the original data, bootstrap
results, and the ROC curve in nested tibbles, these data can be conveniently 
extracted and plotted manually. The relevant
nested tibbles are in the columns `data`, `roc_curve` and `boot`. The following
is an example of accessing and plotting the grouped data.

```{r, fig.width=4, fig.height=3}
library(dplyr)
library(tidyr)
opt_cut_b_g |> 
    select(data, subgroup) |> 
    unnest(cols = data) |> 
    ggplot(aes(x = suicide, y = dsi)) + 
    geom_boxplot(alpha = 0.3) + 
    facet_grid(~subgroup)
```

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API