Clusters and survival

Examples use import kernelmix as km. See the tutorial for a complete analysis.

Structured model results

Task Method or helper
Exact alternative kernels kernel_matrix(Z1, Z2=None, r=None, *, kernel="gaussian", alpha=1)
Intercept/slope coefficient draws fit.random_effects(cluster_new=None, ...)
Gaussian residual variances fit.predict_residual_variance(Znew=None, variance_design_new=None, ...)
Cause-specific h and effect summaries fit.for_cause(cause)
Competing-risk probabilities fit.predict_cumulative_incidence(..., times=..., cause=None)
Time-varying predictor paths fit.predict_survival_path(..., start=..., stop=..., subject_new=..., times=...)

StructuredFit retains the shared summary, sample, diagnostic, contrast and save/load methods. RandomCoefficientPrediction stores coefficient draws; CompetingRiskPrediction.for_cause(k) returns a curve accepted by plot_survival. Additional inputs, initialization shapes and runnable examples are in the structured guide.

Cluster and survival results

fit.random_intercepts(cluster_new=None, *, probability=.95, max_draws=None, seed=None)
fit.predict_survival(
    Znew=None, Xnew=None, *, times, kind="survival", cluster_new=None,
    probability=.95, max_draws=None, seed=None,
)
km.plot_survival(prediction, row=0, ax=None)

random_intercepts returns a Prediction in training-cluster order, or in the supplied label order. The prediction rules for known and new clusters are described below.

Survival result Meaning
times Finite, nonnegative, strictly increasing prediction times
draws Array with axes (chain, draw, row, time)
mean, sd, lower, upper Arrays shaped (row, time)
probability, kind Interval probability and survival/hazard scale
to_records() One summary per profile/time pair

kind="hazard" evaluates hazards on the grid. Plots use survival curves or hazard points with intervals; they do not invent hazard steps between times.

predict additionally accepts offset=None and cluster_new=None. For training count prediction, omitted offsets reuse retained offsets. For new rows, offsets are required if they were supplied during fitting. Response-scale count observations are Poisson or NB2 draws. Latent count observations and survival observation draws are unsupported and raise an error.

Omitted cluster_new sets random effects to zero, including for training predictions. Known labels use their fitted cluster coefficients; unseen labels receive new Gaussian coefficients. Equal labels share a draw. predict_h excludes random effects. For slopes and residual conditioning, see structured prediction. Default Gaussian/probit prediction samples h + u jointly when labels are supplied, preserving posterior covariance.

For the default count/survival route, samples include h and auxiliary latent_white; negative-binomial fits also include dispersion; survival fits include baseline_hazard. Default-route clustered fits include lambda_cluster, and count/survival fits also retain u. Default Gaussian/probit fits integrate out random intercepts during parameter sampling; random_intercepts draws them conditionally afterward. Count/survival fits store sigma2=1 for a consistent result format. It is not an estimated residual variance and is omitted from their summaries. Saved white coordinates are internal standardized sampling variables tied to a matrix decomposition. Use saved h for prediction that can be transferred across platforms.