# 1) Fit on simulated bivariate data, (1x gaussian, 1x poisson) --------
beta <- do.call(rbind, replicate(2, c(2, -0.1, 0.1, -0.2), simplify = FALSE))
gamma <- c(0.3, -0.3)
D <- diag(c(0.25, 0.09, 0.25, 0.05))
family <- list('gaussian', 'poisson')
data <- simData(ntms = 10, beta = beta, D = D, n = 100,
family = family, zeta = c(0, -0.2),
sigma = list(0.16, 0), gamma = gamma)$data
# Specify formulae and target families
long.formulas <- list(
Y.1 ~ time + cont + bin + (1 + time|id), # Gaussian
Y.2 ~ time + cont + bin + (1 + time|id) # Poisson
)
surv.formula <- Surv(survtime, status) ~ bin
fit <- joint(long.formulas, surv.formula, data, family)
# \donttest{
# 2) Fit on PBC data -----------------------------------------------------
data(PBC)
# Subset data and remove NAs
PBC <- subset(PBC, select = c('id', 'survtime', 'status', 'drug', 'time',
'serBilir', 'albumin', 'spiders', 'platelets'))
PBC <- na.omit(PBC)
# Specify GLMM sub-models, including interaction and quadratic time terms
long.formulas <- list(
log(serBilir) ~ drug * (time + I(time^2)) + (1 + time + I(time^2)|id),
albumin ~ drug * time + (1 + time|id),
platelets ~ drug * time + (1 + time|id),
spiders ~ drug * time + (1|id)
)
surv.formula <- Surv(survtime, status) ~ drug
fit <- joint(long.formulas, surv.formula, PBC,
family = list("gaussian", "gaussian", "poisson", "binomial"),
control = list(verbose = TRUE))
fit
# }
# \donttest{
# 3) Fit with dispersion models ----------------------------------------
beta <- do.call(rbind, replicate(2, c(2, -0.1, 0.1, -0.2), simplify = FALSE))
gamma <- c(0.3, -0.3)
D <- diag(c(0.25, 0.09, 0.25, 0.05))
family <- list('negbin', 'poisson') # As an example; only requires one dispersion model.
sigma <- list(c(1, 0.2), 0) # Need to specify the model in simData call too.
disp.formulas = list(~time, ~1) # Even though poisson doesn't model dispersion, need to
# populate this element in disp.formulas!
# Simulate some data
data <- simData(ntms = 10, beta = beta, D = D, n = 500,
family = family, zeta = c(0, -0.2), sigma = sigma,
disp.formulas = disp.formulas, gamma = gamma)$data
# Now fit using joint
long.formulas <- list(
Y.1 ~ time + cont + bin + (1+time|id),
Y.2 ~ time + cont + bin + (1+time|id)
)
fit <- joint(
long.formulas, Surv(survtime, status) ~ bin,
data, family, disp.formulas = disp.formulas
)
fit
summary(fit)
# }
Run the code above in your browser using DataLab