# NOT RUN {
data(cancer, package = "survival")
cancer.imp <- MImpute(cancer[, -c(1:3)], 2)
## MImpute_surv
data(cancer, package = "survival")
cancer$status <- cancer$status - 1
cancer.imp <- MImpute_surv(cancer, 1)
## MImpute_lcens
toy <- iris[, 1:4]
# censor on variables 3 and 4, with LOD at quantile .1 and .2.
LODs <- toy[1, ]
LODs[1, ] <-c(NA, NA, quantile(toy[,3], .2), quantile(toy[,4], .1))
# Censor indicator
Censored <- data.frame(Petal.Length = runif(150, 50,60),
Petal.Width = runif(150, 50,60))
Censored[toy[,3] < LODs[1, 3], 1] <- LODs[1, 3]
Censored[toy[,4] < LODs[1, 4], 2] <- LODs[1, 4]
# NA for censored data
toy[toy[,3] < LODs[1, 3], 3] <- NA
toy[toy[,4] < LODs[1, 4], 4] <- NA
# Additional missing data
toy[sample(1:nrow(toy), 30), 1] <- NA
toy[sample(1:nrow(toy), 30), 3] <- NA
toy[sample(1:nrow(toy), 30), 4] <- NA
toy.imp <- MImpute_lcens(data = toy, data.lod = Censored, standards = LODs,
mi.m = 1, mice.log = FALSE)
## MImpute_lcenssurv
data(cancer, package = "survival")
cancer$status <- cancer$status - 1
toy2 <- cancer[, -1]
# censor on variables age and meal.cal, with LOD at quantile .1 and .2.
LODs <- toy2[1, ]
LODs[1, ] <-c(NA, NA, quantile(toy2[, "age"], .2, na.rm = TRUE), NA, NA,
NA, NA, quantile(toy2[, "meal.cal"], .1, na.rm = TRUE), NA)
# Censor indicator
Censored <- data.frame(age = runif(nrow(toy2), 300,400),
meal.cal = runif(nrow(toy2), 50,60))
Censored[toy2[, "age"] < LODs[1, "age"], "age"] <- LODs[1, "age"]
Censored[!is.na(toy2[, "meal.cal"]) &
toy2[, "meal.cal"] < LODs[1, "meal.cal"], "meal.cal"] <-
LODs[1, "meal.cal"]
# NA for censored data
toy2[toy2[, "age"] < LODs[1, "age"], "age"] <- NA
toy2[!is.na(toy2[, "meal.cal"]) &
toy2[, "meal.cal"] < LODs[1, "meal.cal"],"meal.cal"] <- NA
# Additional missing data
toy2[sample(1:nrow(toy2), 30), 6] <- NA
toy2[sample(1:nrow(toy2), 30), 3] <- NA
toy2[sample(1:nrow(toy2), 30), 4] <- NA
toy2$sex <- factor(toy2$sex)
toy2$ph.ecog <- factor(toy2$ph.ecog)
toy2.imp <- MImpute_lcenssurv(
data = toy2, mi.m = 1, data.lod = Censored, standards = LODs,
mice.log = FALSE)
# }
Run the code above in your browser using DataLab