跳转至

pystatpower.models.proportion.independent.ci

Functions:

Name Description
solve_distance

Calculate the confidence interval width or the distance from the proportion difference to the confidence bound for the difference between two independent proportions.

solve_size

Estimate the required sample size, given either the confidence interval width or the distance from the proportion difference to the confidence bound for the difference between two independent proportions.

solve_treatment_proportion

Estimate the required proportion in the treatment group (\(p_1\)), given either the confidence interval width or the distance from the proportion difference to the confidence bound for the difference between two independent proportions.

solve_reference_proportion

Estimate the required proportion in the reference group (\(p_2\)), given either the confidence interval width or the distance from the proportion difference to the confidence bound for the difference between two independent proportions.

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 one-sided", "upper one-sided"
    ] = "two-sided",
    method: Literal[
        "chisq",
        "chisq_cc",
        "newcombe_wilson",
        "newcombe_wilson_cc",
        "farrington_manning",
        "miettinen_nurminen",
    ] = "chisq",
) -> float

Calculate the confidence interval width or the distance from the proportion difference to the confidence bound for the difference between two independent proportions.

Parameters:

Name Type Description Default
treatment_proportion float

Actual proportion in the treatment group (\(p_1\)). Must be between 0 and 1.

required
reference_proportion float

Actual proportion in the reference group (\(p_2\)). Must be between 0 and 1.

required
treatment_size int

Sample size in the treatment group (\(n_1\)). Must be greater than 0.

required
reference_size int

Sample size in the reference group (\(n_2\)). Must be greater than 0.

required
conf_level float

Confidence level.

0.95
interval_type Literal['two-sided', 'lower one-sided', 'upper one-sided']

Type of the confidence interval.

  • 'two-sided': Two-sided confidence interval.
  • 'lower one-sided': Lower one-sided confidence interval.
  • 'upper one-sided': Upper one-sided confidence interval.
'two-sided'
method Literal['chisq', 'chisq_cc', 'newcombe_wilson', 'newcombe_wilson_cc', 'farrington_manning', 'miettinen_nurminen']

Method to calculate the confidence interval.

  • 'chisq': Pearson's chi-square method.
  • 'chisq_cc': Yate's chi-square with continuity correction method.
  • 'newcombe_wilson': Newcombe-Wilson method.
  • 'newcombe_wilson_cc': Newcombe-Wilson with continuity correction method.
  • 'farrington_manning': Farrington and Manning's score method.
  • 'miettinen_nurminen': Miettinen and Nurminen's score method.
'chisq'

Returns:

Type Description
float

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

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 one-sided", "upper one-sided"
    ] = "two-sided",
    method: Literal[
        "chisq",
        "chisq_cc",
        "newcombe_wilson",
        "newcombe_wilson_cc",
        "farrington_manning",
        "miettinen_nurminen",
    ] = "chisq",
) -> tuple[int, int]

Estimate the required sample size, given either the confidence interval width or the distance from the proportion difference to the confidence bound for the difference between two independent proportions.

Parameters:

Name Type Description Default
treatment_proportion float

Actual proportion in the treatment group (\(p_1\)). Must be between 0 and 1.

required
reference_proportion float

Actual proportion in the reference group (\(p_2\)). Must be between 0 and 1.

required
distance float

Confidence interval width or the distance from the proportion difference to the confidence bound.

  • If interval_type='two-sided', provide confidence interval width.
  • If interval_type='lower one-sided', provide the distance from the proportion difference to the lower one-side confidence bound.
  • If interval_type='upper one-sided', provide the distance from the proportion difference to the upper one-side confidence bound.
required
ratio float

Ratio of the sample size in the treatment group to the sample size in the reference group (\(k = n_1 / n_2\)).

1
conf_level float

Confidence level.

0.95
interval_type Literal['two-sided', 'lower one-sided', 'upper one-sided']

Type of the confidence interval.

  • 'two-sided': Two-sided confidence interval.
  • 'lower one-sided': Lower one-sided confidence interval.
  • 'upper one-sided': Upper one-sided confidence interval.
'two-sided'
method Literal['chisq', 'chisq_cc', 'newcombe_wilson', 'newcombe_wilson_cc', 'farrington_manning', 'miettinen_nurminen']

Method to calculate the confidence interval.

  • 'chisq': Pearson's chi-square method.
  • 'chisq_cc': Yate's chi-square with continuity correction method.
  • 'newcombe_wilson': Newcombe-Wilson method.
  • 'newcombe_wilson_cc': Newcombe-Wilson with continuity correction method.
  • 'farrington_manning': Farrington and Manning's score method.
  • 'miettinen_nurminen': Miettinen and Nurminen's score method.
