在MICE R mice.impute.polyreg.r
中(通过贝叶斯多元回归模型对分类响应变量的估算),提到该方法包括以下步骤:
在实施中:
mice.impute.polyreg <- function(y, ry, x, nnet.maxit = 100,
nnet.trace = FALSE, nnet.maxNWts = 1500, ...) {
x <- as.matrix(x)
aug <- augment(y, ry, x, ...)
x <- aug$x
y <- aug$y
ry <- aug$ry
w <- aug$w
fy <- as.factor(y)
nc <- length(levels(fy))
un <- rep(runif(sum(!ry)), each = nc)
xy <- cbind.data.frame(y = y, x = x) # fixed SvB 6/12/2010
if (ncol(x) == 0L)
xy <- data.frame(xy, int = 1)
fit <- multinom(formula(xy), data = xy[ry,,drop = FALSE ],
weights = w[ry], maxit = nnet.maxit, trace = nnet.trace,
maxNWts = nnet.maxNWts, ...)
post <- predict(fit, xy[!ry, ], type = "probs")
if (sum(!ry) == 1)
post <- matrix(post, nrow = 1, ncol = length(post))
if (is.vector(post))
post <- matrix(c(1 - post, post), ncol = 2)
draws <- un > apply(post, 1, cumsum)
idx <- 1 + apply(draws, 2, sum)
return(levels(fy)[idx])
}
我能够完成前两个步骤,但是我似乎无法找到实现中“噪声”添加到预测中的位置。似乎预测的类别直接返回。
我错过了什么吗?