[R-SIG-Mac]rpy-0.3

Jan de Leeuw deleeuw@stat.ucla.edu
Wed, 4 Dec 2002 17:23:22 -0800


--Apple-Mail-9-614660881
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

At http://gifi.stat.ucla.edu/pub you will find site-packages.tar.gz,
which you unpack in root, and which installs site-packages for
the python-2.2 that comes with Jaguar. It contains the xmlplus,
pyobjc, and rpy packages.

If installed you should be able to run the example below (due to
Tim Chuches) by saying "python faithful.py" in the terminal. The
example gives its alphanumerical output in the terminal and
creates three pdf files with plots.


--Apple-Mail-9-614660881
Content-Disposition: attachment;
	filename=faithful.py
Content-Transfer-Encoding: 7bit
Content-Type: application/text;
	x-unix-mode=0644;
	x-mac-type=54455854;
	name="faithful.py"

from rpy import *

faithful_data = {"eruption_duration":[],
                 "waiting_time":[]}
		 
f = open('faithful.dat','r')

for row in f.readlines()[1:]: # skip the column header line
    splitrow = row[:-1].split(" ")
    faithful_data["eruption_duration"].append(float(splitrow[0]))
    faithful_data["waiting_time"].append(int(splitrow[1]))

f.close()

ed = faithful_data["eruption_duration"] 
edsummary = r.summary(ed)
print "Summary of Old Faithful eruption duration data"
for k in edsummary.keys():
    print k + ": %.3f" % edsummary[k]
print    
print "Stem-and-leaf plot of Old Faithful eruption duration data"
print r.stem(ed)

r.pdf('faithful_histogram.pdf',width=6,height=4)
r.hist(ed,r.seq(1.6, 5.2, 0.2), prob=1,col="lightgreen",main="Old Faithful eruptions",xlab="Eruption duration (seconds)")
r.lines(r.density(ed,bw=0.1),col="orange")
r.rug(ed)
r.dev_off()

long_ed = filter(lambda x: x > 3, ed)
r.pdf('faithful_ecdf.pdf',width=6,height=4)
r.library('stepfun')
r.plot(r.ecdf(long_ed), do_points=0, verticals=1, main="Empirical cumulative distribution function of Old Faithful eruptions longer than 3 seconds")
x = r.seq(3,5.4,0.01)
r.lines(r.seq(3,5.4,0.01),r.pnorm(r.seq(3,5.4,0.01),mean=r.mean(long_ed), sd=r.sqrt(r.var(long_ed))), lty=3, lwd=2, col="red")
r.dev_off()

r.pdf('faithful_qq.pdf',width=6,height=4)
r.par(pty="s")
r.qqnorm(long_ed, col="blue")
r.qqline(long_ed, col="red")
r.dev_off()

r.library('ctest')
print
print "Shapiro-Wilks normality test of Old Faithful eruptions longer than 3 seconds"
sw = r.shapiro_test(long_ed)
print "W = %.4f" % sw['statistic']['W']
print "p-value = %.5f" % sw['p.value']

print
print "One-sample Kolmogorov-Smirnov test of Old Faithful eruptions longer than 3 seconds"
ks = r.ks_test(long_ed,"pnorm", mean=r.mean(long_ed), sd=r.sqrt(r.var(long_ed)))
print "D = %.4f" % ks['statistic']['D']
print "p-value = %.4f" % ks['p.value']
print "Alternative hypothesis: %s" % ks['alternative']
print


--Apple-Mail-9-614660881
Content-Disposition: attachment;
	filename=faithful.dat
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="faithful.dat"

