Skip to content

Linear relative rate / excess relative risk models

1 message · Wollschlaeger, Daniel

#
A while ago, I inquired about fitting excess relative risk models in R. This is a follow-up about what I ended up doing in case the question pops up again.

While I was not successful in using standard tools, switching to Bayesian modeling using rstan (mc-stan.org/rstan.html) worked better. The results closely match those from Epicure.

Using the data here: http://dwoll.de/err/dat.txt
The stan model fit below replicates the results from Epicure here: http://dwoll.de/err/epicure.log

Of course I am still interested in learning about other options or approaches.

Daniel

##-------
## rstan code for fitting an excess relative risk model with linear dose-response
## events = personYears * exp(beta0 + beta1*age + beta2*sex) * (1 +beta3*dose)

dat_code <- '
data {
    int<lower=0> N;
    vector[N] pyears;
    vector[N] age;
    vector[N] sex;
    vector[N] dose;
    int<lower=0> event[N];
}
transformed data {
    vector[N] log_pyears;
    log_pyears <- log(pyears);
}
parameters {
    vector[2] beta;
    real beta0;              # baseline intercept param
    real<lower=0> betaD;     # dose param -> non-negative
}
model {
    # beta0 unspecified -> uniform prior (improper)
    beta  ~ normal(0, 100);  # flat normal prior for params
    betaD ~ cauchy(0, 2.5);  # ok even if not truncated, cf. stan reference
    event ~ poisson_log(log_pyears + beta0 + beta[1]*age + beta[2]*sex +
                        log(1 + betaD*dose));
}
'

library(rstan)
stan_dat <- with(dat,
                 list(pyears=pyears,
                      age=age,
                      sex=sex,
                      N=length(pyears),
                      event=event,
                      dose=dose))

stanFit <- stan(model_code=dat_code, data=stan_dat,
                thin=5, iter=10000, chains=2)

traceplot(stanFit)
stanFit

-----Original Message-----
From: Wollschlaeger, Daniel 
Sent: Thursday, January 9, 2014 10:44 AM
To: David Winsemius
Cc: r-help at r-project.org
Subject: RE: AW: [R] Linear relative rate / excess relative risk models

Thanks for your suggestions! Here are links to simulated data and the Epicure syntax + reference fit:
http://dwoll.de/err/dat.txt
http://dwoll.de/err/epicure.log

The model tested in Epicure is

lambda = exp(alpha0 + alpha1*agePyr)*(1 + beta0*dosePyr*exp(beta1*agePyr))

with counts in variable event and offset pyears.

Many thanks, D