Skip to content

Instantly share code, notes, and snippets.

@krisselden
Last active July 5, 2016 09:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisselden/55ddfa5b081fec16d88c8881768ec472 to your computer and use it in GitHub Desktop.
Save krisselden/55ddfa5b081fec16d88c8881768ec472 to your computer and use it in GitHub Desktop.
# Plot and Test Samples in R

Plot and Test Samples in R

Install R

https://cran.r-project.org/bin/

Setup

chmod a+x plot.R

Run

./plot.R <samples.csv
open boxplot.svg
open histogram.svg

Notes:

The wilcox.test does not assume the data to be normal and is only answering a yes/no for whether the sample sets came from the same overall set (the null hypothesis).

The dots in the box plot are outliers defined as outside 1.5 x IQR (Interquartile Range; the length between the 25th and 75th percentile).

Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/env Rscript
samples = read.csv('stdin')
# by default levels for string factor is alphabetical
# but we want experiment to be x
samples$set <- relevel(samples$set, ref = "experiment")
# test whether the true location of the distribution is shifted
# does not require data to be normally distributed
wilcox.test(µs ~ set, data=samples, conf.int=TRUE)
svg(file = "boxplot.svg")
boxplot(µs ~ set, data=samples)
dev.off()
require(lattice)
svg(file = "histogram.svg")
histogram(~µs | set, data=samples, breaks=nclass.FD)
dev.off()
µs set
43313 control
28189 control
27637 control
33314 control
53477 control
34702 control
26953 control
26048 control
27371 control
40655 control
39419 control
38938 control
29021 control
39428 control
39855 control
25923 control
27741 control
46040 control
31118 control
30566 control
45420 control
30097 control
30534 control
42314 control
30593 control
33346 control
33558 control
37621 control
40106 control
40221 control
46198 experiment
31762 experiment
32098 experiment
27719 experiment
30731 experiment
28709 experiment
40079 experiment
27907 experiment
27790 experiment
25135 experiment
30395 experiment
27865 experiment
29005 experiment
25567 experiment
31863 experiment
43582 experiment
30878 experiment
24699 experiment
31193 experiment
30376 experiment
29083 experiment
28794 experiment
58157 experiment
31611 experiment
32067 experiment
30361 experiment
42587 experiment
28048 experiment
30454 experiment
30126 experiment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment