跳转至

pystatpower.mean.independent.inequality

FUNCTION DESCRIPTION
solve_power

Calculate the statistical power.

solve_size

Estimate the required sample size.

solve_diff

Estimate the required mean difference.

solve_treatment_mean

Estimate the required mean in the treatment group.

solve_reference_mean

Estimate the required mean in the reference group.

solve_treatment_std

Estimate the required standard deviation in the treatment group.

solve_reference_std

Estimate the required standard deviation in the reference group.

solve_power

solve_power(
    *,
    treatment_mean: float | None = None,
    reference_mean: float | None = None,
    diff: float | None = None,
    treatment_std: float | None = None,
    reference_std: float | None = None,
    std: float | None = None,
    treatment_size: int,
    reference_size: int,
    alternative: Literal["two-sided", "greater", "less"] = "two-sided",
    alpha: float = 0.05,
    dist: Literal["z", "t"] = "t",
    equal_var: bool = False,
    approx_t_method: Literal["welch", "satterthwaite"] = "welch",
) -> float

Calculate the statistical power.

PARAMETER DESCRIPTION
treatment_mean

Mean in the treatment group.

If diff is omitted, this parameter is required along with reference_mean.

TYPE: float | None DEFAULT: None

reference_mean

Mean in the reference group.

If diff is omitted, this parameter is required along with treatment_mean.

TYPE: float | None DEFAULT: None

diff

Mean difference between treatment and reference group.

If both treatment_mean and reference_mean are not specified, this parameter is required.

TYPE: float | None DEFAULT: None

treatment_std

Standard deviation in the treatment group.

TYPE: float | None DEFAULT: None

reference_std

Standard deviation in the reference group.

TYPE: float | None DEFAULT: None

std

Standard deviation in both groups.

This is a convenience parameter that will override treatment_std and reference_std when dist is z and equal_var is True.

If you specify dist as z and equal_var as True, you can just specify std instead of treatment_std and reference_std. Internally, the value of std will be treated as the standard deviation of both the treatment and reference groups.

TYPE: float | None DEFAULT: None

treatment_size

Sample size in the treatment group.

TYPE: int

reference_size

Sample size in the reference group.

TYPE: int

alternative

Type of the alternative hypothesis.

  • If alternative is 'two-sided', the alternative hypothesis \(\mu_1 \neq \mu_2\)
  • If alternative is 'greater', the alternative hypothesis \(\mu_1 > \mu_2\)
  • If alternative is 'less', the alternative hypothesis \(\mu_1 < \mu_2\)

TYPE: Literal['two-sided', 'greater', 'less'] DEFAULT: 'two-sided'

alpha

Significance level.

  • If alternative is 'two-sided', alpha represents the two-sided significance level.
  • If alternative is 'greater' or 'less', alpha represents the one-sided significance level.

TYPE: float DEFAULT: 0.05

dist

The distribution used for the test.

  • 'z': Standard normal distribution.
  • 't': Student's or non-central t distribution.

TYPE: Literal['z', 't'] DEFAULT: 't'

equal_var

Whether to assume equal variances between treatment and reference groups.

  • True: Variances are assumed equal.
  • False: Variances are assumed unequal.

TYPE: bool DEFAULT: False

approx_t_method

Approximate t-test method. It is used when dist is 't' and equal_var = False.

  • 'welch': Welch's approximate t-test (1947).
  • 'satterthwaite': Satterthwaite's approximate t-test (1946).

TYPE: Literal['welch', 'satterthwaite'] DEFAULT: 'welch'

RETURNS DESCRIPTION
float

The calculated statistical power of the test.

RAISES DESCRIPTION
ValueError

If all of diff, treatment_mean and reference_mean are omitted.

ValueError

If dist is z and equal_var is True, and all treatment_std, reference_std and std are omitted.

ValueError

If dist is z and equal_var is True, and both treatment_std and reference_std are provided, but they are not equal.

solve_size

solve_size(
    *,
    treatment_mean: float | None = None,
    reference_mean: float | None = None,
    diff: float | None = None,
    treatment_std: float | None = None,
    reference_std: float | None = None,
    std: float | None = None,
    ratio: float = 1,
    alternative: Literal["two-sided", "greater", "less"] = "two-sided",
    alpha: float = 0.05,
    power: float = 0.8,
    dist: Literal["z", "t"] = "t",
    equal_var: bool = False,
    approx_t_method: Literal["welch", "satterthwaite"] = "welch",
) -> tuple[int, int]

Estimate the required sample size.

PARAMETER DESCRIPTION
treatment_mean

Mean in the treatment group.

If diff is omitted, this parameter is required along with reference_mean.

TYPE: float | None DEFAULT: None

reference_mean

Mean in the reference group.

If diff is omitted, this parameter is required along with treatment_mean.

TYPE: float | None DEFAULT: None

diff

Mean difference between treatment and reference group.

If both treatment_mean and reference_mean are not specified, this parameter is required.

TYPE: float | None DEFAULT: None

treatment_std

Standard deviation in the treatment group.

TYPE: float | None DEFAULT: None

reference_std

Standard deviation in the reference group.

TYPE: float | None DEFAULT: None

std

Standard deviation in both groups.

This is a convenience parameter that will override treatment_std and reference_std when dist is z and equal_var is True.

If you specify dist as z and equal_var as True, you can just specify std instead of treatment_std and reference_std. Internally, the value of std will be treated as the standard deviation of both the treatment and reference groups.

TYPE: float | None DEFAULT: None

ratio

Ratio of sample sizes in the treatment and reference groups.

TYPE: float DEFAULT: 1

alternative

Type of the alternative hypothesis.

  • If alternative is 'two-sided', the alternative hypothesis \(\mu_1 \neq \mu_2\)
  • If alternative is 'greater', the alternative hypothesis \(\mu_1 > \mu_2\)
  • If alternative is 'less', the alternative hypothesis \(\mu_1 < \mu_2\)

TYPE: Literal['two-sided', 'greater', 'less'] DEFAULT: 'two-sided'

alpha

Significance level.

  • If alternative is 'two-sided', alpha represents the two-sided significance level.
  • If alternative is 'greater' or 'less', alpha represents the one-sided significance level.

TYPE: float DEFAULT: 0.05

power

Desired statistical power.

TYPE: float DEFAULT: 0.8

dist

The distribution used for the test.

  • 'z': Standard normal distribution.
  • 't': Student's or non-central t distribution.

TYPE: Literal['z', 't'] DEFAULT: 't'

equal_var

Whether to assume equal variances between treatment and reference groups.

  • True: Variances are assumed equal.
  • False: Variances are assumed unequal.

TYPE: bool DEFAULT: False

approx_t_method

Approximate t-test method. It is used when dist is 't' and equal_var = False.

  • 'welch': Welch's approximate t-test (1947).
  • 'satterthwaite': Satterthwaite's approximate t-test (1946).

TYPE: Literal['welch', 'satterthwaite'] DEFAULT: 'welch'

RETURNS DESCRIPTION
tuple[int, int]

The required sample sizes in the treatment and reference groups, respectively.

RAISES DESCRIPTION
ValueError

If all of diff, treatment_mean and reference_mean are omitted.

ValueError

If dist is z and equal_var is True, and all treatment_std, reference_std and std are omitted.

ValueError

If dist is z and equal_var is True, and both treatment_std and reference_std are provided, but they are not equal.

solve_diff

solve_diff(
    *,
    treatment_std: float | None = None,
    reference_std: float | None = None,
    std: float | None = None,
    treatment_size: int,
    reference_size: int,
    alternative: Literal["two-sided", "greater", "less"] = "two-sided",
    alpha: float = 0.05,
    power: float = 0.8,
    dist: Literal["z", "t"] = "t",
    equal_var: bool = False,
    approx_t_method: Literal["welch", "satterthwaite"] = "welch",
    direction: Literal["greater", "less"] | None = None,
) -> float

Estimate the required mean difference.

PARAMETER DESCRIPTION
treatment_std

Standard deviation in the treatment group.

TYPE: float | None DEFAULT: None

reference_std

Standard deviation in the reference group.

TYPE: float | None DEFAULT: None

std

Standard deviation in both groups.

This is a convenience parameter that will override treatment_std and reference_std when dist is z and equal_var is True.

