Also, see the other R page at http://rkd.zgib.net/wiki/R.

Make Histograms

Read five data files, combine several of them, make pdf histograms

G1 = scan("GLASS BSA1.txt")
G2 = scan("GLASS BSA2.txt")
P1 = scan("PEG BSA1.txt")
P2 = scan("PEG BSA2.txt")
P3 = scan("PEG BSA3.txt")
# mode(c(G1, G2))  # does `c` combine it properly?  Also see below
# length(c(G1, G2))
hist(c(G1, G2))
hist(c(P1, P2, P3))
pdf()   # default filename is Rplots.pdf
hist(c(G1, G2), main="Glass")
hist(c(P1, P2, P3), main="PEG")
dev.off()   # pdfs in the file on separate pages

Doing Data analysis from python

Exp1 = r.read_table("CT-1.txt", na_strings='na')
wlen1 = Exp1["V1"]

# Let's say we want to plot the list TheoTemps vs the list powers

r.plot(log(TheoTemps), log(powers),
       xlab="ln(T)", ylab="ln(power)",
       main="Power/Temperature relationship")

model = r("log(powers) ~ log(TheoTemps) ")
#coef = r.lm(model), data=r.data_frame(powers=integrals, TheoTemps=TheoTemps))["
coefficients"]
r.lm.local_mode(rpy.NO_CONVERSION)
fit = r.lm(model, data={"powers": powers,
                        "TheoTemps": TheoTemps})
coef = fit.as_py()["coefficients"]
print coef
r.abline(b=coef['log(TheoTemps)'], a=coef['(Intercept)'])
r.dev_copy(r.postscript, file="plots/step9.eps",
           horizontal=False, onefile=False)
r.dev_off()


print fit.as_py()["coefficients"]
print r.summary(fit)["adj.r.squared"]

RExamples (last edited 2008-03-10 01:38:53 by localhost)