Skip to content

Pathobject

This class holds all necessary attributes of a single path for the multi state model.

Parameters:

Name Type Description Default
covariates Series

Named pandas Series of sample covariates at the initial state. Defaults to None.

None
states List[int]

States visited (encoded as positive integers, 0 is saved for censoring), in the order visited. Defaults to None.

None
time_at_each_state List[float]

Time at each state. Defaults to None.

None
sample_id int

An identification of this sample. Defaults to None.

None
weight float

Sample weight. Defaults to None.

None

Note

If the last state is a terminal state, then the vector of times should be shorter than the vector of states by 1. Conversely, if the last state is not a terminal state, then the length of vector times should be the same as that of the states.

Source code in pymsm/multi_state_competing_risks_model.py
class PathObject:
    """This class holds all necessary attributes of a single path for the multi state model.

    Args:
        covariates (Series, optional): Named pandas Series of sample covariates at the initial state. Defaults to None.
        states (List[int], optional): States visited (encoded as positive integers, 0 is saved for censoring), in the order visited. Defaults to None.
        time_at_each_state (List[float], optional): Time at each state. Defaults to None.
        sample_id (int, optional): An identification of this sample. Defaults to None.
        weight (float, optional): Sample weight. Defaults to None.

    Note:
        If the last state is a terminal state, then the vector of times should be shorter than the vector of
        states by 1. Conversely, if the last state is not a terminal state, then the length of vector times should be
        the same as that of the states.

    """

    def __init__(
        self,
        covariates: Series = None,
        states: List[int] = None,
        time_at_each_state: List[float] = None,
        sample_id: int = None,
        weight: float = None,
    ):

        self.covariates = covariates
        self.states = list() if states is None else states
        self.time_at_each_state = (
            list() if time_at_each_state is None else time_at_each_state
        )
        self.sample_id = sample_id
        self.sample_weight = weight
        # This variable is used when simulating paths using monte carlo
        self.stopped_early = None

    def print_path(self):
        """Helper function for printing the paths of a Monte Carlo simulation"""
        if self.sample_id is not None:
            print(f"Sample id: {self.sample_id}")
        print(f"States: {self.states}")
        print(f"Transition times: {self.time_at_each_state}")
        if self.covariates is not None:
            print(f"Covariates:\n{self.covariates}")

print_path(self) ยค

Helper function for printing the paths of a Monte Carlo simulation

Source code in pymsm/multi_state_competing_risks_model.py
def print_path(self):
    """Helper function for printing the paths of a Monte Carlo simulation"""
    if self.sample_id is not None:
        print(f"Sample id: {self.sample_id}")
    print(f"States: {self.states}")
    print(f"Transition times: {self.time_at_each_state}")
    if self.covariates is not None:
        print(f"Covariates:\n{self.covariates}")