跳转至

pystatpower.proportion.independent.ci

Functions:

Name Description
solve_distance

Calculate the confidence interval width or the distance from the proportion difference to the confidence limit.

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_distance

solve_distance(
    *,
    treatment_proportion: float,
    reference_proportion: float,
    treatment_size: int,
    reference_size: int,
    conf_level: float = 0.95,
    interval_type: Literal[
        "two-sided", "lower", "upper"
    ] = "two-sided",
    method: Literal[
        "chisq",
        "wilson",
        "farrington_manning",
        "fm",
        "miettinen_nurminen",
        "mn",
    ],
    continuity_correction: bool = False,
) -> float

Calculate the confidence interval width or the distance from the proportion difference to the confidence limit.

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
conf_level float

Confidence level.

  • If interval_type is 'two-sided', a two-sided confidence level is required.
  • If interval_type is 'lower' or 'upper', a one-sided confidence level is required.
0.95
interval_type Literal['two-sided', 'lower', 'upper']

Type of the confidence interval.

  • 'two-sided': Two-sided confidence interval.
  • 'lower': Lower one-sided confidence interval.
  • 'upper': Upper one-sided confidence interval.
'two-sided'
method Literal['chisq', 'wilson', 'farrington_manning', 'fm', 'miettinen_nurminen', 'mn']

The method used to construct the confidence interval.

  • 'chisq': Pearson's chi-square method.
  • 'wilson': Newcombe-Wilson method.
  • 'farrington_manning', 'fm': Farrington and Manning's score method.
  • 'miettinen_nurminen', 'mn': Miettinen and Nurminen's score method.
required
continuity_correction bool

Whether to apply the continuity correction, only takes effect when method is specified as 'chisq' or 'wilson'

False

Returns:

Name Type Description
float float

The confidence interval width or the distance from the proportion difference to the confidence limit.

  • If interval_type is 'two-sided', the confidence interval width is returned.
  • If interval_type is 'lower' or 'upper', the distance from the proportion difference to the confidence limit is returned.

solve_size

