pystatpower.proportion.single.superiority
¶
Functions:
| Name | Description |
|---|---|
solve_power |
Calculate the statistical power for a superiority test of one proportion. |
solve_size |
Estimate the required sample size for a superiority test of one proportion. |
solve_proportion |
Estimate the required proportion under the alternative hypothesis for a superiority test of one proportion. |
solve_null_proportion |
Estimate the required proportion under the null hypothesis for a superiority test of one proportion. |
solve_superiority_proportion |
Estimate the required superiority proportion for a superiority test of one proportion. |
solve_margin |
Estimate the required margin for a superiority test for one proportion. |
solve_power
¶
solve_power(
*,
proportion: float,
null_proportion: float | None = None,
margin: float | None = None,
superiority_proportion: float | None = None,
size: int,
alternative: Literal["greater", "less"],
alpha: float = 0.025,
method: Literal["z-p0", "z-phat"],
continuity_correction: bool = False,
) -> float
Calculate the statistical power for a superiority test of one proportion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proportion
|
float
|
Proportion under the alternative hypothesis. |
required |
null_proportion
|
float | None
|
Proportion under the null hypothesis. Ignored if |
None
|
margin
|
float | None
|
The superiority margin. Ignored if Regardless of whether
|
None
|
superiority_proportion
|
float | None
|
The superiority proportion. Required if either |
None
|
size
|
int
|
Sample size. |
required |
alternative
|
Literal['greater', 'less']
|
Type of the alternative hypothesis:
|
required |
alpha
|
float
|
Significance level. The superiority test is a one-sided test, and 0.025 is a commonly used significance level. |
0.025
|
method
|
Literal['z-p0', 'z-phat']
|
The method used to construct the test statistic.
|
required |
continuity_correction
|
bool
|
Whether to apply the continuity correction. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The statistical power of the test. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
solve_size
¶
solve_size(
*,
proportion: float,
null_proportion: float | None = None,
margin: float | None = None,
superiority_proportion: float | None = None,
alternative: Literal["greater", "less"],
alpha: float = 0.025,
power: float = 0.8,
method: Literal["z-p0", "z-phat"],
continuity_correction: bool = False,
) -> int
Estimate the required sample size for a superiority test of one proportion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proportion
|
float
|
Proportion under the alternative hypothesis. |
required |
null_proportion
|
float | None
|
Proportion under the null hypothesis. Ignored if |
None
|
margin
|
float | None
|
The superiority margin. Ignored if Regardless of whether
|
None
|
superiority_proportion
|
float | None
|
The superiority proportion. Required if either |
None
|
alternative
|
Literal['greater', 'less']
|
Type of the alternative hypothesis:
|
required |
alpha
|
float
|
Significance level. The superiority test is a one-sided test, and 0.025 is a commonly used significance level. |
0.025
|
power
|
float
|
Expected statistical power. 0.8 is a commonly used statistical power. |
0.8
|
method
|
Literal['z-p0', 'z-phat']
|
The method used to construct the test statistic.
|
required |
continuity_correction
|
bool
|
Whether to apply the continuity correction. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The required sample size. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
solve_proportion
¶
solve_proportion(
*,
null_proportion: float | None = None,
margin: float | None = None,
superiority_proportion: float | None = None,
size: int,
alternative: Literal["greater", "less"],
alpha: float = 0.025,
power: float = 0.8,
method: Literal["z-p0", "z-phat"],
continuity_correction: bool = False,
) -> float
Estimate the required proportion under the alternative hypothesis for a superiority test of one proportion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
null_proportion
|
float | None
|
Proportion under the null hypothesis. Ignored if |
None
|
margin
|
float | None
|
The superiority margin. Ignored if Regardless of whether
|
None
|
superiority_proportion
|
float | None
|
The superiority proportion. Required if either |
None
|
size
|
int
|
Sample size. |
required |
alternative
|
Literal['greater', 'less']
|
Type of the alternative hypothesis:
|
required |
alpha
|
float
|
Significance level. The superiority test is a one-sided test, and 0.025 is a commonly used significance level. |
0.025
|
power
|
float
|
Expected statistical power. 0.8 is a commonly used statistical power. |
0.8
|
method
|
Literal['z-p0', 'z-phat']
|
The method used to construct the test statistic.
|
required |
continuity_correction
|
bool
|
Whether to apply the continuity correction. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The required proportion under the alternative hypothesis. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
The value range of the alternative hypothesis proportion \(p\) is determined by the null hypothesis proportion \(p_0\) and the non-inferiority margin \(\delta\).
If alternative is 'greater', that is, higher proportions are better, we have:
If alternative is 'less', that is, higher proportions are worse, we have:
solve_null_proportion
¶
solve_null_proportion(
*,
proportion: float,
margin: float,
size: int,
alternative: Literal["greater", "less"],
alpha: float = 0.025,
power: float = 0.8,
method: Literal["z-p0", "z-phat"],
continuity_correction: bool = False,
) -> float
Estimate the required proportion under the null hypothesis for a superiority test of one proportion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proportion
|
float
|
Proportion under the alternative hypothesis. |
required |
margin
|
float
|
The superiority margin. Regardless of whether
|
required |
size
|
int
|
Sample size. |
required |
alternative
|
Literal['greater', 'less']
|
Type of the alternative hypothesis:
|
required |
alpha
|
float
|
Significance level. The superiority test is a one-sided test, and 0.025 is a commonly used significance level. |
0.025
|
power
|
float
|
Expected statistical power. 0.8 is a commonly used statistical power. |
0.8
|
method
|
Literal['z-p0', 'z-phat']
|
The method used to construct the test statistic.
|
required |
continuity_correction
|
bool
|
Whether to apply the continuity correction. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The required proportion under the null hypothesis. |
Notes
The value range of the null hypothesis proportion \(p_0\) is determined by the alternative hypothesis proportion \(p\) and the non-inferiority margin \(\delta\).
If alternative is 'greater', that is, higher proportions are better, we have:
If alternative is 'less', that is, higher proportions are worse, we have:
solve_superiority_proportion
¶
solve_superiority_proportion(
*,
proportion: float,
size: int,
alternative: Literal["greater", "less"],
alpha: float = 0.025,
power: float = 0.8,
method: Literal["z-p0", "z-phat"],
continuity_correction: bool = False,
) -> float
Estimate the required superiority proportion for a superiority test of one proportion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proportion
|
float
|
Proportion under the alternative hypothesis. |
required |
size
|
int
|
Sample size. |
required |
alternative
|
Literal['greater', 'less']
|
Type of the alternative hypothesis:
|
required |
alpha
|
float
|
Significance level. The superiority test is a one-sided test, and 0.025 is a commonly used significance level. |
0.025
|
power
|
float
|
Expected statistical power. 0.8 is a commonly used statistical power. |
0.8
|
method
|
Literal['z-p0', 'z-phat']
|
The method used to construct the test statistic.
|
required |
continuity_correction
|
bool
|
Whether to apply the continuity correction. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The required superiority proportion. |
Notes
The value range of the superiority hypothesis proportion \(p_{\text{sup}}\) is determined by the alternative hypothesis proportion \(p\).
If alternative is 'greater', that is, higher proportions are better, we have:
If alternative is 'less', that is, higher proportions are worse, we have:
solve_margin
¶
solve_margin(
*,
proportion: float,
null_proportion: float,
size: int,
alternative: Literal["greater", "less"],
alpha: float = 0.025,
power: float = 0.8,
method: Literal["z-p0", "z-phat"],
continuity_correction: bool = False,
) -> float
Estimate the required margin for a superiority test for one proportion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proportion
|
float
|
Proportion under the alternative hypothesis. |
required |
null_proportion
|
float
|
Proportion under the null hypothesis. |
required |
size
|
int
|
Sample size. |
required |
alternative
|
Literal['greater', 'less']
|
Type of the alternative hypothesis:
|
required |
alpha
|
float
|
Significance level. The superiority test is a one-sided test, and 0.025 is a commonly used significance level. |
0.025
|
power
|
float
|
Expected statistical power. 0.8 is a commonly used statistical power. |
0.8
|
method
|
Literal['z-p0', 'z-phat']
|
The method used to construct the test statistic.
|
required |
continuity_correction
|
bool
|
Whether to apply the continuity correction. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The required superiority margin. |
Notes
The value range of the null hypothesis proportion \(p_0\) is determined by the alternative hypothesis proportion \(p\) and the non-inferiority margin \(\delta\).
If alternative is 'greater', that is, higher proportions are better, we have:
If alternative is 'less', that is, higher proportions are worse, we have:
To handle cases where the superiority margin is zero, the program computes the margin indirectly. It first calls solve_superiority_proportion to determine the superiority proportion \(p_{\text{sup}}\), and then calculates the margin \(\delta\) using the following formula: