r - 如何用 mice R 仅估算一列或几列

标签 r dataframe imputation r-mice

我正在试验 R 中的 mice 包,我很好奇如何将列排除在插补之外。

  1. 如果我只想对一列进行平均插补, mice.impute.mean(y, ry, x = NULL, ...) 函数似乎是我会使用的。我正在努力理解我需要包含什么作为第三个论点才能让它发挥作用。
  2. 如果我有一个数据集,其中包括姓名、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/

相关文章:

python - 使用 fancyimpute 和 pandas 进行数据插补

r - 为 R 安装 data.table 时出现问题

java - 如何使用 Rcaller 将数据库表从 java 转移到 R?

python - Pandas - 在多列上有条件地合并数据框

r - 如何计算相邻行的平均值?

r - 在 R 中,如何估算右删失缺失数据以遵循假设的分布?

r - 如何将scale_y_continuous(labels = scales::percent) 更改为

r - 在 pdf、单个表、r 中解析跨多个页面的表

python - 在多列上使用 numpy 二维数组从 Pandas 数据框中选择行

r - R中的平均前后插补