跳转至

pystatpower.mean.single.inequality

Functions:

Name Description
solve_power

Calculate the statistical power for an inequality test of one mean.

solve_size

Estimate the required sample size for an inequality test of one mean.

solve_diff

Estimate the required mean difference between the alternative hypothesis and the null hypothesis for an inequality test of one mean.

solve_mean

Estimate the required mean under the alternative hypothesis for an inequality test of one mean.

solve_null_mean

Estimate the required mean under the null hypothesis for an inequality test of one mean.

solve_std

Estimate the required standard deviation for an inequality test of one mean.

solve_power

solve_power(
    *,
    mean: float | None = None,
    null_mean: float | None = None,
    diff: float | None = None,
    std: float,
    size: int,
    alternative: Literal["two-sided", "greater", "less"],
    alpha: float,
    dist: Literal["z", "t"] = "t",
) -> float

Calculate the statistical power for an inequality test of one mean.

Parameters:

Name Type Description Default
mean float | None

Mean under the alternative hypothesis.

If diff is not specified, this parameter and null_mean are required.

None
null_mean float | None

Mean under the null hypothesis.

If diff is not specified, this parameter and mean are required.

None
diff float | None

Mean difference between the alternative hypothesis and the null hypothesis.

If both mean and null_mean are not specified, this parameter is required.

None
std float

Standard deviation.

required
size int

Sample size.

required
alternative Literal['two-sided', 'greater', 'less']

Type of the alternative hypothesis.

  • If alternative is 'two-sided', the alternative hypothesis is \(\mu \neq \mu_0\)
  • If alternative is 'greater', the alternative hypothesis is \(\mu > \mu_0\)
  • If alternative is 'less', the alternative hypothesis is \(\mu < \mu_0\)
required
alpha float

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.
required
dist Literal['z', 't']

The distribution used for the test.

  • 'z': Normal distribution.
  • 't': Student's t distribution.
't'

Returns:

Name Type Description
float float

The statistical power of the test.

Raises:

Type Description
ValueError

If diff is not specified, and either mean or null_mean is not specified.

solve_size

solve_size(
    *,
    mean: float | None = None,
    null_mean: float | None = None,
    diff: float | None = None,
    std: float,
    alternative: Literal["two-sided", "greater", "less"],
    alpha: float,
    power: float = 0.8,
    dist: Literal["z", "t"] = "t",
) -> int

Estimate the required sample size for an inequality test of one mean.

Parameters:

Name Type Description Default
mean float | None

Mean under the alternative hypothesis.

If diff is not specified, this parameter and null_mean are required.

None
null_mean float | None

Mean under the null hypothesis.

If diff is not specified, this parameter and mean are required.

None
diff float | None

Mean difference between the alternative hypothesis and the null hypothesis.

If both mean and null_mean are not specified, this parameter is required.

None
std float

Standard deviation.

required
alternative Literal['two-sided', 'greater', 'less']

Type of the alternative hypothesis.

  • If alternative is 'two-sided', the alternative hypothesis is \(\mu \neq \mu_0\)
  • If alternative is 'greater', the alternative hypothesis is \(\mu > \mu_0\)
  • If alternative is 'less', the alternative hypothesis is \(\mu < \mu_0\)
required
alpha float

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.
required
power float

Expected statistical power.

0.8 is a commonly used statistical power.

0.8
dist Literal['z', 't']

The distribution used for the test.

  • 'z': Normal distribution.
  • 't': Student's t distribution.
't'

Returns:

Name Type Description
int int

The required sample size.

Raises:

Type Description
ValueError

If diff is not specified, and either mean or null_mean is not specified.

solve_diff

solve_diff(
    *,
    std: float,
    size: int,
    alternative: Literal["two-sided", "greater", "less"],
    alpha: float,
    power: float,
    dist: Literal["z", "t"],
    direction: Literal["greater", "less"] | None = None,
) -> float

Estimate the required mean difference between the alternative hypothesis and the null hypothesis for an inequality test of one mean.

Parameters:

Name Type Description Default
std float

Standard deviation.

required
size int

Sample size.

required
alternative Literal['two-sided', 'greater', 'less']

Type of the alternative hypothesis.

  • If alternative is 'two-sided', the alternative hypothesis is \(\mu \neq \mu_0\)
  • If alternative is 'greater', the alternative hypothesis is \(\mu > \mu_0\)
  • If alternative is 'less', the alternative hypothesis is \(\mu < \mu_0\)
required
alpha float

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.
required
power float

Expected statistical power.

0.8 is a commonly used statistical power.

required
dist Literal['z', 't']

The distribution used for the test.

  • 'z': Normal distribution.
  • 't': Student's t distribution.
required
direction Literal['greater', 'less'] | None

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.
None

Returns:

Name Type Description
float float

