-
Notifications
You must be signed in to change notification settings - Fork 0
docs: add usage examples for all models in index.md #21
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import sys | ||
| import os | ||
| sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | ||
| from gen_surv.interface import generate | ||
|
|
||
| # Generate synthetic survival data using Log-Normal AFT model | ||
| df = generate( | ||
| model="aft_ln", | ||
| n=100, | ||
| beta=[0.5, -0.3], | ||
| sigma=1.0, | ||
| model_cens="exponential", | ||
| cens_par=3.0, | ||
| seed=123 | ||
| ) | ||
|
|
||
| print(df.head()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import sys | ||
| import os | ||
| sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | ||
|
|
||
| from gen_surv import generate | ||
|
|
||
| df = generate( | ||
| model="cmm", | ||
| n=100, | ||
| model_cens="exponential", | ||
| cens_par=2.0, | ||
| qmat=[[0, 0.1], [0.05, 0]], | ||
| p0=[1.0, 0.0], | ||
| seed=42 | ||
| ) | ||
|
|
||
| print(df.head()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import sys | ||
| import os | ||
| sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | ||
|
|
||
| from gen_surv import generate | ||
|
|
||
| df = generate( | ||
| model="cphm", | ||
| n=100, | ||
| model_cens="uniform", | ||
| cens_par=1.0, | ||
| beta=0.5, | ||
| covar=2.0, | ||
| seed=42 | ||
| ) | ||
|
|
||
| print(df.head()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import sys | ||
| import os | ||
| sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | ||
|
|
||
| from gen_surv import generate | ||
|
|
||
| df = generate( | ||
| model="tdcm", | ||
| n=100, | ||
| dist="weibull", | ||
| corr=0.5, | ||
| dist_par=[1, 2, 1, 2], | ||
| model_cens="uniform", | ||
| cens_par=1.0, | ||
| beta=[0.1, 0.2, 0.3], | ||
| lam=1.0, | ||
| seed=42 | ||
| ) | ||
|
|
||
| print(df.head()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import sys | ||
| import os | ||
| sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | ||
|
|
||
| from gen_surv import generate | ||
|
|
||
| df = generate( | ||
| model="thmm", | ||
| n=100, | ||
| qmat=[[0, 0.2, 0], [0.1, 0, 0.1], [0, 0.3, 0]], | ||
| emission_pars={"mu": [0.0, 1.0, 2.0], "sigma": [0.5, 0.5, 0.5]}, | ||
| p0=[1.0, 0.0, 0.0], | ||
| model_cens="exponential", | ||
| cens_par=3.0, | ||
| seed=42 | ||
| ) | ||
|
|
||
| print(df.head()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .interface import generate as generate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from _typeshed import Incomplete | ||
|
|
||
| def gen_aft_log_normal(n, beta, sigma, model_cens, cens_par, seed: Incomplete | None = None): ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| def sample_bivariate_distribution(n, dist, corr, dist_par): ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import numpy as np | ||
|
|
||
| def runifcens(size: int, cens_par: float) -> np.ndarray: ... | ||
| def rexpocens(size: int, cens_par: float) -> np.ndarray: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from gen_surv.censoring import rexpocens as rexpocens, runifcens as runifcens | ||
| from gen_surv.validate import validate_gen_cmm_inputs as validate_gen_cmm_inputs | ||
|
|
||
| def generate_event_times(z1: float, beta: list, rate: list) -> dict: ... | ||
| def gen_cmm(n, model_cens, cens_par, beta, covar, rate): ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import pandas as pd | ||
| from gen_surv.censoring import rexpocens as rexpocens, runifcens as runifcens | ||
| from gen_surv.validate import validate_gen_cphm_inputs as validate_gen_cphm_inputs | ||
|
|
||
| def generate_cphm_data(n, rfunc, cens_par, beta, covariate_range): ... | ||
| def gen_cphm(n: int, model_cens: str, cens_par: float, beta: float, covar: float) -> pd.DataFrame: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from gen_surv.aft import gen_aft_log_normal as gen_aft_log_normal | ||
| from gen_surv.cmm import gen_cmm as gen_cmm | ||
| from gen_surv.cphm import gen_cphm as gen_cphm | ||
| from gen_surv.tdcm import gen_tdcm as gen_tdcm | ||
| from gen_surv.thmm import gen_thmm as gen_thmm | ||
|
|
||
| def generate(model: str, **kwargs): ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| from gen_surv.bivariate import sample_bivariate_distribution as sample_bivariate_distribution | ||
| from gen_surv.censoring import rexpocens as rexpocens, runifcens as runifcens | ||
| from gen_surv.validate import validate_gen_tdcm_inputs as validate_gen_tdcm_inputs | ||
|
|
||
| def generate_censored_observations(n, dist_par, model_cens, cens_par, beta, lam, b): ... | ||
| def gen_tdcm(n, dist, corr, dist_par, model_cens, cens_par, beta, lam): ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from gen_surv.censoring import rexpocens as rexpocens, runifcens as runifcens | ||
| from gen_surv.validate import validate_gen_thmm_inputs as validate_gen_thmm_inputs | ||
|
|
||
| def calculate_transitions(z1: float, cens_par: float, beta: list, rate: list, rfunc) -> dict: ... | ||
| def gen_thmm(n, model_cens, cens_par, beta, covar, rate): ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| def validate_gen_cphm_inputs(n: int, model_cens: str, cens_par: float, covar: float): ... | ||
| def validate_gen_cmm_inputs(n: int, model_cens: str, cens_par: float, beta: list, covar: float, rate: list): ... | ||
| def validate_gen_tdcm_inputs(n: int, dist: str, corr: float, dist_par: list, model_cens: str, cens_par: float, beta: list, lam: float): ... | ||
| def validate_gen_thmm_inputs(n: int, model_cens: str, cens_par: float, beta: list, covar: float, rate: list): ... | ||
| def validate_dg_biv_inputs(n: int, dist: str, corr: float, dist_par: list): ... | ||
| def validate_gen_aft_log_normal_inputs(n, beta, sigma, model_cens, cens_par) -> None: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import pandas as pd | ||
| from gen_surv.aft import gen_aft_log_normal | ||
|
|
||
| def test_gen_aft_log_normal_runs(): | ||
| df = gen_aft_log_normal( | ||
| n=10, | ||
| beta=[0.5, -0.2], | ||
| sigma=1.0, | ||
| model_cens="uniform", | ||
| cens_par=5.0, | ||
| seed=42 | ||
| ) | ||
| assert isinstance(df, pd.DataFrame) | ||
| assert not df.empty | ||
| assert "time" in df.columns | ||
| assert "status" in df.columns | ||
| assert "X0" in df.columns | ||
| assert "X1" in df.columns | ||
| assert set(df["status"].unique()).issubset({0, 1}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.