Description Usage Arguments Value Examples
View source: R/MI_imputation.R
Performs imputation of the missing data using MICE and returns a list in the
correct format for the unsupMI() and seMIsupcox()functions.
MImpute() performs imputation for datasets with missing data only.
MImpute_surv() performs imputation for a dataset with survival data.
The Nelson Aalen estimator is calculated and used as predictor in the
imputation, Time is not used as predictor.
MImpute_lcens() performs imputation for a dataset with left-censored
data. Note that with MImpute_lcens() pmm imputation is
performed for variables not affected by left-censoring.
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 | MImpute(
data,
mi.m,
method = NULL,
predMat = NULL,
maxit = 10,
return.midsObject = FALSE
)
MImpute_surv(
data,
mi.m,
time.status.names = c("time", "status"),
return.midsObject = FALSE
)
MImpute_lcens(
data,
data.lod,
standards,
mi.m,
mice.log = 10,
maxit = 10,
return.midsObject = FALSE
)
MImpute_lcenssurv(
data,
mi.m,
time.status.names = c("time", "status"),
data.lod,
standards,
mice.log = 10,
var.log = NULL,
maxit = 10,
return.midsObject = FALSE
)
|
data |
Dataframe with incomplete data. (for |
mi.m |
Number of imputations to perform. |
method |
Optional. single string, or a vector of strings specifying
the imputation method to be used for each column in data
(passed to |
predMat |
Optional. supply a |
maxit |
passed to |
return.midsObject |
Boolean |
time.status.names |
Names of the variables for time and status (in that order). |
data.lod |
Dataframe containing indicators of which observation are
left-censored (censoring value for such observations and any other values
for not censored observations). The colnames should correspond to variables
in |
standards |
Dataframe of 1 row containing the LOD values (not logged,
whatever the value for |
mice.log |
set to |
var.log |
names of variables to log if |
If return.midsObject == FALSE a list of size mi.m, containing
the imputed datasets. If return.midsObject == TRUE a list of 2, the
first element (imputed.data) being the list of size mi.m as
described in the previous sentence, the 2nd element (mids.obj)
containing the mids object as returned by mice()
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 | 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.