The required mean difference between the alternative hypothesis and the null hypothesis.

Raises:

Type Description
ValueError

If alternative is 'two-sided' but direction is not specified.

solve_mean

solve_mean(
    *,
    null_mean: float,
    std: float,
    size: int,
    alternative: Literal["two-sided", "greater", "less"],
    alpha: float,
    power: float,
    dist: Literal["z", "t"],
    direction: Literal["greater", "less"] | None = None,
) -> float

Estimate the required mean under the alternative hypothesis for an inequality test of one mean.

Parameters:

Name Type Description Default
null_mean float

Mean under the null hypothesis.

required
std float

Standard deviation.

required
size int

Sample size.

required
alternative Literal['two-sided', 'greater', 'less']

Type of the alternative hypothesis.

  • If alternative is 'two-sided', the alternative hypothesis is \(\mu \neq \mu_0\)
  • If alternative is 'greater', the alternative hypothesis is \(\mu > \mu_0\)
  • If alternative is 'less', the alternative hypothesis is \(\mu < \mu_0\)
required
alpha float

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.
required
power float

Expected statistical power.

0.8 is a commonly used statistical power.

required
dist Literal['z', 't']

The distribution used for the test.

  • 'z': Normal distribution.
  • 't': Student's t distribution.
required
direction Literal['greater', 'less'] | None

The search direction for the mean under the alternative hypothesis relative to the mean under the null hypothesis.

  • 'greater': Search for the alternative mean that is greater than the null mean.
  • 'less': Search for the alternative mean that is less than the null 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.
None

Returns:

Name Type Description
float float

The required mean under the alternative hypothesis.

Raises:

Type Description
ValueError

If alternative is 'two-sided' but direction is not specified.

solve_null_mean

solve_null_mean(
    *,
    mean: float,
    std: float,
    size: int,
    alternative: Literal["two-sided", "greater", "less"],
    alpha: float,
    power: float = 0.8,
    dist: Literal["z", "t"] = "t",
    direction: Literal["greater", "less"] | None = None,
) -> float

Estimate the required mean under the null hypothesis for an inequality test of one mean.

Parameters:

Name Type Description Default
mean float

Mean under the alternative hypothesis.

required
std float

Standard deviation.

required
size int

Sample size.

required
alternative Literal['two-sided', 'greater', 'less']

Type of the alternative hypothesis.

  • If alternative is 'two-sided', the alternative hypothesis is \(\mu \neq \mu_0\)
  • If alternative is 'greater', the alternative hypothesis is \(\mu > \mu_0\)
  • If alternative is 'less', the alternative hypothesis is \(\mu < \mu_0\)
required
alpha float

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.
required
power float

Expected statistical power.

0.8 is a commonly used statistical power.

0.8
dist Literal['z', 't']

The distribution used for the test.

  • 'z': Normal distribution.
  • 't': Student's t distribution.
't'
direction Literal['greater', 'less'] | None

The search direction for the mean under the null hypothesis relative to the mean under the alternative hypothesis.

  • 'greater': Search for the null mean that is greater than the alternative mean.
  • 'less': Search for the null mean that is less than the alternative 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.
None

Returns:

Name Type Description
float float

The required mean under the null hypothesis.

Raises:

Type Description
ValueError

If alternative is 'two-sided' but direction is not specified.

solve_std

solve_std(
    *,
    mean: float | None = None,
    null_mean: float | None = None,
    diff: float | None = None,
    size: int,
    alternative: Literal["two-sided", "greater", "less"],
    alpha: float,
    power: float,
    dist: Literal["z", "t"],
) -> float

Estimate the required standard deviation for an inequality test of one mean.

Parameters:

Name Type Description Default
mean float | None

Mean under the alternative hypothesis.

If diff is not specified, this parameter and null_mean are required.

None
null_mean float | None

Mean under the null hypothesis.

If diff is not specified, this parameter and mean are required.

None
diff float | None

Mean difference between the alternative hypothesis and the null hypothesis.

If both mean and null_mean are not specified, this parameter is required.

None
size int

Sample size.

required
alternative Literal['two-sided', 'greater', 'less']

Type of the alternative hypothesis.

  • If alternative is 'two-sided', the alternative hypothesis is \(\mu \neq \mu_0\)
  • If alternative is 'greater', the alternative hypothesis is \(\mu > \mu_0\)
  • If alternative is 'less', the alternative hypothesis is \(\mu < \mu_0\)
required
alpha float

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.
required
power float

Expected statistical power.

0.8 is a commonly used statistical power.

required
dist Literal['z', 't']

The distribution used for the test.

  • 'z': Normal distribution.
  • 't': Student's t distribution.
required

Returns:

Name Type Description
float float

The required standard deviation.

Raises:

Type Description
ValueError

If diff is not specified, and either mean or null_mean is not specified.