solve_size(
    *,
    treatment_proportion: float,
    reference_proportion: float,
    distance: float,
    ratio: float = 1,
    conf_level: float = 0.95,
    interval_type: Literal[
        "two-sided", "lower", "upper"
    ] = "two-sided",
    method: Literal[
        "chisq",
        "wilson",
        "farrington_manning",
        "fm",
        "miettinen_nurminen",
        "mn",
    ],
    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
distance float

Confidence interval width or distance from the proportion to the confidence limit.

  • If interval_type = 'two-sided', specify the confidence interval width.
  • If interval_type = 'lower' or 'upper', specify the distance from the proportion difference to the confidence limit.
required
ratio float

Ratio of sample sizes in the treatment and reference group.

1
conf_level float

Confidence level.

  • If interval_type is 'two-sided', specify the two-sided confidence level.
  • If interval_type is 'lower' or 'upper', specify the one-sided confidence level.
0.95
interval_type Literal['two-sided', 'lower', 'upper']

Type of the confidence interval.

  • 'two-sided': Two-sided confidence interval.
  • 'lower': Lower one-sided confidence interval.
  • 'upper': Upper one-sided confidence interval.
'two-sided'
method Literal['chisq', 'wilson', 'farrington_manning', 'fm', 'miettinen_nurminen', 'mn']

The method used to construct the confidence interval.

  • 'chisq': Pearson's chi-square method.
  • 'wilson': Newcombe-Wilson method.
  • 'farrington_manning', 'fm': Farrington and Manning's score method.
  • 'miettinen_nurminen', 'mn': Miettinen and Nurminen's score method.
required
continuity_correction bool

Whether to apply the continuity correction, only takes effect when method is specified as 'chisq' or 'wilson'

False

Returns:

Type Description
tuple[int, int]

tuple[int, int]: The required sample size.

solve_treatment_proportion

solve_treatment_proportion(
    *,
    reference_proportion: float,
    treatment_size: int,
    reference_size: int,
    distance: float,
    conf_level: float = 0.95,
    interval_type: Literal[
        "two-sided", "lower", "upper"
    ] = "two-sided",
    method: Literal[
        "chisq",
        "wilson",
        "farrington_manning",
        "fm",
        "miettinen_nurminen",
        "mn",
    ],
    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
distance float

Confidence interval width or distance from the proportion to the confidence limit.

  • If interval_type = 'two-sided', specify the confidence interval width.
  • If interval_type = 'lower' or 'upper', specify the distance from the proportion difference to the confidence limit.
required
conf_level float

Confidence level.

  • If interval_type is 'two-sided', a two-sided confidence level is required.
  • If interval_type is 'lower' or 'upper', a one-sided confidence level is required.
0.95
interval_type Literal['two-sided', 'lower', 'upper']

Type of the confidence interval.

  • 'two-sided': Two-sided confidence interval.
  • 'lower': Lower one-sided confidence interval.
  • 'upper': Upper one-sided confidence interval.
'two-sided'
method Literal['chisq', 'wilson', 'farrington_manning', 'fm', 'miettinen_nurminen', 'mn']

The method used to construct the confidence interval.

  • 'chisq': Pearson's chi-square method.
  • 'wilson': Newcombe-Wilson method.
  • 'farrington_manning', 'fm': Farrington and Manning's score method.
  • 'miettinen_nurminen', 'mn': Miettinen and Nurminen's score method.
required
continuity_correction bool

Whether to apply the continuity correction, only takes effect when method is specified as 'chisq' or 'wilson'

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

Controls which of the two potential solutions for the treatment proportion is selected.

Since the confidence interval distance constraint typically yields two valid roots, this parameter determines whether to return the higher or lower proportion.

  • 'greater': Returns the larger (higher) of the two treatment proportion solutions.
  • 'less': Returns the smaller (lower) of the two treatment proportion solutions.
required

Returns:

Name Type Description
float float

The required proportion in the treatment group.

Raises:

Type Description
SolutionNotFoundError

If the solution cannot be found.

solve_reference_proportion

solve_reference_proportion(
    *,
    treatment_proportion: float,
    treatment_size: int,
    reference_size: int,
    distance: float,
    conf_level: float = 0.95,
    interval_type: Literal[
        "two-sided", "lower", "upper"
    ] = "two-sided",
    method: Literal[
        "chisq",
        "wilson",
        "farrington_manning",
        "fm",
        "miettinen_nurminen",
        "mn",
    ],
    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
distance float

Confidence interval width or distance from the proportion to the confidence limit.

  • If interval_type = 'two-sided', specify the confidence interval width.
  • If interval_type = 'lower' or 'upper', specify the distance from the proportion difference to the confidence limit.
required
conf_level float

Confidence level.

  • If interval_type is 'two-sided', a two-sided confidence level is required.
  • If interval_type is 'lower' or 'upper', a one-sided confidence level is required.
0.95
interval_type Literal['two-sided', 'lower', 'upper']

Type of the confidence interval.

  • 'two-sided': Two-sided confidence interval.
  • 'lower': Lower one-sided confidence interval.
  • 'upper': Upper one-sided confidence interval.
'two-sided'
method Literal['chisq', 'wilson', 'farrington_manning', 'fm', 'miettinen_nurminen', 'mn']

The method used to construct the confidence interval.

  • 'chisq': Pearson's chi-square method.
  • 'wilson': Newcombe-Wilson method.
  • 'farrington_manning', 'fm': Farrington and Manning's score method.
  • 'miettinen_nurminen', 'mn': Miettinen and Nurminen's score method.
required
continuity_correction bool

Whether to apply the continuity correction, only takes effect when method is specified as 'chisq' or 'wilson'

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

Controls which of the two potential solutions for the reference proportion is selected.

Since the confidence interval distance constraint typically yields two valid roots, this parameter determines whether to return the higher or lower proportion.

  • 'greater': Returns the larger (higher) of the two reference proportion solutions.
  • 'less': Returns the smaller (lower) of the two reference proportion solutions.
required

Returns:

Name Type Description
float float

The required proportion in the reference group.

Raises:

Type Description
SolutionNotFoundError

If the solution cannot be found.