## simulate data
# \donttest{
data <- simulate_GLM_dataset()
# }
## estimate model without misclassification error
# \donttest{
summary(lm(Y ~ X + M2, data))
# }
## estimate model with misclassification error
# \donttest{
summary(lm(Y ~ X + M, data))
# }
## estimate misclassification probabilities
# \donttest{
Pmodel <- glm(M2 ~ M + X, data = data, family = binomial("logit"))
summary(Pmodel)
# }
## construct a-posteriori probabilities from Pmodel
# \donttest{
P <- predict(Pmodel, newdata = data, type = "response")
P <- cbind(1 - P, P)
dimnames(P)[[2]] <- c("M0", "M1") ## speaking names
# }
## estimate misclassGLM
# \donttest{
est <- misclassGLM(Y = data$Y,
X = as.matrix(data[, 2, drop = FALSE]),
setM = matrix(c(0, 1), nrow = 2),
P = P)
summary(est)
# }
## and bootstrapping the results from dataset
if (FALSE) {
summary(boot.misclassGLM(est,
Y = data$Y,
X = data.matrix(data[, 2, drop = FALSE]),
Pmodel = Pmodel,
PX = data,
repetitions = 100))
}
Run the code above in your browser using DataLab