这里只是示例数据:
# generation of correlated data
matrixCR <- matrix(NA, nrow = 100, ncol = 100)
diag(matrixCR) <- 1
matrixCR[upper.tri (matrixCR, diag = FALSE)] <- 0.5
matrixCR[lower.tri (matrixCR, diag = FALSE)] <- 0.5
matrixCR[1:10,1:10]
L = chol(matrixCR)# Cholesky decomposition
nvars = dim(L)[1]
nobs = 200
set.seed(123)
rM = t(L) %*% matrix(rnorm(nvars*nobs), nrow=nvars, ncol=nobs)
rM1 <- t(rM)
rownames(rM1) <- paste("S", 1:200, sep = "")
colnames(rM1) <- paste("M", 1:100, sep = "")
# introducing missing value to the dataset
N <- 2000*0.05 # 5% random missing values
inds <- round ( runif(N, 1, length(rM1)) )
rM1[inds] <- NA
# using random forest implemented in mice package
require(mice)
out.imp <- mice(rM1, m = 5, method ="rf")
imp.data <- complete(out.imp)
我收到以下错误:
iter imp variable
1 1 M1 M2Error in apply(forest, MARGIN = 1, FUN = function(s) sample(unlist(s), :
dim(X) must have a positive length
我不确定是什么导致了这个问题?