Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behaviour of Regression fit when lifetime data order changes #18

Open
21ch216 opened this issue Dec 12, 2024 · 0 comments
Open
Assignees

Comments

@21ch216
Copy link
Collaborator

21ch216 commented Dec 12, 2024

This affects the branch refactoring

Here is a sample code to reproduce the issue :

time, event, entry, *covar = load_insulator_string()
covar = np.column_stack(covar)
ph = ProportionalHazard(Gompertz()).fit(time, event, entry, model_args=(covar,))

Then if in utils.data, IndexedData.union is like :

def union(*others: Self) -> Self:
    return IndexedData(
        np.concatenate(
            [other.values for other in others],
            axis=0,
        ),
        np.concatenate([other.index for other in others]),
    )

the estimation of the parameters fails, the log-likelihood diverges in the optimization steps. After some inspections, I figured out that the values stored in lifetime_data.rc where the same than those in data._time.D_RC but in a different order. Thus, after reordering index and values created in union below, the error has disappeared. Here is the union working fine :

def union(*others: Self) -> Self:
    values = np.concatenate(
        [other.values for other in others],
        axis=0,
    )
    index = np.concatenate([other.index for other in others])
    sort_ind = np.argsort(
        index
    )
    return IndexedData(values[sort_ind], index[sort_ind])

why does the order of values matter ? is it due to scipy operations ? is the fault of np.concatenate ?

@21ch216 21ch216 self-assigned this Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant