I would to ask you if it is possible to use a logistic distribution in an AFT model with brm… l can’t find a suitable function in the manual… @paul.buerkner
library(brms)
library(survival)
data=veteran
model <- brm(time | cens(1-status) ~ factor(trt),
data = data,
family = xxxxx () )
Thanks.
It is challenging for me. I have tried this, but the result does not seem to much flexsurv.
Can anybody tell me how to fix this stan code to get the logistic distribution please?
library(survival)
library(brms)
data= veteran
stan_code <- "
real my_logistic_lpdf(real y, real mu, real sigma) {
return -log(sigma) - 2*log1p_exp((y - mu) / sigma) - ((y - mu) / sigma);
}
real my_logistic_lcdf(real y, real mu, real sigma) {
return -log1p_exp(-(y - mu) / sigma);
}
real my_logistic_lccdf(real y, real mu, real sigma) {
return log1p_exp(-(y - mu) / sigma);
}
"
custom_stan_funs <- stanvar(scode = stan_code, block = "functions")
logistic_family <- custom_family(
"my_logistic",
dpars = c("mu", "sigma"),
links = c("identity", "log"),
lb = c(NA, 0),
type = "real"
)
custom_stan_funs <- stanvar(scode = stan_code, block = "functions")
aft_model <- brm(
formula = time | cens(1 - status) ~ trt,
data = data,
family = logistic_family,
stanvars = custom_stan_funs,
chains = 1,
iter = 1000,
seed = 42
)
library(flexsurv)
flexsurv_model <- flexsurvreg(
Surv(time, status) ~ trt,
data = data,
dist = "llogis"
)