You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for the mice package. I'm using version 3.6.0.
The example below shows mice() changing the predictorMatrix. It appears to be related to the similarity of the variable names, because it doesn't happen if one of the variable names is changed.
Am I misunderstanding something? Thanks.
library(mice)
set.seed(1)
# Repeated measurements of 'y' on each subject.
# 'score' and 'score.previous' are constant within each subject.
d <- data.frame(subject = 1:10,
score = rnorm(10),
score.previous = rnorm(10))
d[1:2, "score"] <- NA
DataA <- d[rep(1:10, each = 3), ] # 3 observations per subject
DataA$y <- rnorm(nrow(DataA))
DataA[4:5, "y"] <- NA
iniA <- mice(DataA, maxit=0)
methA <- iniA$method
methA["score"] <- "2lonly.pmm"
methA["y"] <- "2l.pan"
predMatA <- iniA$predictorMatrix
predMatA[c("score", "score.previous", "y"), "subject"] <- -2
predMatA
## subject score score.previous y
## subject 0 1 1 1
## score -2 0 1 1
## score.previous -2 1 0 1
## y -2 1 1 0
miceA <- mice(data = DataA, m = 5, maxit = 10,
method = methA, predictorMatrix = predMatA)
miceA$predictorMatrix
## subject score score.previous y
## subject 0 1 1 1
## score -2 0 0 1
## score.previous -2 1 0 1
## y -2 1 1 0
# Note that miceA$predictorMatrix["score", "score.previous"] is 0.
# Next, use the same data but change the name 'score.previous' to 'sp'.
DataB <- DataA
names(DataB)[names(DataB) == "score.previous"] <- "sp"
predMatB <- predMatA
rownames(predMatB) <- colnames(predMatB) <- names(DataB)
methB <- methA
names(methB) <- names(DataB)
miceB <- mice(data = DataB, m = 5, maxit = 10,
method = methB, predictorMatrix = predMatB)
miceB$predictorMatrix
## subject score sp y
## subject 0 1 1 1
## score -2 0 1 1
## sp -2 1 0 1
## y -2 1 1 0
# miceB$predictorMatrix["score", "sp"] is 1.
The text was updated successfully, but these errors were encountered:
Thanks for the mice package. I'm using version 3.6.0.
The example below shows mice() changing the predictorMatrix. It appears to be related to the similarity of the variable names, because it doesn't happen if one of the variable names is changed.
Am I misunderstanding something? Thanks.
The text was updated successfully, but these errors were encountered: