Skip to content

Instantly share code, notes, and snippets.

@eliardocosta
Last active August 2, 2017 20:30
Show Gist options
  • Save eliardocosta/ea37479b88f81a402ebb6c382ef1097c to your computer and use it in GitHub Desktop.
Save eliardocosta/ea37479b88f81a402ebb6c382ef1097c to your computer and use it in GitHub Desktop.
The R codes to implement the algorithms and figures in Costa, Lopes & Singer (2016).

Description

These are the R codes to implement the algorithms and figures in Costa, Lopes & Singer (2016).

Reference

License

The MIT License (MIT)

Copyright (c) 2016-2017 Eliardo G. Costa & Julio M. Singer

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#--------------------------------
# Fig. 1 Supplementary Material
#--------------------------------
par(cex.main = 2, cex.lab = 1.5)
plot(function(x) 1 - exp(-x), 0, 3, xlab = expression(lambda~~(org/10~~L)),
ylab = expression(paste(P, "(", X>=1, "| ", lambda, ")")))
abline(v = 0.1, col = "red")
abline(h = 0.95, col = "blue")
text(0.60, 0.75, "0.10 org/10 L", cex = 1.5)
text(1, 0.91, "0.95", cex = 1.5)
#----------------------------------
# Fig. 1 Absolute error case: ea=2
#----------------------------------
par(cex.main = 2, cex.lab = 1.5, mai = c(0.9, 0.95, 0.5, 0.5))
plot(1, type = "n", xlim = c(0, 20), ylim = c(0, 20),
xlab = expression(paste(bold(widehat(lambda)), " : sample mean concentration")),
ylab = expression(paste(bold(lambda), ": true (unknown) concentration")),
axes = FALSE)
title(expression(paste("Absolute error case ", (epsilon[a]==2))))
axis(1, at = c(8, 10, 12, 15), lwd = 2)
axis(1, at = c(0, 20), lwd = 2, labels = FALSE)
axis(2, at = c(10, 13, 17), lwd = 2)
axis(2, at = c(0, 20), lwd = 2, labels = FALSE)
polygon(c(2, 2, 21, 21), c(0, 4, 23, 19), density = 10, border = NA, angle =80 ,
col = "grey")
polygon(c(0, 0, 2, 2), c(0, 2, 4, 0), density = 10, border = NA, angle = 80,
col = "grey")
abline(h = 10, col = "blue", lwd = 4)
text(1.5, 10.7, "D-2 limit")
abline(a = 2, b = 1, lwd = 2)
plot(function(x) ifelse(x > 2, x - 2, 0), xlim = c(2, 21), lwd = 2, add = TRUE)
segments(x0 = 8, y0 = 0, y1 = 10, lty = 2, lwd = 3)
segments(x0 = 12, y0 = 0, y1 = 14, lty = 2, lwd = 3)
segments(x0 = 15, y0 = 0, y1 = 17, lty = 2, lwd = 3)
segments(x0 = 0, y0 = 17, x1 = 15, lty = 2, lwd = 3)
segments(x0 = 0, y0 = 13, x1 = 15, lty = 2, lwd = 3)
segments(x0 = 0, y0 = 0, x1 = 8, col = "green", lwd = 5)
segments(x0 = 8, y0 = 0, x1 = 12, col = "yellow", lwd = 5)
segments(x0 = 12, y0 = 0, x1 = 20, col = "red", lwd = 5)
legend(c(0.5, 20.5), c("compliance range", "doubt range", "non-compliance range"),
pch = "", lwd = c(5, 5, 5), col = c("green", "yellow", "red"), bty = "n")
#------------------------------------
# Fig. 2 Relative error case: er=0.1
#------------------------------------
par(cex.main = 2, cex.lab = 1.5, mai = c(0.9, 0.95, 0.5, 0.5))
plot(1, type = "n", xlim = c(0, 20), ylim = c(0, 20),
xlab = expression(paste(bold(widehat(lambda)), ": sample mean concentration")),
ylab = expression(paste(bold(lambda), ": true (unknown) concentration")), axes = FALSE)
title(expression(paste("Relative error case ", (epsilon[r]==0.1))))
axis(1, at = c(9, 11, 15), lwd = 2)
axis(1, at = c(0, 20), lwd = 2, labels = FALSE)
axis(2, at = c(10), lwd = 2)
axis(2, at = c(round(15/0.9, 1), round(15/1.1, 1)), lwd = 2)
axis(1, at = c(10), lwd = 2)
axis(2, at = c(0, 20), lwd = 2, labels = FALSE)
polygon(c(0, 0, 21, 21), c(0, 0, 21/0.9, 21/1.1), density = 10,
border = NA, angle = 80, col = "grey")
abline(h = 10, col = "blue", lwd = 4)
text(1.5, 10.7, "D-2 limit")
abline(a = 0, b = 1/0.9, lwd = 2)
abline(a = 0, b = 1/1.1, lwd = 2)
segments(x0 = 9, y0 = 0, y1 = 10, lty = 2, lwd = 3)
segments(x0 = 11, y0 = 0, y1 = 11/0.9, lty = 2, lwd = 3)
segments(x0 = 15, y0 = 0, y1 = 15/0.9, lty = 2, lwd = 3)
segments(x0 = 0, y0 = 15/0.9, x1 = 15, lty = 2, lwd = 3)
segments(x0 = 0, y0 = 15/1.1, x1 = 15, lty = 2, lwd = 3)
segments(x0 = 0, y0 = 0, x1 = 9, col = "green", lwd = 5)
segments(x0 = 9, y0 = 0, x1 = 11, col = "yellow", lwd = 5)
segments(x0 = 11, y0 = 0, x1 = 20, col = "red", lwd = 5)
legend(c(0.5, 20.5), c("compliance range", "doubt range", "non-compliance range"),
pch = "", lwd = c(5, 5, 5), col = c("green", "yellow", "red"), bty = "n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment