/usr/lib/R/site-library/multcomp/multcomp_coxme.R is in r-cran-multcomp 1.4-8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | library("coxme")
library("multcomp")
#######################################################
### Source code for simulations presented in
### Dunnett-type inference in the frailty Cox model
### with covariates
### by E. Herberich and T. Hothorn
### Statistics in Medicine 2010
#######################################################
###############################################
# Simulation setup for balanced design
###############################################
#####################################################################################
### Data generating process of the covariates X and cluster centr
### n: total number of observations
### ncenter: number of centers
#####################################################################################
dgpX <- function(n, ncenter){
x1 <- rep(gl(3, n/(3*ncenter)), ncenter)
x2 <- sample(gl(2, n / 2), replace=FALSE)
x3 <- runif(n, 18, 65)
x4 <- sample(gl(3, n / 3), replace=FALSE)
X <- data.frame(X1 = x1, X2 = x2, X3 = x3, X4 = x4)
return(X)
}
dgpZ <- function(n, ncenter){
centr <- gl(ncenter, n/ncenter)
}
#####################################################################################
### Data generating process in the frailty Cox model with Weibull distributed
### survival and normally distributed random effect
### n: total number of observations
### beta: vector of effects of treatments and other covariates
### lambda, nu: scale and shape parameter of the Weibull distribution
### mu: parameter of the exponential distrubution of the cencoring times
### sigma: variance of random effects
### ncenter: number of centers
#####################################################################################
dgp_cox_weibull <- function(n, beta, lambda, nu, mu, sigma, ncenter){
X <- data.frame(dgpX(n, ncenter))
Xm <- model.matrix(~ -1 + X1 + X2 + X3 + X4, data=X)
stopifnot(ncol(Xm) == length(beta))
fixed <- beta %*% t(Xm)
b <- rnorm(ncenter,0,sigma)
Z <- dgpZ(n, ncenter)
Zm <- model.matrix(~ -1 + Z)
random <- b %*% t(Zm)
scale <- lambda * exp(fixed + random)
T <- (-log(runif(n, min=0, max=1))/scale)^(1/nu) # Weibull distributed survival
C <- rexp(n, mu) # exponentially distributed cencoring times
Y <- pmin(T,C) # observed time
status <- (T<=C) # TRUE for events
X$Y <- as.vector(Y)
X$status <- as.vector(status)
X$center <- Z
return(X)
}
#####################################################################################
### Fit of a frailty Cox model
#####################################################################################
fit_coxme <- function(data)
coxme(Surv(Y, status) ~ X1 + X2 + X3 + X4 + (1|center), data=data)
#################################################################################
### Simulations in a frailty Cox model
### Estimation of the coverage probability of simultaneous confidence intervals
### for many-to-one differences of treatment effects
### nsim: number of simulated data sets
### dgp: data generating proccess
### fit: model fit of simulated data
### other parameters: see above
#################################################################################
sim <- function(nsim, dgp, fit, beta, n, lambda, nu, mu, sigma, ncenter){
coverage <- rep(NA, nsim)
contrast1 <- beta[2] - beta[1]
contrast2 <- beta[3] - beta[1]
for (i in 1:nsim){
#print(i)
x <- dgp(n, beta, lambda, nu, mu, sigma, ncenter)
mod <- 0
try(mod <- fit(x), silent = TRUE)
sci <- NA
sci <- try(confint(glht(mod, linfct = mcp(X1 = "Dunnett"), alternative = "less")), silent = TRUE)
try(if(contrast1 < sci$confint[1,3] & contrast2 < sci$confint[2,3]){coverage[i] <- 1}
else{coverage[i] <- 0}, silent = TRUE) }
coverage_probability <- mean(coverage, na.rm = TRUE)
return(coverage_probability)
}
b2 <- seq(-2,0,0.05)
b3 <- seq(-2,0,0.05)
design <- expand.grid(b2, b3)
names(design) <- c("b2", "b3")
nsim <- 10000
lambda <- 0.5
nu <- 2
mu <- 0.1
sigma <- 1
ncenter <- 5
#####################################################################################
### Balanced design with 105 observations
#####################################################################################
n <- 105
results <- matrix(0, nrow=nrow(design), ncol=4, byrow=T)
results[,1] <- rep(n, nrow(design))
set.seed(1803)
for (j in 1:nrow(design)) {
print(j)
beta <- c(0,as.numeric(design[j,]),0.2,0.05,-0.3,-0.1)
results[j,2:3] <- as.numeric(design[j,])
results[j,4] <- sim(nsim, dgp_cox_weibull, fit_coxme, beta, n, lambda, nu, mu, sigma, ncenter)
save(results, file = "coxme_105.Rda")
}
colnames(results)= c("n", "b2", "b3", "cov_prob")
save(results, file = "coxme_105.Rda")
#####################################################################################
### Balanced design with 300 observations
#####################################################################################
n <- 300
results <- matrix(0, nrow=nrow(design), ncol=4, byrow=T)
results[,1] <- rep(n, nrow(design))
set.seed(1803)
for (j in 1:nrow(design)) {
print(j)
beta <- c(0,as.numeric(design[j,]),0.2,0.05,-0.3,-0.1)
results[j,2:3] <- as.numeric(design[j,])
results[j,4] <- sim(nsim, dgp_cox_weibull, fit_coxme, beta, n, lambda, nu, mu, sigma, ncenter)
save(results, file = "coxme_300.Rda")
}
colnames(results)= c("n", "b2", "b3", "cov_prob")
save(results, file = "coxme_300.Rda")
########################################################################################
# Simulation setup for an unbalanced design with less observations in the control group
########################################################################################
#####################################################################################
### Data generating process of the covariates X and cluster centr
### n: total number of observations
### ncenter: number of centers
#####################################################################################
dgpX <- function(n, ncenter){
x1 <- factor(rep(1:3, n/3))
x2 <- sample(gl(2, n / 2), replace=FALSE)
x3 <- runif(n, 18, 65)
x4 <- sample(gl(3, n / 3), replace=FALSE)
X <- data.frame(X1 = x1, X2 = x2, X3 = x3, X4 = x4)
return(X)
}
dgpZ <- function(n, ncenter){
centr <- factor(rep(1:ncenter, rep(c(3,6,9,12,15)*rep(n/135,ncenter)*3)))
}
#####################################################################################
### Unbalanced design with 135 observations
#####################################################################################
n <- 135
results <- matrix(0, nrow=nrow(design), ncol=4, byrow=T)
results[,1] <- rep(n, nrow(design))
set.seed(1803)
for (j in 1:nrow(design)) {
print(j)
beta <- c(0,as.numeric(design[j,]),0.2,0.05,-0.3,-0.1)
results[j,2:3] <- as.numeric(design[j,])
results[j,4] <- sim(nsim, dgp_cox_weibull, fit_coxme, beta, n, lambda, nu, mu, sigma, ncenter)
save(results, file = "coxme1_135.Rda")
}
colnames(results)= c("n", "b2", "b3", "cov_prob")
save(results, file = "coxme1_135.Rda")
#####################################################################################
### Unbalanced design with 405 observations
#####################################################################################
n <- 405
results <- matrix(0, nrow=nrow(design), ncol=4, byrow=T)
results[,1] <- rep(n, nrow(design))
set.seed(1803)
for (j in 1:nrow(design)) {
print(j)
beta <- c(0,as.numeric(design[j,]),0.2,0.05,-0.3,-0.1)
results[j,2:3] <- as.numeric(design[j,])
results[j,4] <- sim(nsim, dgp_cox_weibull, fit_coxme, beta, n, lambda, nu, mu, sigma, ncenter, nther)
save(results, file = "coxme1_405.Rda")
}
colnames(results)= c("n", "b2", "b3", "cov_prob")
save(results, file = "coxme1_405.Rda")
########################################################################################
# Simulation setup for an unbalanced design with more observations in the control group
########################################################################################
#####################################################################################
### Data generating process of the covariates X and cluster centr
### n: total number of observations
### ncenter: number of centers
#####################################################################################
dgpX <- function(n, ncenter){
x1 <- factor(rep(c(rep(1,5),rep(2,10),rep(3,10)), ncenter))
x2 <- sample(gl(2, n / 2), replace=FALSE)
x3 <- runif(n, 18, 65)
x4 <- sample(gl(3, n / 3), replace=FALSE)
X <- data.frame(X1 = x1, X2 = x2, X3 = x3, X4 = x4)
return(X)
}
dgpZ <- function(n, ncenter){
centr <- gl(ncenter, n/ncenter)
}
#####################################################################################
### Unbalanced design with 125 observations
#####################################################################################
n <- 125
results <- matrix(0, nrow=nrow(design), ncol=4, byrow=T)
results[,1] <- rep(n, nrow(design))
set.seed(1803)
for (j in 1:nrow(design)) {
print(j)
beta <- c(0,as.numeric(design[j,]),0.2,0.05,-0.3,-0.1)
results[j,2:3] <- as.numeric(design[j,])
results[j,4] <- sim(nsim, dgp_cox_weibull, fit_coxme, beta, n, lambda, nu, mu, sigma, ncenter)
save(results, file = "coxme2_125.Rda")
}
colnames(results)= c("n", "b2", "b3", "cov_prob")
results
save(results, file = "coxme2_125.Rda")
#####################################################################################
### Unbalanced design with 375 observations
#####################################################################################
n <- 375
results <- matrix(0, nrow=nrow(design), ncol=4, byrow=T)
results[,1] <- rep(n, nrow(design))
set.seed(1803)
for (j in 1:nrow(design)) {
print(j)
beta <- c(0,as.numeric(design[j,]),0.2,0.05,-0.3,-0.1)
results[j,2:3] <- as.numeric(design[j,])
results[j,4] <- sim(nsim, dgp_cox_weibull, fit_coxme, beta, n, lambda, nu, mu, sigma, ncenter)
save(results, file = "coxme2_375.Rda")
}
colnames(results)= c("n", "b2", "b3", "cov_prob")
results
save(results, file = "coxme2_375.Rda")
########################################################################################
# Simulation setup for an unbalanced design with number of observations differing
# between centers
########################################################################################
#####################################################################################
### Unbalanced design with 100 observations
#####################################################################################
#####################################################################################
### Data generating process of the covariates X and cluster centr
### n: total number of observations
### ncenter: number of centers
#####################################################################################
dgpX <- function(n, ncenter){
x1 <- factor(rep(c(rep(1,10),rep(2,5),rep(3,5)), ncenter))
x2 <- sample(gl(2, n / 2), replace=FALSE)
x3 <- runif(n, 18, 65)
x4 <- sample(gl(3, n / 3), replace=FALSE)
X <- data.frame(X1 = x1, X2 = x2, X3 = x3, X4 = x4)
return(X)
}
dgpZ <- function(n, ncenter){
centr <- gl(ncenter, n/ncenter)
}
n <- 100
results <- matrix(0, nrow=nrow(design), ncol=4, byrow=T)
results[,1] <- rep(n, nrow(design))
set.seed(1803)
for (j in 1:nrow(design)) {
print(j)
beta <- c(0,as.numeric(design[j,]),0.2,0.05,-0.3,-0.1)
results[j,2:3] <- as.numeric(design[j,])
results[j,4] <- sim(nsim, dgp_cox_weibull, fit_coxme, beta, n, lambda, nu, mu, sigma, ncenter)
save(results, file = "coxme3_100.Rda")
}
colnames(results)= c("n", "b2", "b3", "cov_prob")
results
save(results, file = "coxme3_100.Rda")
#####################################################################################
### Unbalanced design with 300 observations
#####################################################################################
#####################################################################################
### Data generating process of the covariates X and cluster centr
### n: total number of observations
### ncenter: number of centers
#####################################################################################
dgpX <- function(n, ncenter){
x1 <- factor(rep(c(rep(1,30),rep(2,15),rep(3,15)), ncenter))
x2 <- sample(gl(2, n / 2), replace=FALSE)
x3 <- runif(n, 18, 65)
x4 <- sample(gl(3, n / 3), replace=FALSE)
X <- data.frame(X1 = x1, X2 = x2, X3 = x3, X4 = x4)
return(X)
}
dgpZ <- function(n, ncenter){
centr <- gl(ncenter, n/ncenter)
}
n <- 300
results <- matrix(0, nrow=nrow(design), ncol=4, byrow=T)
results[,1] <- rep(n, nrow(design))
set.seed(1803)
for (j in 1:nrow(design)) {
print(j)
beta <- c(0,as.numeric(design[j,]),0.2,0.05,-0.3,-0.1)
results[j,2:3] <- as.numeric(design[j,])
results[j,4] <- sim(nsim, dgp_cox_weibull, fit_coxme, beta, n, lambda, nu, mu, sigma, ncenter)
save(results, file = "coxme3_300.Rda")
}
colnames(results)= c("n", "b2", "b3", "cov_prob")
results
save(results, file = "coxme3_300.Rda")
########################################################################################
# Simulation setup for an unbalanced design with many centers and two observations
# in each centers
########################################################################################
#####################################################################################
### Data generating process of the covariates X and cluster centr
### n: total number of observations
### ncenter: number of centers
#####################################################################################
dgpX <- function(n, ncenter){
x1 <- factor(rep(1:3, n/3))
x2 <- sample(gl(2, n / 2), replace=FALSE)
x3 <- runif(n, 18, 65)
x4 <- sample(gl(3, n / 3), replace=FALSE)
X <- data.frame(X1 = x1, X2 = x2, X3 = x3, X4 = x4)
return(X)
}
dgpZ <- function(ncenter){
centr <- sample(factor(rep(1:ncenter, 2)))
}
#####################################################################################
### Data generating process in the frailty Cox model with Weibull distributed
### survival and normally distributed random effect
### n: total number of observations
### beta: vector of effects of treatments and other covariates
### lambda, nu: scale and shape parameter of the Weibull distribution
### mu: parameter of the exponential distrubution of the cencoring times
### sigma: variance of random effects
### ncenter: number of centers
#####################################################################################
dgp_cox_weibull <- function(n, beta, lambda, nu, mu, sigma, ncenter){
X <- data.frame(dgpX(n, ncenter))
Xm <- model.matrix(~ -1 + X1 + X2 + X3 + X4, data=X)
stopifnot(ncol(Xm) == length(beta))
fixed <- beta %*% t(Xm)
b <- rnorm(ncenter,0,sigma)
Z <- dgpZ(ncenter)
Zm <- model.matrix(~ -1 + Z)
random <- b %*% t(Zm)
scale <- lambda * exp(fixed + random)
T <- (-log(runif(n, min=0, max=1))/scale)^(1/nu)
C <- sample(c(rep(0, 0.2*n), rep(10000,0.8*n))) # 20% Censoring
Y <- pmin(T,C)
status <- (T<=C)
X$Y <- as.vector(Y)
X$status <- as.vector(status)
X$center <- Z
return(X)
}
#####################################################################################
### Unbalanced design with 60 centers
#####################################################################################
ncenter <- 60
results <- matrix(0, nrow=nrow(design), ncol=4, byrow=T)
results[,1] <- rep(n, nrow(design))
set.seed(1803)
for (j in 1:nrow(design)) {
print(j)
beta <- c(0,as.numeric(design[j,]),0.2,0.05,-0.3,-0.1)
results[j,2:3] <- as.numeric(design[j,])
results[j,4] <- sim(nsim, dgp_cox_weibull, fit_coxme, beta, n, lambda, nu, mu, sigma, ncenter)
save(results, file = "coxme4_120.Rda")
}
colnames(results)= c("n", "b2", "b3", "cov_prob")
results
save(results, file = "coxme4_120.Rda")
#####################################################################################
### Unbalanced design with 150 centers
#####################################################################################
ncenter <- 150
results <- matrix(0, nrow=nrow(design), ncol=4, byrow=T)
results[,1] <- rep(n, nrow(design))
set.seed(1803)
for (j in 1:nrow(design)) {
print(j)
beta <- c(0,as.numeric(design[j,]),0.2,0.05,-0.3,-0.1)
results[j,2:3] <- as.numeric(design[j,])
results[j,4] <- sim(nsim, dgp_cox_weibull, fit_coxme, beta, n, lambda, nu, mu, sigma, ncenter)
save(results, file = "coxme4_300.Rda")
}
colnames(results)= c("n", "b2", "b3", "cov_prob")
results
save(results, file = "coxme4_300.Rda")
|