On Dec 20, 2007 3:04 PM, Simon Beaumont <[EMAIL PROTECTED]> wrote:
>
> Is there some secret handshake I should use or did I ask a difficult
> question?

Give us money :-)  Just kidding!

A lot of Sage developers -- like me -- are on vacation for the
holidays right now.

> On Dec 18, 10:26 pm, Simon Beaumont <[EMAIL PROTECTED]> wrote:
> > Just installed 2.9 - how do I use the newly integrated R from sage?
> > documentation seems to be behind on this ;-)

Yep, there's no documentation at all included with Sage on how to use
R from Sage
or even that R is included in Sage.

To use R in a way that integrates nicely with Sage,  check out this webpage:

http://rpy.sourceforge.net/

Here is a notebook session that illustrates doing some things with
the R <--> Sage interface:

{{{id=16|
from rpy import *
r.t_test(range(10))
///
{'null.value': {'mean': 0.0}, 'data.name': '0:9', 'method': 'One
Sample t-test', 'p.value': 0.0011200178871001592, 'statistic': {'t':
4.7000967108038418}, 'estimate': {'mean of x': 4.5}, 'conf.int':
[2.3341494103318317, 6.6658505896681683], 'parameter': {'df': 9.0},
'alternative': 'two.sided'}
}}}

{{{id=17|
from rpy import *
v = [1,2,5, 10]
v = [int(z) for z in v]      # rpy doesn't play well with Sage types yet!!!
r.t_test(v)
///
{'null.value': {'mean': 0.0}, 'data.name': 'c(1L, 2L, 5L, 10L)',
'method': 'One Sample t-test', 'p.value': 0.11231741583919484,
'statistic': {'t': 2.2269224668742709}, 'estimate': {'mean of x':
4.5}, 'conf.int': [-1.930851808629775, 10.930851808629777],
'parameter': {'df': 3.0}, 'alternative': 'two.sided'}
}}}

{{{id=18|
from rpy import *
v = [random.random() for _ in range(10^4)]
r.mean(v)
///
0.50381458009226054
}}}

{{{id=19|
r.median(v)
///
0.50252807909097674
}}}

{{{id=21|
r.sd(v)
///
0.2889341870587569
}}}

{{{id=22|

}}}


This last may or may not work for you.  For me it popped up a window
with a plot in it.

{{{id=15|
from rpy import *
degrees = 4
grid = r.seq(0, 10, length=100)
values = [r.dchisq(x, degrees) for x in grid]
r.par(ann=0)
r.plot(grid, values, type='lines')
///
Warning message:
In plot.xy(xy, type, ...) :
  plot type 'lines' will be truncated to first character
}}}


We haven't quite stabilized how we will do plotting with R and the Sage notebook
yet.

Here's another big example:


{{{id=14|
%python

faithful_dat = get_remote_file('http://rpy.sourceforge.net/faithful.dat')
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.png('faithful_histogram.png',width=733,height=550)
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.library('ctest')
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
///
Attempting to load remote file: http://rpy.sourceforge.net/faithful.dat
Loading: [print "\x01r\x01e49"
.]
Summary of Old Faithful eruption duration data
Min.: 1.600
1st Qu.: 2.163
3rd Qu.: 4.454
Median: 4.000
Max.: 5.100
Mean: 3.488

Stem-and-leaf plot of Old Faithful eruption duration data

  The decimal point is 1 digit(s) to the left of the |

  16 | 070355555588
  18 | 000022233333335577777777888822335777888
  20 | 00002223378800035778
  22 | 0002335578023578
  24 | 00228
  26 | 23
  28 | 080
  30 | 7
  32 | 2337
  34 | 250077
  36 | 0000823577
  38 | 2333335582225577
  40 | 0000003357788888002233555577778
  42 | 03335555778800233333555577778
  44 | 02222335557780000000023333357778888
  46 | 0000233357700000023578
  48 | 00000022335800333
  50 | 0370

None
Warning message:
package 'ctest' has been merged into 'stats'
Shapiro-Wilks normality test of Old Faithful eruptions longer than 3 seconds
W = 0.9793
p-value = 0.01052

One-sample Kolmogorov-Smirnov test of Old Faithful eruptions longer
than 3 seconds
Warning message:
In function (x, y, ..., alternative = c("two.sided", "less", "greater"),  :
  cannot compute correct p-values with ties
D = 0.0661
p-value = 0.4284
Alternative hypothesis: two-sided
}}}

> >
> > Whilst I'm here a vote of thanks! I have been playing with sage for
> > about a week now - (almost non-stop) - and I am very impressed... This

Awesome!

> > is my modeling environment of choice from herein... after all it
> > subsumes everything else of note and presents the coolest web based
> > front end... brilliant work - just at the right time for me.
> >
> > Can't wait for the fully distributed notebook.

What do you mean by the "fully distributed notebook"?

 -- William

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to