R Statistics Snippets

Running in batch mode

  • For an R script file plot.R, session output put into output.txt
R CMD BATCH plot.R output.txt

Labelling Graphs

  • the parameters main="main title", xlab="x-axis label", ylab="y-axis label" can be added to plot() or provided subsequently via title()
plot(..., main="title")
title(xlab="X label")

Saving graphs

  • To save plot directly to a file use pdf() to open the pdf device before doing the plot(), then close using dev.off()
plot(..insert as appropriate...)

Using ROCR for ROC-style analysis

  • Data format
    • predictions needs to be an array of comparable values
      • smaller values assumed to be "more false"
    • labels should be binary (TRUE FALSE) array of the same size as the predictions
pred <- prediction(prediction_array, label_array)
# ROC curve
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf, col="red")
# Cumulative Gains chart
perf <- performance(pred, measure = "tpr", x.measure = "rpp")
plot(perf, col="red")
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.