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.
|
0.95
|
interval_type
|
Literal['two-sided', 'lower', 'upper']
|
Type of the confidence interval.
|
'two-sided'
|
method
|
Literal['chisq', 'wilson', 'farrington_manning', 'fm', 'miettinen_nurminen', 'mn']
|
The method used to construct the confidence interval.
|
required |
continuity_correction
|
bool
|
Whether to apply the continuity correction, only takes effect when |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The confidence interval width or the distance from the proportion difference to the confidence limit.
|
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.
|
required |
ratio
|
float
|
Ratio of sample sizes in the treatment and reference group. |
1
|
conf_level
|
float
|
Confidence level.
|
0.95
|
interval_type
|
Literal['two-sided', 'lower', 'upper']
|
Type of the confidence interval.
|
'two-sided'
|
method
|
Literal['chisq', 'wilson', 'farrington_manning', 'fm', 'miettinen_nurminen', 'mn']
|
The method used to construct the confidence interval.
|
required |
continuity_correction
|
bool
|
Whether to apply the continuity correction, only takes effect when |
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.
|
required |
conf_level
|
float
|
Confidence level.
|
0.95
|
interval_type
|
Literal['two-sided', 'lower', 'upper']
|
Type of the confidence interval.
|
'two-sided'
|
method
|
Literal['chisq', 'wilson', 'farrington_manning', 'fm', 'miettinen_nurminen', 'mn']
|
The method used to construct the confidence interval.
|
required |
continuity_correction
|
bool
|
Whether to apply the continuity correction, only takes effect when |
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.
|
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.
|
required |
conf_level
|
float
|
Confidence level.
|
0.95
|
interval_type
|
Literal['two-sided', 'lower', 'upper']
|
Type of the confidence interval.
|
'two-sided'
|
method
|
Literal['chisq', 'wilson', 'farrington_manning', 'fm', 'miettinen_nurminen', 'mn']
|
The method used to construct the confidence interval.
|
required |
continuity_correction
|
bool
|
Whether to apply the continuity correction, only takes effect when |
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.
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The required proportion in the reference group. |
Raises:
| Type | Description |
|---|---|
SolutionNotFoundError
|
If the solution cannot be found. |