Last data update: 2014.03.03

R: function to build objects of class 'rocc'
rocdemo.scaR Documentation

function to build objects of class 'rocc'

Description

rocdemo.sca – demonstrate 'rocc' class construction using a scalar marker and simple functional rule

Usage

rocdemo.sca(truth, data, rule=NULL, 
       cutpts=NA,
       markerLabel="unnamed marker", caseLabel="unnamed diagnosis")

Arguments

truth

true classification of objects. Must take values 0 or 1.

data

quantitative markers used to classify

rule

rule: a function with arguments (x, thresh) returning 0 or 1. If no rule is provided or the standard rule dxrule.sca is passed, a faster C-based implementation is used to compute sensitivity and specificity.

cutpts

values of thresholds; no NA allowed, or they will be recomputed using smallest gap between data points with distinct values

markerLabel

textual label describing marker

caseLabel

textual label describing classification

Details

dxrule.sca is function (x, thresh) ifelse(x > thresh, 1, 0)

The default value of argument cutpts is a point less than min(data), points separating the unique values of data and a point greater than max(data).

Value

an object of S4 class rocc

Author(s)

Vince Carey (stvjc@channing.harvard.edu)

See Also

AUC

Examples

set.seed(123)
R1 <- rocdemo.sca( rbinom(40,1,.3), rnorm(40), caseLabel="new case", markerLabel="demo Marker" )
plot(R1, line=TRUE, show.thresh=TRUE)

truth <- c(0, 1, 0, 1, 1, 0, 1, 1)
data <- c(2, 3, 4, 4, 5, 6, 7, 8)
R2 <- rocdemo.sca(truth, data, dxrule.sca)
plot(R2, line=TRUE, show.thresh=TRUE)
R3 <- rocdemo.sca(truth, data, function(x, thresh) 1 - dxrule.sca(x, thresh))
if (AUC(R2) + AUC(R3) != 1) stop('Sum of AUCs should be 1.')
#
# more involved
#
set.seed(1234)
x = runif(1000)
w = runif(1000)
z = rbinom(1000, 1, plogis(-2.7+6.2*x + .3*w))
m1 = glm(z~x, fam=binomial)
demorule.glm.clo = function(model) function(w,thresh)
 ifelse(predict(model, newdata=list(x=w), type="response")>thresh, 1, 0)
demorule.glm = demorule.glm.clo(m1)
R4 = rocdemo.sca(z, x, demorule.glm )
plot(R4)
  

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(ROC)
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/ROC/rocdemo.sca.Rd_%03d_medium.png", width=480, height=480)
> ### Name: rocdemo.sca
> ### Title: function to build objects of class 'rocc'
> ### Aliases: rocdemo.sca dxrule.sca
> ### Keywords: models
> 
> ### ** Examples
> 
> set.seed(123)
> R1 <- rocdemo.sca( rbinom(40,1,.3), rnorm(40), caseLabel="new case", markerLabel="demo Marker" )
NA in cutpts forces recomputation using smallest gap
> plot(R1, line=TRUE, show.thresh=TRUE)
> 
> truth <- c(0, 1, 0, 1, 1, 0, 1, 1)
> data <- c(2, 3, 4, 4, 5, 6, 7, 8)
> R2 <- rocdemo.sca(truth, data, dxrule.sca)
NA in cutpts forces recomputation using smallest gap
> plot(R2, line=TRUE, show.thresh=TRUE)
> R3 <- rocdemo.sca(truth, data, function(x, thresh) 1 - dxrule.sca(x, thresh))
NA in cutpts forces recomputation using smallest gap
> if (AUC(R2) + AUC(R3) != 1) stop('Sum of AUCs should be 1.')
> #
> # more involved
> #
> set.seed(1234)
> x = runif(1000)
> w = runif(1000)
> z = rbinom(1000, 1, plogis(-2.7+6.2*x + .3*w))
> m1 = glm(z~x, fam=binomial)
> demorule.glm.clo = function(model) function(w,thresh)
+  ifelse(predict(model, newdata=list(x=w), type="response")>thresh, 1, 0)
> demorule.glm = demorule.glm.clo(m1)
> R4 = rocdemo.sca(z, x, demorule.glm )
NA in cutpts forces recomputation using smallest gap
> plot(R4)
>   
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>