跳转至

pystatpower.proportion.independent.inequality

Functions:

Name Description
solve_power

Calculate the statistical power.

solve_size

Estimate the required sample size.

solve_treatment_proportion

Estimate the required proportion in the treatment group.

solve_reference_proportion

Estimate the required proportion in the reference group.

solve_power

solve_power(
    *,
    treatment_proportion: float,
    reference_proportion: float,
    treatment_size: int,
    reference_size: int,
    alternative: Literal["two-sided", "one-sided"],
    alpha: float = 0.05,
    method: Literal["z-pooled", "z-unpooled"],
    continuity_correction: bool = False,
) -> float

Calculate the statistical power.

Parameters:

Name Type Description Default
treatment_proportion float

Proportion in the treatment group.

required
reference_proportion float

Proportion in the reference group.

required
treatment_size int

Sample size in the treatment group.

required
reference_size int

Sample size in the reference group.

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

Type of the alternative hypothesis.

  • If alternative is 'two-sided', the alternative hypothesis is \(p_1 ≠ p_2\)
  • If alternative is 'one-sided', the alternative hypothesis is \(p_1 > p_2\) or \(p_1 < p_2\), depending on the value of treatment_proportion and reference_proportion.
required
alpha float

Significance level.

  • If alternative is 'two-sided', alpha represents the two-sided significance level.
  • If alternative is 'one-sided', alpha represents the one-sided significance level.
0.05
method Literal['z-pooled', 'z-unpooled']

The method used to construct the test statistic.

  • 'z-pooled': Z-test using pooled variance.
  • 'z-unpooled': Z-test using unpooled variance.
required
continuity_correction bool

Wether to apply Yates' continuity correction.

False

Returns:

Name Type Description
float float

The statistical power of the test.

solve_size

solve_size(
    *,
    treatment_proportion: float,
    reference_proportion: float,
    alternative: Literal["two-sided", "one-sided"],
    ratio: float = 1,
    alpha: float = 0.05,
    power: float = 0.8,
    method: Literal["z-pooled", "z-unpooled"],
    continuity_correction: bool = False,
) -> tuple[int, int]

Estimate the required sample size.

Parameters:

Name Type Description Default
treatment_proportion float

Proportion in the treatment group.

required
reference_proportion float

Proportion in the reference group.

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

Type of the alternative hypothesis.

  • If alternative is 'two-sided', the alternative hypothesis is \(p_1 ≠ p_2\)
  • If alternative is 'one-sided', the alternative hypothesis is \(p_1 > p_2\) or \(p_1 < p_2\), depending on the value of treatment_proportion and reference_proportion.
required
ratio float

Ratio of sample sizes in the treatment and reference groups.

1
alpha float

Significance level.

  • If alternative is 'two-sided', alpha represents the two-sided significance level.
  • If alternative is 'one-sided', alpha represents the one-sided significance level.
0.05
power float

Expected statistical power.

0.8 is a commonly used statistical power.

0.8
method Literal['z-pooled', 'z-unpooled']

The method used to construct the test statistic.

  • 'z-pooled': Z-test using pooled variance.
  • 'z-unpooled': Z-test using unpooled variance.
required
continuity_correction bool

Wether to apply Yates' continuity correction.

False

Returns:

Type Description
tuple[int, int]

tuple[int, int]: The required sample sizes for the treatment and reference groups, respectively.

solve_treatment_proportion

solve_treatment_proportion(
    *,
    reference_proportion: float,
    treatment_size: int,
    reference_size: int,
    alternative: Literal["two-sided", "one-sided"],
    alpha: float = 0.05,
    power: float = 0.8,
    method: Literal["z-pooled", "z-unpooled"],
    continuity_correction: bool = False,
    direction: Literal["greater", "less"],
) -> float

Estimate the required proportion in the treatment group.

Parameters:

Name Type Description Default
reference_proportion float

Proportion in the reference group.

required
treatment_size int

Sample size in the treatment group.

required
reference_size int

Sample size in the reference group.

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

Type of the alternative hypothesis.

  • If alternative is 'two-sided', the alternative hypothesis is \(p_1 ≠ p_2\)
  • If alternative is 'one-sided', the alternative hypothesis is \(p_1 > p_2\) or \(p_1 < p_2\), depending on the value of treatment_proportion and reference_proportion.
required
alpha float

Significance level.

  • If alternative is 'two-sided', alpha represents the two-sided significance level.
  • If alternative is 'one-sided', alpha represents the one-sided significance level.
0.05
power float

Expected statistical power.

0.8 is a commonly used statistical power.

0.8
method Literal['z-pooled', 'z-unpooled']

The method used to construct the test statistic.

  • 'z-pooled': Z-test using pooled variance.
  • 'z-unpooled': Z-test using unpooled variance.
required
continuity_correction bool

Wether to apply Yates' continuity correction.

False
direction Literal['greater', 'less']

The direction for the treatment proportion relative to the reference proportion.

  • 'greater': Search for the treatment proportion greater than the reference proportion.
  • 'less': Search for the treatment proportion less than the reference proportion.
required

Returns:

Name Type Description
float float

The required proportion in the treatment group.

solve_reference_proportion

solve_reference_proportion(
    *,
    treatment_proportion: float,
    treatment_size: int,
    reference_size: int,
    alternative: Literal["two-sided", "one-sided"],
    alpha: float = 0.05,
    power: float = 0.8,
    method: Literal["z-pooled", "z-unpooled"],
    continuity_correction: bool = False,
    direction: Literal["greater", "less"],
) -> float

Estimate the required proportion in the reference group.

Parameters:

Name Type Description Default
treatment_proportion float

Proportion in the treatment group.

required
treatment_size int

Sample size in the treatment group.

required
reference_size int

Sample size in the reference group.

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

Type of the alternative hypothesis.

  • If alternative is 'two-sided', the alternative hypothesis is \(p_1 ≠ p_2\)
  • If alternative is 'one-sided', the alternative hypothesis is \(p_1 > p_2\) or \(p_1 < p_2\), depending on the value of treatment_proportion and reference_proportion.
required
alpha float

Significance level.

  • If alternative is 'two-sided', alpha represents the two-sided significance level.
  • If alternative is 'one-sided', alpha represents the one-sided significance level.
0.05
power float

Expected statistical power.

0.8 is a commonly used statistical power.

0.8
method Literal['z-pooled', 'z-unpooled']

The method used to construct the test statistic.

  • 'z-pooled': Z-test using pooled variance.
  • 'z-unpooled': Z-test using unpooled variance.
required
continuity_correction bool

Wether to apply Yates' continuity correction.

False
direction Literal['greater', 'less']

The direction for the treatment proportion relative to the reference proportion.

  • 'greater': Search for the treatment proportion greater than the reference proportion.
  • 'less': Search for the treatment proportion less than the reference proportion.
required

Returns:

Name Type Description
float float

The required proportion in the reference group.