If you specify dist as z and equal_var as True, you can just specify std instead of treatment_std and reference_std. Internally, the value of std will be treated as the standard deviation of both the treatment and reference groups.

TYPE: float | None DEFAULT: None

treatment_size

Sample size in the treatment group.

TYPE: int

reference_size

Sample size in the reference group.

TYPE: int

alternative

Type of the alternative hypothesis.

  • If alternative is 'two-sided', the alternative hypothesis \(\mu_1 \neq \mu_2\)
  • If alternative is 'greater', the alternative hypothesis \(\mu_1 > \mu_2\)
  • If alternative is 'less', the alternative hypothesis \(\mu_1 < \mu_2\)

TYPE: Literal['two-sided', 'greater', 'less'] DEFAULT: 'two-sided'

alpha

Significance level.

  • If alternative is 'two-sided', alpha represents the two-sided significance level.
  • If alternative is 'greater' or 'less', alpha represents the one-sided significance level.

TYPE: float DEFAULT: 0.05

power

Expected statistical power.

0.8 is a commonly used value for statistical power.

TYPE: float DEFAULT: 0.8

dist

The distribution used for the test.

  • 'z': Standard normal distribution.
  • 't': Student's or non-central t distribution.

TYPE: Literal['z', 't'] DEFAULT: 't'

equal_var

Whether to assume equal variances between treatment and reference groups.

  • True: Variances are assumed equal.
  • False: Variances are assumed unequal.

TYPE: bool DEFAULT: False

approx_t_method

Approximate t-test method. It is used when dist is 't' and equal_var = False.

  • 'welch': Welch's approximate t-test (1947).
  • 'satterthwaite': Satterthwaite's approximate t-test (1946).

TYPE: Literal['welch', 'satterthwaite'] DEFAULT: 'welch'

direction

The search direction for the mean difference relative to zero.

  • 'greater': Search for the mean difference that is greater than zero.
  • 'less': Search for the mean difference that is less than zero.

Note

  • If alternative is 'two-sided', the parameter direction is required.
  • If alternative is 'greater', the search direction is automatically inferred to be 'greater', and the parameter direction is ignored.
  • If alternative is 'less', the search direction is automatically inferred to be 'less', and the parameter direction is ignored.

TYPE: Literal['greater', 'less'] | None DEFAULT: None

RETURNS DESCRIPTION
float

The required difference between the treatment and reference means.

RAISES DESCRIPTION
ValueError

If dist is z and equal_var is True, and all treatment_std, reference_std and std are omitted.

ValueError

If dist is z and equal_var is True, and both treatment_std and reference_std are provided, but they are not equal.

ValueError

If alternative is 'two-sided' and direction is omitted.

solve_treatment_mean

solve_treatment_mean(
    *,
    reference_mean: float,
    treatment_std: float | None = None,
    reference_std: float | None = None,
    std: float | None = None,
    treatment_size: int,
    reference_size: int,
    alternative: Literal["two-sided", "greater", "less"] = "two-sided",
    alpha: float = 0.05,
    power: float = 0.8,
    dist: Literal["z", "t"] = "t",
    equal_var: bool = False,
    approx_t_method: Literal["welch", "satterthwaite"] = "welch",
    direction: Literal["greater", "less"] | None = None,
) -> float

Estimate the required mean in the treatment group.

PARAMETER DESCRIPTION
reference_mean

Mean in the reference group.

TYPE: float

treatment_std

Standard deviation in the treatment group.

TYPE: float | None DEFAULT: None

reference_std

Standard deviation in the reference group.

TYPE: float | None DEFAULT: None

std

Standard deviation in both groups.

This is a convenience parameter that will override treatment_std and reference_std when dist is z and equal_var is True.

If you specify dist as z and equal_var as True, you can just specify std instead of treatment_std and reference_std. Internally, the value of std will be treated as the standard deviation of both the treatment and reference groups.

TYPE: float | None DEFAULT: None

treatment_size

Sample size in the treatment group.

TYPE: int

reference_size

Sample size in the reference group.

TYPE: int

alternative

Type of the alternative hypothesis.

  • If alternative is 'two-sided', the alternative hypothesis \(\mu_1 \neq \mu_2\)
  • If alternative is 'greater', the alternative hypothesis \(\mu_1 > \mu_2\)
  • If alternative is 'less', the alternative hypothesis \(\mu_1 < \mu_2\)

TYPE: Literal['two-sided', 'greater', 'less'] DEFAULT: 'two-sided'

alpha

Significance level.

  • If alternative is 'two-sided', alpha represents the two-sided significance level.
  • If alternative is 'greater' or 'less', alpha represents the one-sided significance level.

TYPE: float DEFAULT: 0.05

power

Expected statistical power.

0.8 is a commonly used value for statistical power.

TYPE: float DEFAULT: 0.8

dist

The distribution used for the test.

  • 'z': Standard normal distribution.
  • 't': Student's or non-central t distribution.

TYPE: Literal['z', 't'] DEFAULT: 't'

equal_var

Whether to assume equal variances between treatment and reference groups.

  • True: Variances are assumed equal.
  • False: Variances are assumed unequal.

TYPE: bool DEFAULT: False

approx_t_method

Approximate t-test method. It is used when dist is 't' and equal_var = False.

  • 'welch': Welch's approximate t-test (1947).
  • 'satterthwaite': Satterthwaite's approximate t-test (1946).

TYPE: Literal['welch', 'satterthwaite'] DEFAULT: 'welch'

direction

The search direction for the treatment mean relative to the reference mean.

  • 'greater': Search for the treatment mean that is greater than the reference mean.
  • 'less': Search for the treatment mean that is less than the reference mean.

Note

  • If alternative is 'two-sided', the parameter direction is required.
  • If alternative is 'greater', the search direction is automatically inferred to be 'greater', and the parameter direction is ignored.
  • If alternative is 'less', the search direction is automatically inferred to be 'less', and the parameter direction is ignored.

TYPE: Literal['greater', 'less'] | None DEFAULT: None

RETURNS DESCRIPTION
float

The required mean in the treatment group.

RAISES DESCRIPTION
ValueError

If dist is z and equal_var is True, and all treatment_std, reference_std and std are omitted.

ValueError

If dist is z and equal_var is True, and both treatment_std and reference_std are provided, but they are not equal.

ValueError

If alternative is 'two-sided' and direction is omitted.

solve_reference_mean

solve_reference_mean(
    *,
    treatment_mean: float,
    treatment_std: float | None = None,
    reference_std: float | None = None,
    std: float | None = None,
    treatment_size: int,
    reference_size: int,
    alternative: Literal["two-sided", "greater", "less"] = "two-sided",
    alpha: float = 0.05,
    power: float = 0.8,
    dist: Literal["z", "t"] = "t",
    equal_var: bool = False,
    approx_t_method: Literal["welch", "satterthwaite"] = "welch",
    direction: Literal["greater", "less"] | None = None,
) -> float

Estimate the required mean in the reference group.

PARAMETER DESCRIPTION
treatment_mean

Mean in the treatment group.

TYPE: float

treatment_std

Standard deviation in the treatment group.

TYPE: float | None DEFAULT: None

reference_std

Standard deviation in the reference group.

TYPE: float | None DEFAULT: None

std

Standard deviation in both groups.

This is a convenience parameter that will override treatment_std and reference_std when dist is z and equal_var is True.

If you specify dist as z and equal_var as True, you can just specify std instead of treatment_std and reference_std. Internally, the value of std will be treated as the standard deviation of both the treatment and reference groups.

TYPE: float | None DEFAULT: None

treatment_size

Sample size in the treatment group.

TYPE: int

reference_size

Sample size in the reference group.

TYPE: int

alternative

Type of the alternative hypothesis.

  • If alternative is 'two-sided', the alternative hypothesis \(\mu_1 \neq \mu_2\)
  • If alternative is 'greater', the alternative hypothesis \(\mu_1 > \mu_2\)
  • If alternative is 'less', the alternative hypothesis \(\mu_1 < \mu_2\)

TYPE: Literal['two-sided', 'greater', 'less'] DEFAULT: 'two-sided'

alpha

Significance level.

  • If alternative is 'two-sided', alpha represents the two-sided significance level.
  • If alternative is 'greater' or 'less', alpha represents the one-sided significance level.

TYPE: float DEFAULT: 0.05

power

Expected statistical power.

0.8 is a commonly used value for statistical power.

TYPE: float DEFAULT: 0.8

dist

The distribution used for the test.

  • 'z': Standard normal distribution.
  • 't': Student's or non-central t distribution.

TYPE: Literal['z', 't'] DEFAULT: 't'

equal_var

Whether to assume equal variances between treatment and reference groups.

  • True: Variances are assumed equal.
  • False: Variances are assumed unequal.

TYPE: bool DEFAULT: False

approx_t_method

Approximate t-test method. It is used when dist is 't' and equal_var = False.

  • 'welch': Welch's approximate t-test (1947).
  • 'satterthwaite': Satterthwaite's approximate t-test (1946).

TYPE: Literal['welch', 'satterthwaite'] DEFAULT: 'welch'

direction

The search direction for the reference mean relative to the treatment mean.

  • 'greater': Search for the reference mean that is greater than the treatment mean.
  • 'less': Search for the reference mean that is less than the treatment mean.

Note

  • If alternative is 'two-sided', the parameter direction is required.
  • If alternative is 'greater', the search direction is automatically inferred to be 'less', and the parameter direction is ignored.
  • If alternative is 'less', the search direction is automatically inferred to be 'greater', and the parameter direction is ignored.

TYPE: Literal['greater', 'less'] | None DEFAULT: None

RETURNS DESCRIPTION
float

The required mean in the treatment group.

RAISES DESCRIPTION
ValueError

If dist is z and equal_var is True, and all treatment_std, reference_std and std are omitted.

ValueError

If dist is z and equal_var is True, and both treatment_std and reference_std are provided, but they are not equal.

ValueError

If alternative is 'two-sided' and direction is omitted.

solve_treatment_std

solve_treatment_std(
    *,
    treatment_mean: float | None = None,
    reference_mean: float | None = None,
    diff: float | None = None,
    reference_std: float | None = None,
    treatment_size: int,
    reference_size: int,
    alternative: Literal["two-sided", "greater", "less"] = "two-sided",
    alpha: float = 0.05,
    power: float = 0.8,
    dist: Literal["z", "t"] = "t",
    equal_var: bool = True,
    approx_t_method: Literal["welch", "satterthwaite"] = "welch",
) -> float

Estimate the required standard deviation in the treatment group.

PARAMETER DESCRIPTION
treatment_mean

Mean in the treatment group.

If diff is omitted, this parameter is required along with reference_mean.

TYPE: float | None DEFAULT: None

reference_mean

Mean in the reference group.

If diff is omitted, this parameter is required along with treatment_mean.

TYPE: float | None DEFAULT: None

diff

Mean difference between treatment and reference group.

If both treatment_mean and reference_mean are not specified, this parameter is required.

TYPE: float | None DEFAULT: None

reference_std

Standard deviation in the reference group.

  • If dist is z and equal_var is True, this parameter is ignored.
  • If dist is z and equal_var is False, this parameter is required.
  • If dist is t and equal_var is True, this parameter is optional. If specified, this value is used to calculate the standard error of mean difference.
  • If dist is t and equal_var is False, this parameter is required.

TYPE: float | None DEFAULT: None

treatment_size

Sample size in the treatment group.

TYPE: int

reference_size

Sample size in the reference group.

TYPE: int

alternative

Type of the alternative hypothesis.

  • If alternative is 'two-sided', the alternative hypothesis \(\mu_1 \neq \mu_2\)
  • If alternative is 'greater', the alternative hypothesis \(\mu_1 > \mu_2\)
  • If alternative is 'less', the alternative hypothesis \(\mu_1 < \mu_2\)

TYPE: Literal['two-sided', 'greater', 'less'] DEFAULT: 'two-sided'

alpha

Significance level.

  • If alternative is 'two-sided', alpha represents the two-sided significance level.
  • If alternative is 'greater' or 'less', alpha represents the one-sided significance level.

TYPE: float DEFAULT: 0.05

power

Expected statistical power.

0.8 is a commonly used value for statistical power.

TYPE: float DEFAULT: 0.8

dist