"eruptions" "waiting"
3.6 79
1.8 54
3.333 74
2.283 62
4.533 85
2.883 55
4.7 88
3.6 85
1.95 51
4.35 85
1.833 54
3.917 84
4.2 78
1.75 47
4.7 83
2.167 52
1.75 62
4.8 84
1.6 52
4.25 79
1.8 51
1.75 47
3.45 78
3.067 69
4.533 74
3.6 83
1.967 55
4.083 76
3.85 78
4.433 79
4.3 73
4.467 77
3.367 66
4.033 80
3.833 74
2.017 52
1.867 48
4.833 80
1.833 59
4.783 90
4.35 80
1.883 58
4.567 84
1.75 58
4.533 73
3.317 83
3.833 64
2.1 53
4.633 82
2 59
4.8 75
4.716 90
1.833 54
4.833 80
1.733 54
4.883 83
3.717 71
1.667 64
4.567 77
4.317 81
2.233 59
4.5 84
1.75 48
4.8 82
1.817 60
4.4 92
4.167 78
4.7 78
2.067 65
4.7 73
4.033 82
1.967 56
4.5 79
4 71
1.983 62
5.067 76
2.017 60
4.567 78
3.883 76
3.6 83
4.133 75
4.333 82
4.1 70
2.633 65
4.067 73
4.933 88
3.95 76
4.517 80
2.167 48
4 86
2.2 60
4.333 90
1.867 50
4.817 78
1.833 63
4.3 72
4.667 84
3.75 75
1.867 51
4.9 82
2.483 62
4.367 88
2.1 49
4.5 83
4.05 81
1.867 47
4.7 84
1.783 52
4.85 86
3.683 81
4.733 75
2.3 59
4.9 89
4.417 79
1.7 59
4.633 81
2.317 50
4.6 85
1.817 59
4.417 87
2.617 53
4.067 69
4.25 77
1.967 56
4.6 88
3.767 81
1.917 45
4.5 82
2.267 55
4.65 90
1.867 45
4.167 83
2.8 56
4.333 89
1.833 46
4.383 82
1.883 51
4.933 86
2.033 53
3.733 79
4.233 81
2.233 60
4.533 82
4.817 77
4.333 76
1.983 59
4.633 80
2.017 49
5.1 96
1.8 53
5.033 77
4 77
2.4 65
4.6 81
3.567 71
4 70
4.5 81
4.083 93
1.8 53
3.967 89
2.2 45
4.15 86
2 58
3.833 78
3.5 66
4.583 76
2.367 63
5 88
1.933 52
4.617 93
1.917 49
2.083 57
4.583 77
3.333 68
4.167 81
4.333 81
4.5 73
2.417 50
4 85
4.167 74
1.883 55
4.583 77
4.25 83
3.767 83
2.033 51
4.433 78
4.083 84
1.833 46
4.417 83
2.183 55
4.8 81
1.833 57
4.8 76
4.1 84
3.966 77
4.233 81
3.5 87
4.366 77
2.25 51
4.667 78
2.1 60
4.35 82
4.133 91
1.867 53
4.6 78
1.783 46
4.367 77
3.85 84
1.933 49
4.5 83
2.383 71
4.7 80
1.867 49
3.833 75
3.417 64
4.233 76
2.4 53
4.8 94
2 55
4.15 76
1.867 50
4.267 82
1.75 54
4.483 75
4 78
4.117 79
4.083 78
4.267 78
3.917 70
4.55 79
4.083 70
2.417 54
4.183 86
2.217 50
4.45 90
1.883 54
1.85 54
4.283 77
3.95 79
2.333 64
4.15 75
2.35 47
4.933 86
2.9 63
4.583 85
3.833 82
2.083 57
4.367 82
2.133 67
4.35 74
2.2 54
4.45 83
3.567 73
4.5 73
4.15 88
3.817 80
3.917 71
4.45 83
2 56
4.283 79
4.767 78
4.533 84
1.85 58
4.25 83
1.983 43
2.25 60
4.75 75
4.117 81
2.15 46
4.417 90
1.817 46
4.467 74

--Apple-Mail-9-614660881
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	delsp=yes;
	charset=US-ASCII;
	format=flowed


===
Jan de Leeuw; Professor and Chair, UCLA Department of Statistics;
Editor: Journal of Multivariate Analysis, Journal of Statistical  
Software
US mail: 9432 Boelter Hall, Box 951554, Los Angeles, CA 90095-1554
phone (310)-825-9550;  fax (310)-206-5658;  email: deleeuw@stat.ucla.edu
homepage: http://gifi.stat.ucla.edu
   
------------------------------------------------------------------------ 
-------------------------
           No matter where you go, there you are. --- Buckaroo Banzai
                    http://gifi.stat.ucla.edu/sounds/nomatter.au
   
------------------------------------------------------------------------ 
------------------------- 
        
--Apple-Mail-9-614660881--