Censoring¶
Censoring-time samplers and the bivariate draw used by TDCM.
Only runifcens and rexpocens are wired into the generators through
model_cens; the rest are standalone. See the
Censoring guide for how to apply them.
Censoring times¶
censoring
¶
CensoringFunc
¶
Bases: Protocol
Protocol for censoring time generators.
CensoringModel
¶
Bases: Protocol
Protocol for class-based censoring generators.
WeibullCensoring
¶
Class-based generator for Weibull censoring times.
Store Weibull scale and shape parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
float
|
Scale parameter of the Weibull distribution. |
required |
shape
|
float
|
Shape parameter of the Weibull distribution. |
required |
Source code in gen_surv/censoring.py
LogNormalCensoring
¶
Class-based generator for log-normal censoring times.
Store log-normal parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean
|
float
|
Mean of the underlying normal distribution. |
required |
sigma
|
float
|
Standard deviation of the underlying normal distribution. |
required |
Source code in gen_surv/censoring.py
GammaCensoring
¶
Class-based generator for Gamma censoring times.
Store Gamma distribution parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
float
|
Shape parameter of the Gamma distribution. |
required |
scale
|
float
|
Scale parameter of the Gamma distribution. |
required |
Source code in gen_surv/censoring.py
runifcens
¶
Generate uniform censoring times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Number of samples. |
required |
cens_par
|
float
|
Upper bound for the uniform distribution. |
required |
rng
|
Generator
|
Random number generator to use. If |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Array of censoring times. |
Source code in gen_surv/censoring.py
rexpocens
¶
Generate exponential censoring times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Number of samples. |
required |
cens_par
|
float
|
Mean of the exponential distribution. |
required |
rng
|
Generator
|
Random number generator to use. If |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Array of censoring times. |
Source code in gen_surv/censoring.py
rweibcens
¶
rweibcens(
size: int,
scale: float,
shape: float,
rng: Generator | None = None,
) -> NDArray[float64]
Generate Weibull-distributed censoring times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Number of samples. |
required |
scale
|
float
|
Scale parameter of the Weibull distribution. |
required |
shape
|
float
|
Shape parameter of the Weibull distribution. |
required |
rng
|
Generator
|
Random number generator to use. If |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Array of censoring times. |
Source code in gen_surv/censoring.py
rlognormcens
¶
rlognormcens(
size: int,
mean: float,
sigma: float,
rng: Generator | None = None,
) -> NDArray[float64]
Generate log-normal-distributed censoring times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Number of samples. |
required |
mean
|
float
|
Mean of the underlying normal distribution. |
required |
sigma
|
float
|
Standard deviation of the underlying normal distribution. |
required |
rng
|
Generator
|
Random number generator to use. If |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Array of censoring times. |
Source code in gen_surv/censoring.py
rgammacens
¶
rgammacens(
size: int,
shape: float,
scale: float,
rng: Generator | None = None,
) -> NDArray[float64]
Generate Gamma-distributed censoring times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Number of samples. |
required |
shape
|
float
|
Shape parameter of the Gamma distribution. |
required |
scale
|
float
|
Scale parameter of the Gamma distribution. |
required |
rng
|
Generator
|
Random number generator to use. If |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Array of censoring times. |
Source code in gen_surv/censoring.py
Bivariate sampling¶
bivariate
¶
sample_bivariate_distribution
¶
sample_bivariate_distribution(
n: int,
dist: str,
corr: float,
dist_par: Sequence[float],
seed: RandomStateLike = None,
) -> NDArray[float64]
Draw dependent samples with Weibull or exponential marginals.
Dependence is induced with a Gaussian copula: a pair of correlated standard normals is mapped to uniforms through the normal CDF, and those uniforms are pushed through the inverse marginal CDFs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of samples to generate. |
required |
dist
|
(weibull, exponential)
|
Type of marginal distributions. |
"weibull"
|
corr
|
float
|
Correlation of the underlying normals, in |
required |
dist_par
|
Sequence[float]
|
Distribution parameters |
required |
seed
|
int or Generator
|
Seed or generator for reproducibility. |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Array of shape |
Examples:
>>> from gen_surv.bivariate import sample_bivariate_distribution
>>> sample_bivariate_distribution(
... 3,
... "weibull",
... 0.3,
... [1.0, 2.0, 1.5, 2.5],
... seed=42,
... )
array([[...], [...], [...]])
Raises:
| Type | Description |
|---|---|
ValidationError
|
If |