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.
|
0.95
|
interval_type
|
Literal['two-sided', 'lower', 'upper']
|
Type of the confidence interval.
|
'two-sided'
|
method
|
Literal['wald', 'wilson', 'clopper-pearson', 'cp']
|
The method used to construct the confidence interval.
|
'cp'
|
continuity_correction
|
bool
|
Whether to apply the continuity correction, only takes effect when |
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
|
|
required |
conf_level
|
float
|
Confidence level.
|
0.95
|
interval_type
|
Literal['two-sided', 'lower', 'upper']
|
Type of the confidence interval.
|
'two-sided'
|
method
|
Literal['wald', 'wilson', 'clopper-pearson', 'cp']
|
The method used to construct the confidence interval.
|
'cp'
|
continuity_correction
|
bool
|
Whether to apply the continuity correction, only takes effect when |
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
|
|
required |
conf_level
|
float
|
Confidence level.
|
0.95
|
interval_type
|
Literal['two-sided', 'lower', 'upper']
|
Type of the confidence interval.
|
'two-sided'
|
method
|
Literal['wald', 'wilson', 'clopper-pearson', 'cp']
|
The method used to construct the confidence interval.
|
'cp'
|
continuity_correction
|
bool
|
Whether to apply the continuity correction, only takes effect when |
False
|
direction
|
Literal['greater', 'less']
|
The search direction for the proportion relative to the 0.5.
|
'greater'
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The required proportion. |