# with glm, family = binomial
set.seed(888)
intercept <- 1
beta <- c(0.5, 1.2)
n <- 200
x1 <- rnorm(n, mean = 1, sd = 1)
x2 <- rbinom(n, size = 1, prob = 0.3)
linpred <- intercept + x1 * beta[1] + x2 * beta[2]
prob <- exp(linpred) / (1 + exp(linpred))
runis <- runif(n, min = 0, max = 1)
ytest <- ifelse(test = runis < prob, yes = 1, no = 0)
simdat <- data.frame(cbind(y = ifelse(runis < prob, 1, 0), x1, x2))
fit <- glm(y ~ x1 + x2, family = binomial, data = simdat, x = TRUE)
summary(fit)
global <- shrink(fit, type = "global", method = "dfbeta")
print(global)
coef(global)
shrink(fit, type = "parameterwise", method = "dfbeta")
shrink(fit, type = "parameterwise", method = "dfbeta", join = list(c("x1", "x2")))
#shrink(fit, type = "global", method = "jackknife")
#shrink(fit, type = "parameterwise", method = "jackknife")
#shrink(fit, type = "parameterwise", method = "jackknife",
# join = list(c("x1", "x2")))
# For more examples see shrink
Run the code above in your browser using DataLab