agentsclimarketplace

Survival models

Skill choxos/BiostatAgent/plugins/bayesian-modeling/skills/survival-models

Claude Code plugin marketplace for biostatistics in R — 30 agents, 17 commands, and 45 skills spanning Bayesian modeling (Stan/PyMC/JAGS), indirect treatment comparisons (NMA/MAIC/STC/ML-NMR), tidy R workflows, and clinical trial simulation.

Install
npx -y skills add choxos/BiostatAgent --skill survival-models

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 8 stars8 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Bayesian survival analysis models including exponential, Weibull, log-normal, and piecewise exponential hazard models with censoring support.

SKILL.md

4.1 KB, as published. Nobody here has run it

Survival Models

Data Structure

data {
  int<lower=0> N;
  vector<lower=0>[N] time;      // Observed/censored time
  array[N] int<lower=0,upper=1> event;  // 1=event, 0=censored
  matrix[N, K] X;               // Covariates
}

Exponential Model

Stan

parameters {
  real alpha;           // Log baseline hazard
  vector[K] beta;
}
model {
  alpha ~ normal(0, 2);
  beta ~ normal(0, 1);

  for (n in 1:N) {
    real lambda = exp(alpha + X[n] * beta);
    if (event[n] == 1)
      target += exponential_lpdf(time[n] | lambda);
    else
      target += exponential_lccdf(time[n] | lambda);  // Survival
  }
}

JAGS (with censoring)

model {
  for (i in 1:N) {
    is.censored[i] ~ dinterval(t[i], t.cen[i])
    t[i] ~ dexp(lambda[i])
    log(lambda[i]) <- alpha + inprod(X[i,], beta[])
  }
  alpha ~ dnorm(0, 0.25)
  for (k in 1:K) { beta[k] ~ dnorm(0, 1) }
}

Weibull Model

Stan (AFT Parameterization)

parameters {
  real alpha;                    // Intercept (log scale)
  vector[K] beta;
  real<lower=0> shape;           // Weibull shape
}
model {
  alpha ~ normal(0, 5);
  beta ~ normal(0, 2);
  shape ~ exponential(1);

  for (n in 1:N) {
    real mu = alpha + X[n] * beta;
    if (event[n] == 1)
      target += weibull_lpdf(time[n] | shape, exp(mu));
    else
      target += weibull_lccdf(time[n] | shape, exp(mu));
  }
}

JAGS

model {
  for (i in 1:N) {
    is.censored[i] ~ dinterval(t[i], t.cen[i])
    t[i] ~ dweib(shape, lambda[i])
    log(lambda[i]) <- alpha + inprod(X[i,], beta[])
  }
  shape ~ dgamma(1, 0.001)
  alpha ~ dnorm(0, 0.01)
  for (k in 1:K) { beta[k] ~ dnorm(0, 0.01) }
}

Log-Normal Model

Stan

parameters {
  real alpha;
  vector[K] beta;
  real<lower=0> sigma;
}
model {
  for (n in 1:N) {
    real mu = alpha + X[n] * beta;
    if (event[n] == 1)
      target += lognormal_lpdf(time[n] | mu, sigma);
    else
      target += lognormal_lccdf(time[n] | mu, sigma);
  }
}

Piecewise Exponential (Cox-like)

Stan

data {
  int<lower=0> N;
  int<lower=0> J;               // Number of intervals
  vector[J] cuts;               // Cut points
  matrix[N, J] d;               // Time in each interval
  array[N] int<lower=0,upper=1> event;
  array[N] int<lower=1,upper=J> interval;  // Event interval
  matrix[N, K] X;
}
parameters {
  vector[J] log_baseline;       // Log baseline hazard per interval
  vector[K] beta;
}
model {
  log_baseline ~ normal(0, 2);
  beta ~ normal(0, 1);

  for (n in 1:N) {
    real log_hazard = log_baseline[interval[n]] + X[n] * beta;

    // Contribution from all intervals
    for (j in 1:J)
      target += -d[n,j] * exp(log_baseline[j] + X[n] * beta);

    // Event contribution
    if (event[n] == 1)
      target += log_hazard;
  }
}

Frailty Model (Random Effects)

Stan

data {
  int<lower=0> N;
  int<lower=0> G;               // Number of groups
  array[N] int<lower=1,upper=G> group;
  // ... rest of survival data
}
parameters {
  real alpha;
  vector[K] beta;
  real<lower=0> shape;
  vector[G] frailty_raw;        // Non-centered
  real<lower=0> sigma_frailty;
}
transformed parameters {
  vector[G] frailty = sigma_frailty * frailty_raw;
}
model {
  sigma_frailty ~ exponential(1);
  frailty_raw ~ std_normal();

  for (n in 1:N) {
    real mu = alpha + X[n] * beta + frailty[group[n]];
    // ... Weibull likelihood with censoring
  }
}

Generated Quantities

generated quantities {
  // Hazard ratio for 1-unit increase in X[,1]
  real HR = exp(beta[1]);

  // Median survival at X=0
  real median_survival = exp(alpha) * pow(log(2), 1/shape);

  // Survival function at time t=1
  array[N] real S_1;
  for (n in 1:N)
    S_1[n] = exp(-pow(1 / exp(alpha + X[n] * beta), shape));
}

Interpretation

  • Weibull shape: <1 decreasing hazard, =1 constant (exponential), >1 increasing
  • HR: Hazard ratio (multiplicative effect on hazard)
  • AFT: Accelerated failure time (multiplicative effect on survival time)

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.