Welcome to my Open Notebook

This is an Open Notebook with Selected Content - Delayed. All content is licenced with CC-BY. Find out more Here.

ONS-SCD.png

reproducible-research-reports-using-emacs-orgmode-export-to-knitr

  • Emacs orgmode is so good for Reproducible Research Reports. Check out the paper by Eric Schulte et al “A Multi-Language Computing Environment for Literate Programming”
  • it provides a good export function to convert the code file into a html or latex report using C-c C-e h OR C-c C-e l respectively.
  • but I have found there are some limitations with these export reports compared to knitr
  • primarily the limitation of the need to include the images as seperate files whereas knitr encodes these explicitly in the report is the one I dislike the most
  • another limitation is the way that tables are handled
  • HOWEVER the code editing features of Emacs orgmode are so superior to the other options I have tried to write knitr documents in that I feel it is worth trying to find some middle ground.
  • I have been happy for a little while using a method of writing documents in Emacs orgmode and exporting the text and code Chunks to a knitr RMD file, and then compiling that file to create the report.
  • I have set up an example using the classic Challenger Space Shuttle logistic regression in this file

The Output

Reproducible Research Report using Emacs orgmode to knitr

ivan.hanigan@anu.edu.au

Introduction

  • This is an example or a Reproducible Research Report.
  • The report is the output of a program written in Emacs orgmode, which constructs a knitr document and creates this HTML output.

logistic regression of the challenger disaster

The problem was with the failure rate (and number of) O-rings that failed (n.fail) related to the temperature (temp).

name:create-data

# n.fail = failed o rings
# totalMinusNfail = total-n.fail
# total = there were 6 o rings for each of 23 attempts
# pfail = probability of fail pFail <- n.fail/total
# temp = temperature (F)

dat <- read.csv(textConnection(
"nfail, totalMinusNfail, total,     pFail,       temp
2,               4,     6,          0.3333333,   53
0,               6,     6,          0.0000000,   66
0,               6,     6,          0.0000000,   68
1,               5,     6,          0.1666667,   70
0,               6,     6,          0.0000000,   75
0,               6,     6,          0.0000000,   78
1,               5,     6,          0.1666667,   57
0,               6,     6,          0.0000000,   67
0,               6,     6,          0.0000000,   69
1,               5,     6,          0.1666667,   70
2,               4,     6,          0.3333333,   75
0,               6,     6,          0.0000000,   79
1,               5,     6,          0.1666667,   58
0,               6,     6,          0.0000000,   67
0,               6,     6,          0.0000000,   70
0,               6,     6,          0.0000000,   72
0,               6,     6,          0.0000000,   76
0,               6,     6,          0.0000000,   81
1,               5,     6,          0.1666667,   63
0,               6,     6,          0.0000000,   67
0,               6,     6,          0.0000000,   70
0,               6,     6,          0.0000000,   73
0,               6,     6,          0.0000000,   76
"))
nfail totalMinusNfail total pFail temp
2 4 6 0.33 53
0 6 6 0.00 66
0 6 6 0.00 68
1 5 6 0.17 70
0 6 6 0.00 75
0 6 6 0.00 78
1 5 6 0.17 57
0 6 6 0.00 67
0 6 6 0.00 69
1 5 6 0.17 70
2 4 6 0.33 75
0 6 6 0.00 79
1 5 6 0.17 58
0 6 6 0.00 67
0 6 6 0.00 70
0 6 6 0.00 72
0 6 6 0.00 76
0 6 6 0.00 81
1 5 6 0.17 63
0 6 6 0.00 67
0 6 6 0.00 70
0 6 6 0.00 73
0 6 6 0.00 76
#### learnR-logistic
png("pfail.png")
with(dat, plot(temp, pFail, pch = 16, xlim = c(40, 100), ylim = c(0, 0.4)))
title("A plot of the proportion failed by temperature")
dev.off()

pdf 2

pfail.png

fit model

# newnode: linear names(dat)
resp <- cbind(dat$nfail, dat$totalMinusNfail)
temp <- dat$temp
linear <- glm(resp ~ 1 + temp, family = binomial(link = logit))
# TODO this just prints the codes not the table?  xtable(linear, type =
# 'html')

Model Diagnostics

cf <- linearoutput$coeff
signif(cf[which(row.names(cf) == "temp"), "Estimate"], 2)

[1] -0.12

png("challengerLogistic.png")
par(mfrow = c(2, 2))
plot(linear)
dev.off()

pdf 2

challengerLogistic.png

plot-model

dummy <- data.frame(temp = seq(20, 100, 1))
pred.prob <- predict.glm(linear, newdata = dummy, type = "resp")
png("pfailfit.png")
with(dat, plot(temp, pFail, xlab = "Launch Temperature (F)", ylab = "Proportion Failing", 
    pch = 16, xlim = c(20, 100), ylim = c(0, 1)))
lines(dummy$temp, pred.prob)
dev.off()

pdf 2

pfailfit.png

Posted in  research methods


blog comments powered by Disqus