跳转至

pystatpower.proportion.single.inequality

FUNCTION DESCRIPTION
solve_power

Calculate the statistical power.

solve_size

Estimate the required sample size.

solve_proportion

Estimate the required proportion under the alternative hypothesis.

solve_null_proportion

Estimate the required proportion under the null hypothesis.

solve_power

solve_power(
    *,
    proportion: float,
    null_proportion: float,
    size: int,
    alternative: Literal["two-sided", "greater", "less"] = "two-sided",
    alpha: float = 0.05,
    method: Literal["exact", "z-p0", "z-phat"] = "exact",
    continuity_correction: bool = False,
) -> float

Calculate the statistical power.

PARAMETER DESCRIPTION
proportion

Proportion under the alternative hypothesis.

TYPE: float

null_proportion

Proportion under the null hypothesis.

TYPE: float

size

Sample size.

TYPE: int

alternative

Type of the alternative hypothesis:

  • If alternative is 'two-sided', the alternative hypothesis is \(p ≠ p_0\)
  • If alternative is 'greater', the alternative hypothesis is \(p > p_0\)
  • If alternative is 'less', the alternative hypothesis is \(p < p_0\)

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

method

The method used to construct the test statistic.

  • 'exact': Binomial distribution.
  • 'z-p0': Standard normal distribution (large sample approximation), using p0 to calculate the variance.
  • 'z-phat': Standard normal distribution (large sample approximation), using phat to calculate the variance.

TYPE: Literal['exact', 'z-p0', 'z-phat'] DEFAULT: 'exact'

continuity_correction

Whether to apply the continuity correction.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
float

The statistical power of the test.

solve_size

solve_size(
    *,
    proportion: float,
    null_proportion: float,
    alternative: Literal["two-sided", "greater", "less"] = "two-sided",
    alpha: float = 0.05,
    power: float = 0.8,
    method: Literal["exact", "z-p0", "z-phat"] = "exact",
    continuity_correction: bool = False,
) -> int

Estimate the required sample size.

PARAMETER DESCRIPTION
proportion

Proportion under the alternative hypothesis.

TYPE: float

null_proportion

Proportion under the null hypothesis.

TYPE: float

alternative

Type of the alternative hypothesis:

  • If alternative is 'two-sided', the alternative hypothesis is \(p ≠ p_0\)
  • If alternative is 'greater', the alternative hypothesis is \(p > p_0\)
  • If alternative is 'less', the alternative hypothesis is \(p < p_0\)

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

method

The method used to construct the test statistic.

  • 'exact': Binomial distribution.
  • 'z-p0': Standard normal distribution (large sample approximation), using p0 to calculate the variance.
  • 'z-phat': Standard normal distribution (large sample approximation), using phat to calculate the variance.

TYPE: Literal['exact', 'z-p0', 'z-phat'] DEFAULT: 'exact'

continuity_correction

Whether to apply the continuity correction.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
int

The required sample size.

solve_proportion

solve_proportion(
    *,
    null_proportion: float,
    size: int,
    alternative: Literal["two-sided", "greater", "less"] = "two-sided",
    alpha: float = 0.05,
    power: float = 0.8,
    method: Literal["exact", "z-p0", "z-phat"] = "exact",
    continuity_correction: bool = False,
    direction: Literal["greater", "less"] | None = None,
) -> float

Estimate the required proportion under the alternative hypothesis.

PARAMETER DESCRIPTION
null_proportion

Proportion under the null hypothesis.

TYPE: float

size

Sample size.

TYPE: int

alternative

Type of the alternative hypothesis:

  • If alternative is 'two-sided', the alternative hypothesis is \(p ≠ p_0\)
  • If alternative is 'greater', the alternative hypothesis is \(p > p_0\)
  • If alternative is 'less', the alternative hypothesis is \(p < p_0\)

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

method

The method used to construct the test statistic.

  • 'exact': Binomial distribution.
  • 'z-p0': Standard normal distribution (large sample approximation), using p0 to calculate the variance.
  • 'z-phat': Standard normal distribution (large sample approximation), using phat to calculate the variance.

TYPE: Literal['exact', 'z-p0', 'z-phat'] DEFAULT: 'exact'

continuity_correction

Whether to apply the continuity correction.

TYPE: bool DEFAULT: False

direction

The direction for the proportion under the alternative hypothesis relative to the proportion under the null hypothesis.

  • 'greater': Search for the alternative proportion greater than the null proportion.
  • 'less': Search for the alternative proportion less than the null proportion.

Note

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

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

RETURNS DESCRIPTION
float

The required proportion under the alternative hypothesis.

RAISES DESCRIPTION
ValueError

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

solve_null_proportion

solve_null_proportion(
    *,
    proportion: float,
    size: int,
    alternative: Literal["two-sided", "greater", "less"] = "two-sided",
    alpha: float = 0.05,
    power: float = 0.8,
    method: Literal["z-p0", "z-phat"] = "z-phat",
    continuity_correction: bool = False,
    direction: Literal["greater", "less"] | None = None,
) -> float

Estimate the required proportion under the null hypothesis.

PARAMETER DESCRIPTION
proportion

Proportion under the alternative hypothesis.

TYPE: float

size

Sample size.

TYPE: int

alternative

Type of the alternative hypothesis:

  • If alternative is 'two-sided', the alternative hypothesis is \(p ≠ p_0\)
  • If alternative is 'greater', the alternative hypothesis is \(p > p_0\)
  • If alternative is 'less', the alternative hypothesis is \(p < p_0\)

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

method

The method used to construct the test statistic.

  • 'z-p0': Standard normal distribution (large sample approximation), using p0 to calculate the variance.
  • 'z-phat': Standard normal distribution (large sample approximation), using phat to calculate the variance.

TYPE: Literal['z-p0', 'z-phat'] DEFAULT: 'z-phat'

continuity_correction

Whether to apply the continuity correction.

TYPE: bool DEFAULT: False

direction

The direction for the proportion under the null hypothesis relative to the proportion under the alternative hypothesis.

  • 'greater': Search for the null proportion greater than the alternative proportion.
  • 'less': Search for the null proportion less than the alternative proportion.

Note

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

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

RETURNS DESCRIPTION
float

The required proportion under the null hypothesis.

RAISES DESCRIPTION
ValueError

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

Info

This solver does not support the exact test method, as minor fluctuations in null_proportion can cause oscillations in power, making it impossible to obtain an accurate null_proportion value under the given parameters.