The distribution used for the test.

  • 'z': Standard normal distribution.
  • 't': Student's or non-central t distribution.

TYPE: Literal['z', 't'] DEFAULT: 't'

equal_var

Whether to assume equal variances between treatment and reference groups.

  • True: Variances are assumed equal.
  • False: Variances are assumed unequal.

TYPE: bool DEFAULT: True

approx_t_method

Approximate t-test method. It is used when dist is 't' and equal_var = False.

  • 'welch': Welch's approximate t-test (1947).
  • 'satterthwaite': Satterthwaite's approximate t-test (1946).

TYPE: Literal['welch', 'satterthwaite'] DEFAULT: 'welch'

RETURNS DESCRIPTION
float

The required standard deviation in the treatment group.

RAISES DESCRIPTION
ValueError

If all of diff, treatment_mean and reference_mean are omitted.

ValueError

If equal_var is False, and reference_std is omitted.

solve_reference_std

solve_reference_std(
    *,
    treatment_mean: float | None = None,
    reference_mean: float | None = None,
    diff: float | None = None,
    treatment_std: float | None = None,
    treatment_size: int,
    reference_size: int,
    alternative: Literal["two-sided", "greater", "less"] = "two-sided",
    alpha: float = 0.05,
    power: float = 0.8,
    dist: Literal["z", "t"] = "t",
    equal_var: bool = True,
    approx_t_method: Literal["welch", "satterthwaite"] = "welch",
) -> float

Estimate the required standard deviation in the reference group.

PARAMETER DESCRIPTION
treatment_mean

Mean in the treatment group.

If diff is omitted, this parameter is required along with reference_mean.

TYPE: float | None DEFAULT: None

reference_mean

Mean in the reference group.

If diff is omitted, this parameter is required along with treatment_mean.

TYPE: float | None DEFAULT: None

diff

Mean difference between treatment and reference group.

If both treatment_mean and reference_mean are not specified, this parameter is required.

TYPE: float | None DEFAULT: None

treatment_std

Standard deviation in the treatment group.

  • If dist is z and equal_var is True, this parameter is ignored.
  • If dist is z and equal_var is False, this parameter is required.
  • If dist is t and equal_var is True, this parameter is optional. If specified, this value is used to calculate the standard error of mean difference.
  • If dist is t and equal_var is False, this parameter is required.

TYPE: float | None DEFAULT: None

treatment_size

Sample size in the treatment group.

TYPE: int

reference_size

Sample size in the reference group.

TYPE: int

alternative

Type of the alternative hypothesis.

  • If alternative is 'two-sided', the alternative hypothesis \(\mu_1 \neq \mu_2\)
  • If alternative is 'greater', the alternative hypothesis \(\mu_1 > \mu_2\)
  • If alternative is 'less', the alternative hypothesis \(\mu_1 < \mu_2\)

TYPE: Literal['two-sided', 'greater', 'less'] DEFAULT: 'two-sided'

alpha

Significance level.

  • If alternative is 'two-sided', alpha represents the two-sided significance level.
  • If alternative is 'greater' or 'less', alpha represents the one-sided significance level.

TYPE: float DEFAULT: 0.05

power

Expected statistical power.

0.8 is a commonly used value for statistical power.

TYPE: float DEFAULT: 0.8

dist

The distribution used for the test.

  • 'z': Standard normal distribution.
  • 't': Student's or non-central t distribution.

TYPE: Literal['z', 't'] DEFAULT: 't'

equal_var

Whether to assume equal variances between treatment and reference groups.

  • True: Variances are assumed equal.
  • False: Variances are assumed unequal.

TYPE: bool DEFAULT: True

approx_t_method

Approximate t-test method. It is used when dist is 't' and equal_var = False.

  • 'welch': Welch's approximate t-test (1947).
  • 'satterthwaite': Satterthwaite's approximate t-test (1946).

TYPE: Literal['welch', 'satterthwaite'] DEFAULT: 'welch'

RETURNS DESCRIPTION
float

The required standard deviation in the reference group.

RAISES DESCRIPTION
ValueError

If all of diff, treatment_mean and reference_mean are omitted.

ValueError

If equal_var is False, and treatment_std is omitted.