module documentation

Module for functions to predict the risk of lymphatic progression.

The code in this module is utilized by the views.render_risk_prediction and views.render_risk_prediction functions of the riskpredictor app to compute the risk of lymphatic progression for a given diagnosis.

Function assemble_diagnosis Create a DiagnosisConfig object from the cleaned form data.
Function collect_risk_stats For an array of risk_values, collect the mean and std for each risk type.
Function compute_posteriors Compute the posterior state dists for the given model, priors, and diagnosis.
Function compute_risks Compute the risks for the given checkpoint and form data.
Function create_risks_fields_and_kwargs Create the fields and kwargs for dynamically created pydantic Risks model.
Type Variable BaseModelT Undocumented
Variable logger Undocumented
Variable NullableBoolPercents Keys may be True, False, or None, while values are the counts of each.
def assemble_diagnosis(form_data: dict[str, Any], lnls: list[str], modality: str = 'D') -> DiagnosisConfig:

Create a DiagnosisConfig object from the cleaned form data.

def collect_risk_stats(risk_values: np.ndarray) -> dict[Literal[True, None, False], float]:

For an array of risk_values, collect the mean and std for each risk type.

The format is chosen like the lyprox.dataexplorer.query.Statistics object that collects how many patients had True, None, or False involvement for a given LNL. In this case, we construct the returned dictionary like this:

{
    True: 26.3,   # Risk of involvement minus half the standard deviation
    None: 5.2,    # The standard deviation of the risk
    False: 68.5,  # Remaining number to sum to 100
}

This format is compatible with the lyprox.dataexplorer.query.Statistics object and thus also with the HTML templates used in the dataexplorer app.

def compute_posteriors(model: Model, priors: np.ndarray, diagnosis: DiagnosisConfig, midext: bool | None = None, specificity: float = 0.9, sensitivity: float = 0.9) -> np.ndarray:

Compute the posterior state dists for the given model, priors, and diagnosis.

def compute_risks(checkpoint: CheckpointModel, form_data: dict[str, Any], lnls: list[str]) -> BaseModelT:

Compute the risks for the given checkpoint and form data.

Returns an instance of a dynamically created pydantic BaseModel class that has fields like ipsi_II or contra_III. In these fields, it stores the risk in dictionaries returned by the collect_risk_stats function.

def create_risks_fields_and_kwargs(model: Model, state_dists: np.ndarray, lnls: list[str], keys_to_consider: Container[str]) -> tuple[dict[str, tuple[type, ...]], dict[str, dict]]:

Create the fields and kwargs for dynamically created pydantic Risks model.

BaseModelT =

Undocumented

Value
TypeVar('BaseModelT',
        bound=BaseModel)
logger =

Undocumented

NullableBoolPercents =

Keys may be True, False, or None, while values are the counts of each.