# NOT RUN {
require(JMcmprsk)
set.seed(123)
data(lung)
yread <- lung[, c(1,2:11)]
cread <- unique(lung[, c(1, 12, 13, 6:10)])
# }
# NOT RUN {
#Please note only those variables that will appear in the model can be included
res <- jmc(long_data = yread, surv_data = cread, out = "FVC",
FE = c("time", "FVC0", "FIB0", "CYC", "FVC0.CYC",
"FIB0.CYC", "time.CYC"),
RE = "linear", ID = "ID",cate = NULL, intcpt = 0,
quad.points = 8, quiet = FALSE)
# }
# NOT RUN {
#make up two categorical variables and add them into yread
sex <- sample(c("Female", "Male"), nrow(cread), replace = TRUE)
race <- sample(c("White", "Black", "Asian", "Hispanic"),
nrow(cread), replace = TRUE)
ID <- cread$ID
cate_var <- data.frame(ID, sex, race)
if (require(dplyr)) {
yread <- dplyr::left_join(yread, cate_var, by = "ID")
}
# }
# NOT RUN {
# run jmc function again for yread file with two added categorical variables
res2 <- jmc(long_data = yread, surv_data = cread,
out = "FVC", cate = c("sex", "race"),
FE = c("time", "FVC0", "FIB0", "CYC", "FVC0.CYC",
"FIB0.CYC", "time.CYC"),
RE = "time", ID = "ID", intcpt = 0,
quad.points = 8, quiet = FALSE)
res2
# Extract the parameter estimates of longitudinal sub-model fixed effects
beta <- coef(res2, coeff = "beta")
beta
## Linear hypothesis of testing all coefficients of beta's equal 0
linearTest(res2, coeff="beta")
## Linear hypothesis of testing beta1=beta2
## create a linear contrast for beta1=beta2 (intercept not included in Lb)
Lb <- matrix(c(1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0), ncol = length(beta)-1, nrow = 1)
linearTest(res2, coeff="beta", Lb = Lb)
# Extract the parameter estimates of survival sub-model fixed effects
gamma <- coef(res2, coeff = "gamma")
gamma
## Linear hypothesis of testing all coefficients of gamma's equal 0
linearTest(res2, coeff="gamma")
## Linear hypothesis of testing gamma11=gamma21
## (the coefficients of first covariate from
## both risk functions are equal)
Lg <- matrix(c(1, 0, 0, 0, 0, -1, 0, 0, 0, 0), ncol = length(gamma), nrow = 1)
linearTest(res2, coeff="gamma", Lg = Lg)
## Extract the standard errors for the longitudinal portion
summary(res2, coeff = "longitudinal", digits = 4)
## Extract the standard errors for the survival portion
summary(res2, coeff = "survival", digits = 4)
# }
Run the code above in your browser using DataLab