# updated 7/12/2010 to include As, Pb, Mo
# updated 4/21/2010 to include Uranium

# This S-PLUS script computes correlations (Spearmans Rho) between analytes 

# Major ion, nutrient, and trace data nondetects have been recensored from Reporting Levels to Detection Level
# This way the samples are retained but are very small relative to the true detections
# Radchem nondetects are equal to the sample specific reporting level

# Low Tritium values and non-detects censored to 0.3
# Low DO values and non-detects censored to 0.18 (some non-detects were < 0.1)
# 8 Mn non-detects at < 1 were removed because of the high detection level from 1996
# 2 Ni non-detects at < 1 were removed because of the high detection level from 1996
# 18 U non-detects at < 1 were removed because of the high detection level from 1996
# AS, PB, Mo non-detects at < 1 were removed, as well as other elevated non-detects for these



# Text output will be written to the file specified in the sink command.
sink("report.spearman.corr.all.txt")


# Read data file
attach.data.frame(camord_nawqa_spearman)

# print a matrix of correlation coefficients
print(cor.all(camord_nawqa_spearman, method='s', na.method='pairwise')$estimates)

# print a matrix of p values
print(cor.all(camord_nawqa_spearman, method='s', na.method='pairwise')$p.values)

# print a matrix of the number of observations
print(cor.all(camord_nawqa_spearman, method='s', na.method='pairwise')$counts)


# Detach the data frame
detach(camord_nawqa_spearman)

# close output file
sink()