Monday, May 19, 2014

Radiation Sampling with Visual Comparisons : Part II



RM80 <- function() {
require(plyr) # for 'count'
options(graphics.record=TRUE)
# RMF Media/ RMF Network Security 7:00 PM 3/20/2014. Tested on R 3.03
# Takes four CSV samples (One Control and Two Samples) from Aware Electronics RM-80 GM Counter.
# Configured to read data from "n TBU per line" for any Time Base Unit . I use TBU = 2.
# Samples must have headers with "Time" and "MicroRads_HR" (separated by tab) like this:
# Time MicroRads_HR
# 37264.91529 8.47
# 37264.91531 8.47
# 37264.91534 16.95

# Four Samples
# From Aware-Electronics Manual:
# "MicroRads_HR = microroentgens/hr"
# "One roentgen equals one thousand milliroentgens (1R = 1000mR), and one milliroentgen equals one thousand microroentgens
# (1mR = 1000uR)."

# These files can be found at ftp://rmfmedia.com/web-root/CSV/
 print("Four samples:")
 print("Control is Room Air.")
 print("Sample1 is a high (MERV rating) rated blank filter with metal grate still in sealed plastic.")
 print("Sample2 Tests high (MERV rating) air filter located outside 8 inch external air intake for  approximately one month.")
 print("Sample2 RM80 stationary against center of filter while covered in plastic sack.")
 print("Sample3 Tests high (MERV rating) air filter located outside 8 inch external air intake for  approximately one month.")
 print("Sample3 : RM80 stationary against center of filter without barrier.")

 s <- read.delim("roomair.csv",header=TRUE,sep="\t")
 b <- read.delim("blankfilter.csv",header=TRUE,sep="\t")
 c <- read.delim("05.24.2014_ExtFilter.csv",header=TRUE,sep="\t")
 d <- read.delim("05.24.2014_ExtFilter_np.csv",header=TRUE,sep="\t")
 print("Time Base Unit is 2 seconds. MicroRads_HR = microroentgens/hr")
# Select equal amounts of data
 s <- s[1:718,]
 b <- b[1:718,]
 c <- c[1:718,]
 d <- d[1:718,]

 e <- cbind("s1"=s,"s2"=b,"s3"=c,"s4"=d)
e <- e[,c(2,4,6,8)
summary(e)

cols <- as.data.frame(rbind(nrow(subset(s, select = MicroRads_HR)),
nrow(subset(b, select = MicroRads_HR)),
nrow(subset(c, select = MicroRads_HR)),
nrow(subset(d, select = MicroRads_HR))))

colZero <- as.data.frame(rbind(nrow(subset(s, MicroRads_HR ==0.00, select = MicroRads_HR)),
nrow(subset(b, MicroRads_HR ==0.00, select = MicroRads_HR)),
nrow(subset(c, MicroRads_HR ==0.00, select = MicroRads_HR)),
nrow(subset(d, MicroRads_HR ==0.00, select = MicroRads_HR))))

colmin <-  as.data.frame(rbind(min(subset(s, MicroRads_HR !=0.00, select = MicroRads_HR)),
min(subset(b, MicroRads_HR !=0.00, select = MicroRads_HR)),
min(subset(c, MicroRads_HR !=0.00, select = MicroRads_HR)),
min(subset(d, MicroRads_HR !=0.00, select = MicroRads_HR))))

colmax <-  as.data.frame(rbind( max(s$MicroRads_HR),max(b$MicroRads_HR), max(c$MicroRads_HR), max(d$MicroRads_HR)))
colmean <-  as.data.frame(rbind( mean(s$MicroRads_HR), mean(b$MicroRads_HR), mean(c$MicroRads_HR), mean(d$MicroRads_HR)))
colsd <-  as.data.frame(rbind(sd(s$MicroRads_HR),sd(b$MicroRads_HR), sd(c$MicroRads_HR), sd(d$MicroRads_HR)))
colstats <- as.data.frame(c("Samples"=cols,"SampleEqZero"=colZero,"MinNot0"=colmin,"max"=colmax,"mean"=colmean,"sd"=colsd),check.names=TRUE,row.names=c("Control","Sample1","Sample2","Sample3"))

print("Sample Statistics for Non Zero Data:")
print(colstats)

# Graphs Not Useful Enough 6:27 PM 3/20/2014
# print("Sending Four Graphs of Sample Statistics")
# barplot(colstats$MinNot0.V1, names.arg=c("Control", "Sample1", "Sample2", "Sample3"),horiz=TRUE,,xlab="Min != 0")
# barplot(colstats$max.V1, names.arg=c("Control", "Sample1", "Sample2", "Sample3"),horiz=TRUE,xlab="Max microRoentgens/hr")
# barplot(colstats$mean.V1, names.arg=c("Control", "Sample1", "Sample2", "Sample3"),horiz=TRUE,xlab="Mean microRoentgens/hr")
# barplot(colstats$sd.V1, names.arg=c("Control", "Sample1", "Sample2", "Sample3"),horiz=TRUE,xlab="StDev microRoentgens/hr")

cat("\n")
print("Matrix Information for Non Zero Data")
print("Control")
print(count(subset(s, MicroRads_HR !=0.00, select = MicroRads_HR)))
smat <- as.matrix(count(subset(s, MicroRads_HR !=0.00, select = MicroRads_HR)))
smatt <- (smat[1:nrow(smat),1]) %*% (smat[1:nrow(smat),2])

print("Sample1")
print(count(subset(b, MicroRads_HR !=0.00, select = MicroRads_HR)))
bmat <- as.matrix(count(subset(b, MicroRads_HR !=0.00, select = MicroRads_HR)))
bmatt <- (bmat[1:nrow(bmat),1]) %*% (bmat[1:nrow(bmat),2])

print("Sample2")
print(count(subset(c, MicroRads_HR !=0.00, select = MicroRads_HR)))
cmat <- as.matrix(count(subset(c, MicroRads_HR !=0.00, select = MicroRads_HR)))
cmatt <- (cmat[1:nrow(cmat),1]) %*% (cmat[1:nrow(cmat),2])

print("Sample3")
print(count(subset(d, MicroRads_HR !=0.00, select = MicroRads_HR)))
dmat <- as.matrix(count(subset(d, MicroRads_HR !=0.00, select = MicroRads_HR)))
dmatt <- (dmat[1:nrow(dmat),1]) %*% (dmat[1:nrow(dmat),2])

cat("\n")
print("Sending Four time-based Graphs of MicroRads_HR Averages Non Zero Data")
barplot(s$MicroRads_HR,xlab="Control", ylab="Non-Zero microRoentgens/hr",legend.text=c(rev(smat[,1])))
barplot(b$MicroRads_HR,xlab="Sample 1",ylab="Non-Zero microRoentgens/hr",legend.text=c(rev(bmat[,1])))
barplot(c$MicroRads_HR,xlab="Sample 2",ylab="Non-Zero microRoentgens/hr",legend.text=c(rev(cmat[,1])))
barplot(d$MicroRads_HR,xlab="Sample 3",ylab="Non-Zero microRoentgens/hr",legend.text=c(rev(dmat[,1])))

print("Sending Four frequency-based Graphs of MicroRads_HR Averages for Non Zero Data")
barplot(as.matrix(count(subset(s, MicroRads_HR !=0.00, select = MicroRads_HR))),legend.text=c(smat[,1]),xlab="Stacked as per Legend", ylab="Control")
barplot(as.matrix(count(subset(b, MicroRads_HR !=0.00, select = MicroRads_HR))),legend.text=c(bmat[,1]),xlab="Stacked as per Legend", ylab="Sample 1")
barplot(as.matrix(count(subset(c, MicroRads_HR !=0.00, select = MicroRads_HR))),legend.text=c(cmat[,1]),xlab="Stacked as per Legend",  ylab="Sample 2")
barplot(as.matrix(count(subset(d, MicroRads_HR !=0.00, select = MicroRads_HR))),legend.text=c(dmat[,1]),xlab="Stacked as per Legend",  ylab="Sample 3")

cat("\n")
matstats <- data.frame("MR/HR.Mtrx.Mult"=rbind(smatt,bmatt,cmatt,dmatt),check.names=TRUE,row.names=c("Control","Sample1","Sample2","Sample3"))
print("(Matrix) Sums of row based multiplication for non zero samples.")
print(matstats)
}

No comments:

Post a Comment