跳转至

pystatpower.models.proportion.single.inequality

Functions:

Name Description
solve_power

Calculate the power for a one-sample proportion test.

solve_size

Estimate the sample size required for a one-sample proportion test.

solve_null_proportion

Estimate the null proportion (p0) required to achieve a target power for a one-sample proportion test.

solve_proportion

Estimate the alternative proportion (p1) required to achieve a target power for a one-sample proportion test.

solve_power

solve_power(*, null_proportion: float, proportion: float, size: int, alternative: Literal['one-sided', 'two-sided'] = 'two-sided', alpha: float = 0.05, phat: bool = False, continuity_correction: bool = False) -> float

Calculate the power for a one-sample proportion test.

Parameters:

Name Type Description Default
null_proportion float

The proportion specified under the null hypothesis (p0). Must be in the interval (0, 1).

required
proportion float

The expected or observed proportion under the alternative hypothesis (p1). Must be in the interval (0, 1).

required
size int

Total number of independent observations (sample size). Must be >= 1.

required
alternative Literal['one-sided', 'two-sided']

Direction of the test:

  • "two-sided": \(H1: p1 \neq p_0\)
  • "one-sided": \(H1: p1 > p_0\) or \(p1 < p_0\)

Default is "two-sided".

'two-sided'
alpha float

Significance level (Type I error rate). Defaults is 0.05.

0.05
phat bool

Whether to use sample proportion to calculate standard deviation. Defaults is False.

False
continuity_correction bool

Whether to apply continuity correction to the normal approximation. Defaults is False.

False

Returns:

Name Type Description
power float

The calculated power of the test, in the range [0, 1].

solve_size

solve_size(*, null_proportion: float, proportion: float, alternative: Literal['one-sided', 'two-sided'] = 'two-sided', alpha: float = 0.05, power: float = 0.8, phat: bool = False, continuity_correction: bool = False) -> int

Estimate the sample size required for a one-sample proportion test.

Parameters:

Name Type Description Default
null_proportion float

The proportion specified under the null hypothesis (p0). Must be in the interval (0, 1).

required
proportion float

The expected proportion under the alternative hypothesis (p1). Must be in the interval (0, 1).

required
alternative Literal['one-sided', 'two-sided']

Direction of the test:

  • "two-sided": \(H1: p \neq p_0\)
  • "one-sided": \(H1: p > p_0\) or \(p < p_0\)

Default is "two-sided".

'two-sided'
alpha float

Significance level (Type I error rate). Defaults is 0.05.

0.05
power float

Desired statistical power (1 - Type II error rate). Defaults is 0.80.

0.8
phat bool

Whether to use sample proportion to calculate standard deviation. Defaults is False.

False
continuity_correction bool

Whether to apply continuity correction to the normal approximation. Defaults is False.

False

Returns:

Name Type Description
size float

The minimum sample size (rounded up to the nearest integer) required to achieve the target power.

solve_null_proportion

solve_null_proportion(*, proportion: float, size: int, alternative: Literal['one-sided', 'two-sided'] = 'two-sided', alpha: float = 0.05, power: float = 0.8, phat: bool = False, continuity_correction: bool = False, proportion_selection: Literal['lower', 'upper'] = 'lower') -> float

Estimate the null proportion (p0) required to achieve a target power for a one-sample proportion test.

Parameters:

Name Type Description Default
proportion float

The expected proportion under the alternative hypothesis (p1). Must be in the interval (0, 1).

required
size int

Total number of independent observations (sample size). Must be >= 1.

required
alternative Literal['one-sided', 'two-sided']

Direction of the test:

  • "two-sided": \(H1: p \neq p_0\)
  • "one-sided": \(H1: p > p_0\) or \(p < p_0\)

Default is "two-sided".

'two-sided'
alpha float

Significance level (Type I error rate). Defaults is 0.05.

0.05
power float

Desired statistical power (1 - Type II error rate). Defaults is 0.80.

0.8
phat bool

Whether to use sample proportion to calculate standard deviation. Defaults is False.

False
continuity_correction bool

Whether to apply continuity correction to the normal approximation. Defaults is False.

False
proportion_selection Literal['lower', 'upper']

Selection strategy when two valid null proportions exist:

  • "lower": Returns the solution where p0 < p1.
  • "upper": Returns the solution where p0 > p1.

If only one solution exists in (0, 1), this parameter is ignored. Defaults is "lower".

'lower'

Returns:

Name Type Description
null_proportion float

The estimated null proportion (p0).

solve_proportion

solve_proportion(*, null_proportion: float, size: int, alternative: Literal['one-sided', 'two-sided'] = 'two-sided', alpha: float = 0.05, power: float = 0.8, phat: bool = False, continuity_correction: bool = False, proportion_selection: Literal['lower', 'upper'] = 'upper')

Estimate the alternative proportion (p1) required to achieve a target power for a one-sample proportion test.

Parameters:

Name Type Description Default
null_proportion float

The proportion specified under the null hypothesis (p0). Must be in the interval (0, 1).

required
size int

Total number of independent observations (sample size). Must be >= 1.

required
alternative Literal['one-sided', 'two-sided']

Direction of the test:

  • "two-sided": \(H1: p \neq p_0\)
  • "one-sided": \(H1: p > p_0\) or \(p < p_0\)

Default is "two-sided".

'two-sided'
alpha float

Significance level (Type I error rate). Defaults is 0.05.

0.05
power float

Desired statistical power (1 - Type II error rate). Defaults is 0.80.

0.8
phat bool

Whether to use sample proportion to calculate standard deviation. Defaults is False.

False
continuity_correction bool

Whether to apply continuity correction to the normal approximation. Defaults is False.

False
proportion_selection Literal['lower', 'upper']

Selection strategy when two valid alternative proportions exist:

  • "lower": Returns the solution where p1 < p0.
  • "upper": Returns the solution where p1 > p0.

If only one solution exists in (0, 1), this parameter is ignored. Defaults is "upper".

'upper'

Returns:

Name Type Description
proportion float

The estimated alternative proportion (p1).