Hi,
I’m trying to run a survival model in “brms” with the attached dataset:
AustinCats <- read.csv("AustinCats.csv")
d <- AustinCats
rm(AustinCats)
d <-
d %>%
mutate(black = ifelse(color == "Black", "black", "other"))
d <-
d %>%
mutate(adopted = ifelse(out_event == "Adoption", 1, 0),
censored = ifelse(out_event != "Adoption", 1, 0))
model <-
brm(data = d,
family = exponential,
days_to_event | cens(censored) ~ 0 + black,
prior(normal(0, 1), class = b),
iter = 2000, warmup = 1000, chains = 4, cores = 4
)
The corresponding Stan code is:
stancode(model)
// generated with brms 2.15.0
functions {
}
data {
int<lower=1> N; // total number of observations
vector[N] Y; // response variable
int<lower=-1,upper=2> cens[N]; // indicates censoring
int<lower=1> K; // number of population-level effects
matrix[N, K] X; // population-level design matrix
int prior_only; // should the likelihood be ignored?
}
transformed data {
}
parameters {
vector[K] b; // population-level effects
}
transformed parameters {
}
model {
// likelihood including constants
if (!prior_only) {
// initialize linear predictor term
vector[N] mu = X * b;
for (n in 1:N) {
// apply the inverse link function
mu[n] = exp(-(mu[n]));
}
for (n in 1:N) {
// special treatment of censored data
if (cens[n] == 0) {
target += exponential_lpdf(Y[n] | mu[n]);
} else if (cens[n] == 1) {
target += exponential_lccdf(Y[n] | mu[n]);
} else if (cens[n] == -1) {
target += exponential_lcdf(Y[n] | mu[n]);
}
}
}
// priors including constants
target += normal_lpdf(b | 0, 1);
}
generated quantities {
}
My question concerns matrix[N, K] X; // population-level design matrix
:
- What is the X matrix for in the model?
- How do I build it so that I can reproduce the analysis using rstan?
Thanks