Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/stats/r.py
4056 views
1
##########################################################################
2
#
3
# Copyright (C) 2007 William Stein <[email protected]>
4
# 2007 Mike Hansen <[email protected]>
5
# 2008 Harald Schilly <[email protected]>
6
#
7
# Distributed under the terms of the GNU General Public License (GPL)
8
#
9
# http://www.gnu.org/licenses/
10
#
11
##########################################################################
12
13
from sage.interfaces.r import R
14
15
# my own copy of an R interface
16
myR = R()
17
18
def ttest(x,y,conf_level = 0.95, **kw):
19
"""
20
T-Test using R
21
22
Arguments:
23
x, y -- vectors of same length
24
conf_level -- confidence level of the interval, [0,1) in percent
25
26
Result:
27
Tuple: (p-value, R return object)
28
29
Example:
30
sage: a, b = ttest([1,2,3,4,5],[1,2,3,3.5,5.121]); a
31
0.941026372027427
32
"""
33
if len(x) != len(y):
34
raise AttributeError, "vectors x and y must be of same length"
35
36
test = myR.t_test(x,y,conf_level = conf_level, **kw)._sage_()
37
t = test.get('DATA').get('p_value')
38
return t, test
39
40