跳转至

pystatpower.proportion.single.ci

Functions:

Name Description
solve_distance

Calculate the width of the confidence interval for a single-group proportion (two-sided confidence interval),

solve_size

Estimate the required sample size for a single-group proportion confidence interval.

solve_proportion

Estimate the required proportion for a single-group proportion confidence interval.

solve_distance

solve_distance(
    *,
    proportion: float,
    size: int,
    conf_level: float = 0.95,
    interval_type: Literal[
        "two-sided", "lower", "upper"
    ] = "two-sided",
    method: Literal[
        "wald", "wilson", "clopper-pearson", "cp"
    ] = "cp",
    continuity_correction: bool = False,
) -> float

Calculate the width of the confidence interval for a single-group proportion (two-sided confidence interval), or the distance from the proportion to the confidence limit (lower or upper one-sided confidence interval).

Parameters:

Name Type Description Default
proportion float

Proportion.

required
size int

Sample size.

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['wald', 'wilson', 'clopper-pearson', 'cp']

The method used to construct the confidence interval.

  • 'wald': Wald method.
  • 'wilson': Wilson method.
  • 'clopper-pearson', 'cp': Clopper-Pearson method.
'cp'
continuity_correction bool

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

False

Returns:

Name Type Description
float float

The confidence interval width (two-sided confidence interval), or the distance from the proportion to the confidence limit (lower or upper one-sided confidence interval).

solve_size

solve_size(
    *,
    proportion: float,
    distance: float,
    conf_level: float = 0.95,
    interval_type: Literal[
        "two-sided", "lower", "upper"
    ] = "two-sided",
    method: Literal[
        "wald", "wilson", "clopper-pearson", "cp"
    ] = "cp",
    continuity_correction: bool = False,
) -> int

Estimate the required sample size for a single-group proportion confidence interval.

For two-sided confidence interval, the confidence interval width needs to be given.

For one-sided confidence interval, the distance from the proportion to the confidence limit needs to be given.

Parameters:

Name Type Description Default
proportion float

Proportion.

required
distance float
  • If interval_type is 'two-sided', a confidence interval width is required.
  • If interval_type is 'lower' or 'upper', a distance from the proportion to the confidence limit is required.
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['wald', 'wilson', 'clopper-pearson', 'cp']

The method used to construct the confidence interval.

  • 'wald': Wald method.
  • 'wilson': Wilson method.
  • 'clopper-pearson', 'cp': Clopper-Pearson method.
'cp'
continuity_correction bool

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

False

Returns:

Name Type Description
int int

The required sample size.

solve_proportion

solve_proportion(
    *,
    size: int,
    distance: float,
    conf_level: float = 0.95,
    interval_type: Literal[
        "two-sided", "lower", "upper"
    ] = "two-sided",
    method: Literal[
        "wald", "wilson", "clopper-pearson", "cp"
    ] = "cp",
    continuity_correction: bool = False,
    direction: Literal["greater", "less"] = "greater",
) -> float

Estimate the required proportion for a single-group proportion confidence interval.

For two-sided confidence interval, the confidence interval width needs to be given.

For one-sided confidence interval, the distance from the proportion to the confidence limit needs to be given.

Parameters:

Name Type Description Default
size int

Sample size.

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

Confidence level.

  • If interval_type is 'two-sided', a two-sided confidence level should 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['wald', 'wilson', 'clopper-pearson', 'cp']

The method used to construct the confidence interval.

  • 'wald': Wald method.
  • 'wilson': Wilson method.
  • 'clopper-pearson', 'cp': Clopper-Pearson method.
'cp'
continuity_correction bool

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

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

The search direction for the proportion relative to the 0.5.

  • 'greater': Search for the proportion greater than 0.5.
  • 'less': Search for the proportion less than 0.5.
'greater'

Returns:

Name Type Description
float float

The required proportion.