跳转至

pystatpower.proportion.independent.ci

FUNCTION 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.

PARAMETER DESCRIPTION
treatment_proportion

Proportion in the treatment group.

TYPE: float

reference_proportion

Proportion in the reference group.

TYPE: float

treatment_size

Sample size in the treatment group.

TYPE: int

reference_size

Sample size in the reference group.

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.

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

TYPE: Literal['chisq', 'wilson', 'farrington_manning', 'fm', 'miettinen_nurminen', 'mn']

continuity_correction

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

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
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.

PARAMETER DESCRIPTION
treatment_proportion

Proportion in the treatment group.

TYPE: float

reference_proportion

Proportion in the reference group.

TYPE: float

distance

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.

TYPE: float

ratio

Ratio of sample sizes in the treatment and reference groups.

TYPE: float DEFAULT: 1

conf_level

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.

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.

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

TYPE: Literal['chisq', 'wilson', 'farrington_manning', 'fm', 'miettinen_nurminen', 'mn']

continuity_correction

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

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
tuple[int, int]

The required sample sizes in treatment and reference groups, respectively.

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.

PARAMETER DESCRIPTION
reference_proportion

Proportion in the reference group.

TYPE: float

treatment_size

Sample size in the treatment group.

TYPE: int

reference_size

Sample size in the reference group.

TYPE: int

distance

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.

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.

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

TYPE: Literal['chisq', 'wilson', 'farrington_manning', 'fm', 'miettinen_nurminen', 'mn']

continuity_correction

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

TYPE: bool DEFAULT: False

direction

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.

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

RETURNS DESCRIPTION
float

The required proportion in the treatment group.

RAISES 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.

PARAMETER DESCRIPTION
treatment_proportion

Proportion in the treatment group.

TYPE: float

treatment_size

Sample size in the treatment group.

TYPE: int

reference_size

Sample size in the reference group.

TYPE: int

distance

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.

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.

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

TYPE: Literal['chisq', 'wilson', 'farrington_manning', 'fm', 'miettinen_nurminen', 'mn']

continuity_correction

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

TYPE: bool DEFAULT: False

direction

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.

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

RETURNS DESCRIPTION
float

The required proportion in the reference group.

RAISES DESCRIPTION
SolutionNotFoundError

If the solution cannot be found.