|
Size: 1495
Comment:
|
Size: 2589
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 71: | Line 71: |
| sage: t = ttest([1,2,3,4,5],[1,2,3,3.5,5.121]) sage: t |
|
| Line 72: | Line 74: |
| (0.941026372027427, {'DATA': {'alternative': 'two.sided', 'conf_int': {'DATA': [-2.2140805547522402, 2.3656805547522399], 'conf_level': 0.94999999999999996}, 'data_name': 'sage5 and sage11', 'estimate': {'DATA': [3, 2.9241999999999999], '_Names': ['mean of x', 'mean of y']}, 'method': 'Welch Two Sample t-test', 'null_value': {'DATA': 0, '_Names': 'difference in means'}, 'p_value': 0.941026372027427, 'parameter': {'DATA': 7.9983864630024701, '_Names': 'df'}, 'statistic': {'DATA': 0.076336405881313296, '_Names': 't'}}, '_Names': ['statistic', 'parameter', 'p.value', 'conf.int', 'estimate', 'null.value', 'alternative', 'method', 'data.name'], '_r_class': 'htest'}) sage: t[0] 0.941026372027427 sage: ttest([1,2,3,4,5],[1,2,3,3.5,5.121])[0] 0.941026372027427 |
R
"R is a language and environment for statistical computing and graphics." -- http://www.r-project.org/
Sage includes R and is able to invoke it. It is possible to send lines of code, invoke commands in a standardized fashion, work with results of calculations as objects and convert those objects back into python data structures. The last point is essential to write native Sage commands that use R as backend.
Examples
sequence
sage: r.seq(1,9) [1] 1 2 3 4 5 6 7 8 9
Matrix
Matrix m as Sage object and R printout - then a translation to a Sage matrix.
sage: m = r.matrix(r.seq(1,12),3)
sage: type(m)
<class 'sage.interfaces.r.RElement'>
sage: m
[,1] [,2] [,3] [,4]
[1,] 1 4 7 10
[2,] 2 5 8 11
[3,] 3 6 9 12argument byrow=True
sage: m = r.matrix(r.seq(1,12),3, byrow=True)
sage: m
[,1] [,2] [,3] [,4]
[1,] 1 2 3 4
[2,] 5 6 7 8
[3,] 9 10 11 12
t-Test
sage: r.t_test(r.c(1,2,3,5),r.c(1,2,4,5))
or just
sage: r.t_test([1,2,3],[1,2,4])
Welch Two Sample t-test
data: sage6 and sage7
t = -0.2, df = 5.973, p-value = 0.8481
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-3.311938 2.811938
sample estimates:
mean of x mean of y
2.75 3.00 and native
sage: t = ttest([1,2,3,4,5],[1,2,3,3.5,5.121])
sage: t
(0.941026372027427,
{'DATA': {'alternative': 'two.sided',
'conf_int': {'DATA': [-2.2140805547522402, 2.3656805547522399],
'conf_level': 0.94999999999999996},
'data_name': 'sage5 and sage11',
'estimate': {'DATA': [3, 2.9241999999999999],
'_Names': ['mean of x', 'mean of y']},
'method': 'Welch Two Sample t-test',
'null_value': {'DATA': 0, '_Names': 'difference in means'},
'p_value': 0.941026372027427,
'parameter': {'DATA': 7.9983864630024701, '_Names': 'df'},
'statistic': {'DATA': 0.076336405881313296, '_Names': 't'}},
'_Names': ['statistic',
'parameter',
'p.value',
'conf.int',
'estimate',
'null.value',
'alternative',
'method',
'data.name'],
'_r_class': 'htest'})
sage: t[0]
0.941026372027427
sage: ttest([1,2,3,4,5],[1,2,3,3.5,5.121])[0]
0.941026372027427