t-test

t_test()

EzPyZ.t_test(x, y=None, alternative='two-tailed', mu=None, data=None, paired=False, conf_level=0.05, subset=None)

Conducts a t-test.

Parameters
  • x (EzPyZ.column.Column or str) – The column of the first sample. If data is not None, then a string providing the column title may be provided.

  • y (EzPyZ.column.Column or str) – (optional) The column of the second sample. If data is not None, then a string providing the column title may be provided. If performing a one-sample t-test, this should not be used. Defaults to None.

  • alternative (str) – (optional) String. Whether the x column is being tested to be greater than, less than, or not equal to the y column. Must be one of “two-tailed”, “less”, or “greater”. Defaults to “two-tailed”.

  • mu (float) – (optional) Float. The population mean for a one-sample t-test. Defaults to None.

  • data (EzPyZ.DataFrame) – (optional) The dataframe containing the values. Defaults to None

  • paired (bool) – (optional) Boolean. Whether the t-test is a paired-samples t-test. If False, an independent-samples t-test is conducted. Defaults to False.

  • conf_level (float) – (optional) Float. The confidence interval. Defaults to 0.05.

  • subset (str) – (optional) String containing rules to exclude cetain rows from the analysis. See EzPyZ.DataFrame for more information on writing these strings. This parameter may only be used when data is set to a valid EzPyZ.DataFrame! Defaults to None.

Returns

The results of the t-test.

Return type

EzPyZ.TResult

Example one-sample t-test:

>>> import EzPyZ as ez
>>> data = {
...     'score': [15, 17, 16, 16, 19, 14, 17]
... }
>>> df = ez.DataFrame(data)
>>> # Let's conduct a two-tailed, one-sample t-test between the scores and a population mean,
>>> # in this case well say 12.
>>> # We'll also use the standard confidence level of 0.05.
>>> t_res = ez.t_test(data=df, x='score', mu=15)
>>> print(t_res)

                        One-sample t-test

data:   score
t = 7.0711, df = 6, p-value = 0.000401
null hypothesis:                        true difference in means is equal to 0
alternative hypothesis:                 true difference in means is not equal to 0
resolution:                             reject null hypothesis with confidence level of 0.05
95.0 percent confidence interval for x: [13.14278, 19.428649]
mean of the differences (μ - x):        -4.285714

Example independent-samples t-test:

>>> import EzPyZ as ez
>>> data = {
...     'before': [1, 3, 4, 2, 3, 4, 6],
...     'after': [3, 4, 6, 9, 8, 7, 11]
... }
>>> df = ez.DataFrame(data)
>>> # Let's conduct a two-tailed, independent-samples t-test between the before and after
>>> # scores.
>>> # We'll also use the standard confidence level of 0.05.
>>> t_res = ez.t_test(data=df, x='before', y='after', paired=True)
>>> print(t_res)

                        Welch Two-Sample t-test

data:   before and after
t = -2.9327, df = 9.5647, p-value = 0.015663
null hypothesis:                        true difference in means is equal to 0
alternative hypothesis:                 true difference in means is not equal to 0
resolution:                             reject null hypothesis with confidence level of 0.05
95.0 percent confidence interval for x: [0.14278, 6.428649]
mean of the differences (y - x):        3.571429

Example paired-samples t-test:

>>> import EzPyZ as ez
>>> data = {
...     'before': [1, 3, 4, 2, 3, 4, 6],
...     'after': [3, 4, 6, 9, 8, 7, 11]
... }
>>> df = ez.DataFrame(data)
>>> # Let's conduct a two-tailed, paired-samples t-test between the before and after scores.
>>> # We'll also use the standard confidence level of 0.05.
>>> t_res = ez.t_test(data=df, x='before', y='after', paired=True)
>>> print(t_res)

                                        Paired t-test

data:                                                   before (m = 3.29) and after (m = 6.86)
output:                                                 t = -4.3966, df = 6, p-value = 0.004585
null hypothesis:                                        true difference in means is equal to 0
alternative hypothesis:                                 true difference in means is not equal to 0
resolution:                                             reject null hypothesis with confidence level of 0.05
95.0 percent confidence interval for x:                 [0.14278, 6.428649]
mean of the differences (y - x):                        3.571429

TResult

class EzPyZ.t_test.TResult(info)

Bases: object

A TResult object will be generated and returned by t-tests. It will contain the following attributes:

TResult.desc

A description of the t-test run (i.e. one-sample, paired-samples, etc.).

TResult.x

The EzPyZ.Column object for the x column.

TResult.y

The EzPyZ.Column object for the y column.

TResult.mu

The population mean.

TResult.conf_level

The confidence level.

TResult.conf_perc

The percentage confidence level. For conf_level = .05, this would be 95.

TResult.t

The t-score.

TResult.df

The degrees of freedom.

TResult.p

The p-value.

TResult.resolution

A brief statement saying whether the null hypothesis was rejected.

TResult.alt

The alternative hypothesis.

TResult.null

The null hypothesis.

TResult.conf_interval

The confidence interval of the x column.

TResult.mean_diff

The mean difference (y - x) or (μ - x).

__init__(info)

Constructs a TResult object.

Parameters

info (Dict[str, Union[str, Dict[str, Any]]]) – Dictionary. The data from the t-test.

Returns

Nothing.

Return type

NoneType

__repr__()

Returns basic TResult information.

Returns

Basic TResult information.

Return type

str

Usage:

>>> import EzPyZ as ez
>>> data = {
...     'before': [1, 3, 4, 2, 3, 4, 6],
...     'after': [3, 4, 6, 9, 8, 7, 11]
... }
>>> df = ez.DataFrame(data)
>>> t_res = ez.t_test(data=df, x='before', y='after')
>>> print(repr(t_res))
TResult(x=before, y=after, paired=False, t=-2.9327, df=9.5647, p=0.015663)
__str__()

Returns the TResult as a string.

Returns

A print-friendly string representing the TResult object.

Return type

str

Usage:

>>> import EzPyZ as ez
>>> data = {
...     'score': [15, 17, 16, 16, 19, 14, 17]
... }
>>> df = ez.DataFrame(data)
>>> # Let's conduct a two-tailed, one-sample t-test between the scores and a population
>>> # mean, in this case well say 12.
>>> # We'll also use the standard confidence level of 0.05.
>>> t_res = ez.t_test(data=df, x='score', mu=15)
>>> # t_res now contains a ``TResponse``object.
>>> print(t_res)

                    One-sample t-test

data:   score
t = 7.0711, df = 6, p-value = 0.000401
null hypothesis:                        true difference in means is equal to 0
alternative hypothesis:                 true difference in means is not equal to 0
resolution:                             reject null hypothesis with confidence level of 0.05
95.0 percent confidence interval for x: [13.14278, 19.428649]
mean of the differences (μ - x):        -4.285714
apa_style()

Generates and returns an APA-style string. This string is compliant to the APA 7th edition standard.

Returns

An APA-style string describing the results of the t-test.

Return type

str