跳转至

pystatpower.proportion.single.ci

FUNCTION DESCRIPTION
solve_distance

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

solve_size

Estimate the required sample size.

solve_proportion

Estimate the required proportion.

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 confidence interval width or the distance from the proportion to the confidence limit.

PARAMETER DESCRIPTION
proportion

Proportion.

TYPE: float

size

Sample size.

TYPE: int

conf_level

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.

TYPE: float DEFAULT: 0.95

interval_type

Type of the confidence interval.

  • 'two-sided': Two-sided confidence interval.
  • 'lower': Lower one-sided confidence interval.
  • 'upper': Upper one-sided confidence interval.

TYPE: Literal['two-sided', 'lower', 'upper'] DEFAULT: 'two-sided'

method

The method used to construct the confidence interval.

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

TYPE: Literal['wald', 'wilson', 'clopper-pearson', 'cp'] DEFAULT: 'cp'

continuity_correction

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

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
float

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

  • If alternative is 'two-sided', the confidence interval width is returned.
  • If alternative is 'less', the distance from the proportion to the confidence limit is returned.

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 two-sided confidence interval, the confidence interval width is required.

For one-sided confidence interval, the distance from the proportion to the confidence limit is required.

PARAMETER DESCRIPTION
proportion

Proportion.

TYPE: float

distance
  • 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.

TYPE: float

conf_level

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.

TYPE: float DEFAULT: 0.95

interval_type

Type of the confidence interval.

  • 'two-sided': Two-sided confidence interval.
  • 'lower': Lower one-sided confidence interval.
  • 'upper': Upper one-sided confidence interval.

TYPE: Literal['two-sided', 'lower', 'upper'] DEFAULT: 'two-sided'

method

The method used to construct the confidence interval.

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

TYPE: Literal['wald', 'wilson', 'clopper-pearson', 'cp'] DEFAULT: 'cp'

continuity_correction

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

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
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 two-sided confidence interval, the confidence interval width is required.

For one-sided confidence interval, the distance from the proportion to the confidence limit is required.

PARAMETER DESCRIPTION
size

Sample size.

TYPE: int

distance
  • 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.

TYPE: float

conf_level

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.

TYPE: float DEFAULT: 0.95

interval_type

Type of the confidence interval.

  • 'two-sided': Two-sided confidence interval.
  • 'lower': Lower one-sided confidence interval.
  • 'upper': Upper one-sided confidence interval.

TYPE: Literal['two-sided', 'lower', 'upper'] DEFAULT: 'two-sided'

method

The method used to construct the confidence interval.

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

TYPE: Literal['wald', 'wilson', 'clopper-pearson', 'cp'] DEFAULT: 'cp'

continuity_correction

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

TYPE: bool DEFAULT: False

direction

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.

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

RETURNS DESCRIPTION
float

The required proportion.