Survival outcomes

Restricted Cox methods for right-censored outcomes.

fit_cox(durations, events, exposures, covariates=None, *, q=4, breaks=None, alpha=0.05, weights=None, offset=None, cluster_ids=None)

Fit a right-censored Cox model and sum exposure coefficients.

Durations must be positive, events must be zero or one, and inputs must be complete numeric arrays. Positive case weights enter the risk sets and event contributions. As in R's coxph default, fractional weights trigger a robust score-sandwich variance; integer weights use model-based variance. A finite offset gives one known log-hazard contribution per row. Exact integer cluster_ids group row scores for robust uncertainty; they do not change the fitted coefficients or exposure cuts. This subset has no formula. Shared event times use Efron's approximation. Its hazard ratio is conditional, not a marginal risk or survival contrast.

fit_cox_formula(formula, data, exposures, *, q=4, breaks=None, alpha=0.05, weights=None, cluster_ids=None, offset=None)

Fit a complete-data additive survival formula.

Write Surv(time,event) ~ exposure + C(adjustment). The two response columns must hold positive follow-up times and zero-one event indicators. Exposure terms must be plain numeric columns. C(name) is allowed for a text adjustment column, with the first sorted level as reference. weights, cluster_ids and known log-hazard offset are row vectors in the same order as data. Missing rows are not removed.

fit_cox_bootstrap(durations, events, exposures, covariates=None, *, q=4, breaks=None, alpha=0.05, degree=1, B=200, MCsize=None, seed=None)

Fit a marginal Cox curve with Monte Carlo events and row-bootstrap SE.

Parameters:
  • durations (Any) –

    Same complete, numeric right-censored inputs as :func:fit_cox.

  • events (Any) –

    Same complete, numeric right-censored inputs as :func:fit_cox.

  • exposures (Any) –

    Same complete, numeric right-censored inputs as :func:fit_cox.

  • covariates (Any) –

    Same complete, numeric right-censored inputs as :func:fit_cox.

  • q (int | None, default: 4 ) –

    Exposure scoring and confidence level as in :func:fit_cox.

  • breaks (int | None, default: 4 ) –

    Exposure scoring and confidence level as in :func:fit_cox.

  • alpha (int | None, default: 4 ) –

    Exposure scoring and confidence level as in :func:fit_cox.

  • degree ((1, 2), default: 1 ) –

    Polynomial degree of the joint intervention score in the marginal Cox model.

  • B (int, default: 200 ) –

    Number of independent row-bootstrap replicates, at least two.

  • MCsize (int, default: None ) –

    Simulated people per intervention level; at least the input row count. The default is max(input rows, 10000), as in R qgcomp 2.19.6.

  • seed (int, default: None ) –

    NumPy generator seed. Does not change the global random state.

Returns:
  • CoxBootstrapResult –

    Marginal curve coefficients and normal intervals based on bootstrap SD.

Notes

Event times are drawn by inverting the fitted cumulative hazard and are censored at the last observed follow-up time. R qgcomp 2.19.6 instead compares each hazard increment directly with a uniform draw and can produce missing times at its last support point. This intentional difference is recorded in the validation report. Independent censoring, proportional hazards, and causal identification require substantive assessment.

qgcomp_survcurve_boot(result)

Return marginal and conditional survival curves without uncertainty bands.

mdfq is the marginal model curve at each fitted joint intervention level. mdfpop averages those curves equally across levels. cdfpop averages conditional-model curves over all original adjustment profiles and levels. Following R's helper, cdfq holds each level's conditional curve for the first original adjustment profile, not its population average. The four tables may have different time grids: the marginal grid comes from simulated outcomes and the conditional grid from observed outcomes. No confidence bands are supplied.

For a prequantized fit, Python uses the actual pooled-quartile intervention levels saved by the bootstrap fit. R qgcomp 2.19.6 instead reconstructs zero-based integer levels from its saved breaks when q is NULL; the two displays can differ in that setting.