我正在试验 R 中的 mice 包,我很好奇如何将列排除在插补之外。
- 如果我只想对一列进行平均插补,
mice.impute.mean(y, ry, x = NULL, ...)
函数似乎是我会使用的。我正在努力理解我需要包含什么作为第三个论点才能让它发挥作用。 - 如果我有一个数据集,其中包括姓名、ID、出生日期等分类数据,这些数据不应该影响其他列的计算,并且在缺失时不应该填写,我如何告诉老鼠排除这些其计算中的列?
我一直在使用 mice 数据集
nhanes
供我探索。
谢谢
最佳答案
我不知道你的数据,因此我不能为你创建一个例子,但你正在寻找 mice() 函数的这个参数
predictorMatrix
A numeric matrix of length(blocks) rows and ncol(data) columns, containing 0/1 data specifying the set of predictors to be used for each target column. Each row corresponds to a variable block, i.e., a set of variables to be imputed. A value of 1 means that the column variable is used as a predictor for the target block (in the rows). By default, the predictorMatrix is a square matrix of ncol(data) rows and columns with all 1's, except for the diagonal. Note: For two-level imputation models (which have "2l" in their names) other codes (e.g, 2 or -2) are also allowed.
使用此参数,您可以定义要使用哪些列来估算特定列。
where
A data frame or matrix with logicals of the same dimensions as data indicating where in the data the imputations should be created. The default, where = is.na(data), specifies that the missing data should be imputed. The where argument may be used to overimpute observed data, or to skip imputations for selected missing values.
您可以在此处定义要为哪些列创建插补。
关于r - 如何用 mice R 仅估算一列或几列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57613208/