'chisq'

Returns:

Type Description
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 one-sided", "upper one-sided"
    ] = "two-sided",
    method: Literal[
        "chisq",
        "chisq_cc",
        "newcombe_wilson",
        "newcombe_wilson_cc",
        "farrington_manning",
        "miettinen_nurminen",
    ] = "chisq",
) -> float | tuple[float, float]

Estimate the required proportion in the treatment group (\(p_1\)), given either the confidence interval width or the distance from the proportion difference to the confidence bound for the difference between two independent proportions.

Parameters:

Name Type Description Default
reference_proportion float

Actual proportion in the reference group (\(p_2\)). Must be between 0 and 1.

required
treatment_size int

Sample size in the treatment group (\(n_1\)). Must be greater than 0.

required
reference_size int

Sample size in the reference group (\(n_2\)). Must be greater than 0.

required
distance float

Confidence interval width or the distance from the proportion difference to the confidence bound.

  • If interval_type='two-sided', provide confidence interval width.
  • If interval_type='lower one-sided', provide the distance from the proportion difference to the lower one-side confidence bound.
  • If interval_type='upper one-sided', provide the distance from the proportion difference to the upper one-side confidence bound.
required
conf_level float

Confidence level.

0.95
interval_type Literal['two-sided', 'lower one-sided', 'upper one-sided']

Type of the confidence interval.

  • 'two-sided': Two-sided confidence interval.
  • 'lower one-sided': Lower one-sided confidence interval.
  • 'upper one-sided': Upper one-sided confidence interval.
'two-sided'
method Literal['chisq', 'chisq_cc', 'newcombe_wilson', 'newcombe_wilson_cc', 'farrington_manning', 'miettinen_nurminen']

Method to calculate the confidence interval.

  • 'chisq': Pearson's chi-square method.
  • 'chisq_cc': Yate's chi-square with continuity correction method.
  • 'newcombe_wilson': Newcombe-Wilson method.
  • 'newcombe_wilson_cc': Newcombe-Wilson with continuity correction method.
  • 'farrington_manning': Farrington and Manning's score method.
  • 'miettinen_nurminen': Miettinen and Nurminen's score method.
'chisq'

Returns:

Type Description
float | tuple[float, float]

The required proportion in the treatment group (\(p_1\)), or a tuple of proportions if two solutions 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 one-sided", "upper one-sided"
    ] = "two-sided",
    method: Literal[
        "chisq",
        "chisq_cc",
        "newcombe_wilson",
        "newcombe_wilson_cc",
        "farrington_manning",
        "miettinen_nurminen",
    ] = "chisq",
) -> float | tuple[float, float]

Estimate the required proportion in the reference group (\(p_2\)), given either the confidence interval width or the distance from the proportion difference to the confidence bound for the difference between two independent proportions.

Parameters:

Name Type Description Default
treatment_proportion float

Actual proportion in the treatment group (\(p_1\)). Must be between 0 and 1.

required
treatment_size int

Sample size in the treatment group (\(n_1\)). Must be greater than 0.

required
reference_size int

Sample size in the reference group (\(n_2\)). Must be greater than 0.

required
distance float

Confidence interval width or the distance from the proportion difference to the confidence bound.

  • If interval_type='two-sided', provide confidence interval width.
  • If interval_type='lower one-sided', provide the distance from the proportion difference to the lower one-side confidence bound.
  • If interval_type='upper one-sided', provide the distance from the proportion difference to the upper one-side confidence bound.
required
conf_level float

Confidence level.

0.95
interval_type Literal['two-sided', 'lower one-sided', 'upper one-sided']

Type of the confidence interval.

  • 'two-sided': Two-sided confidence interval.
  • 'lower one-sided': Lower one-sided confidence interval.
  • 'upper one-sided': Upper one-sided confidence interval.
'two-sided'
method Literal['chisq', 'chisq_cc', 'newcombe_wilson', 'newcombe_wilson_cc', 'farrington_manning', 'miettinen_nurminen']

Method to calculate the confidence interval.

  • 'chisq': Pearson's chi-square method.
  • 'chisq_cc': Yate's chi-square with continuity correction method.
  • 'newcombe_wilson': Newcombe-Wilson method.
  • 'newcombe_wilson_cc': Newcombe-Wilson with continuity correction method.
  • 'farrington_manning': Farrington and Manning's score method.
  • 'miettinen_nurminen': Miettinen and Nurminen's score method.
'chisq'

Returns:

Type Description
float | tuple[float, float]

The required proportion in the reference group (\(p_2\)), or a tuple of proportions if two solutions found.