跳转至

pystatpower.correlation.ci

Functions:

Name Description
solve_distance

Calculate the correlation coefficient confidence interval width or the distance from the correlation coefficient to the confidence bound

solve_size

Estimate the required sample size, given the correlation coefficient confidence interval width or the distance from the correlation coefficient to the confidence bound

solve_correlation

Estimate the required correlation coefficient, given the correlation coefficient confidence interval width or the distance from the correlation coefficient to the confidence bound

solve_distance

solve_distance(
    *,
    correlation: float,
    size: int,
    conf_level: float = 0.95,
    interval_type: Literal[
        "two-sided", "lower", "upper"
    ] = "two-sided",
    bias_adj: bool = False,
) -> float

Calculate the correlation coefficient confidence interval width or the distance from the correlation coefficient to the confidence bound

Parameters:

Name Type Description Default
correlation float

Actual correlation coefficient (\(r\)). Must be between -1 and 1.

required
size int

Sample size \(n\).

required
conf_level float

Condidence level.

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

Type of the confidence interval.

  • 'two-sided': Two-sided confidence interval.
  • 'lower': Lower one-sided confidence interval.
  • 'upper': Upper one-sided confidence interval.
'two-sided'
bias_adj bool

Whether to adjust for bias.

False

Returns:

Type Description
float

The correlation coefficient confidence interval width or the distance from the correlation coefficient to the confidence bound.

solve_size

solve_size(
    *,
    correlation: float,
    distance: float,
    conf_level: float = 0.95,
    interval_type: Literal[
        "two-sided", "lower", "upper"
    ] = "two-sided",
    bias_adj: bool = False,
) -> int

Estimate the required sample size, given the correlation coefficient confidence interval width or the distance from the correlation coefficient to the confidence bound

Parameters:

Name Type Description Default
correlation float

Actual correlation coefficient (\(r\)). Must be between -1 and 1.

required
distance float

Correlation coefficient confidence interval width or the distance from the correlation coefficient to the confidence bound.

  • If interval_type = 'two-sided', specify the correlation coefficient two-sided confidence interval width.
  • If interval_type = 'lower', specify the distance from the correlation coefficient to the lower one-sided confidence bound.
  • If interval_type = 'upper', specify the distance from the correlation coefficient to the upper one-sided confidence bound.
required
conf_level float

Condidence level.

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

Type of the confidence interval.

  • 'two-sided': Two-sided confidence interval.
  • 'lower': Lower one-sided confidence interval.
  • 'upper': Upper one-sided confidence interval.
'two-sided'
bias_adj bool

Whether to adjust for bias.

False

Returns:

Type Description
float

The required sample size \(n\).

solve_correlation

solve_correlation(
    *,
    distance: float,
    size: int,
    conf_level: float = 0.95,
    interval_type: Literal[
        "two-sided", "lower", "upper"
    ] = "two-sided",
    bias_adj: bool = False,
) -> float | tuple[float, float]

Estimate the required correlation coefficient, given the correlation coefficient confidence interval width or the distance from the correlation coefficient to the confidence bound

Parameters:

Name Type Description Default
distance float

Correlation coefficient confidence interval width or the distance from the correlation coefficient to the confidence bound.

  • If interval_type = 'two-sided', specify the correlation coefficient two-sided confidence interval width.
  • If interval_type = 'lower', specify the distance from the correlation coefficient to the lower one-sided confidence bound.
  • If interval_type = 'upper', specify the distance from the correlation coefficient to the upper one-sided confidence bound.
required
size int

Sample size \(n\).

required
conf_level float

Condidence level.

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

Type of the confidence interval.

  • 'two-sided': Two-sided confidence interval.
  • 'lower': Lower one-sided confidence interval.
  • 'upper': Upper one-sided confidence interval.
'two-sided'
bias_adj bool

Whether to adjust for bias.

False

Returns:

Type Description
float | tuple[float, float]

The required correlation coefficient \(r\), or a tuple of correlation coefficient if two solutions found. Note that this function only returns positive correlation coefficient.