1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
conditionalBootstrap <-
function(object, BootStrRep) {
# A function that calculates the bias correction for a (generalized) linear
# mixed models by the methods in Efron (2004).
#
# Args:
# object = Object of class lmerMod or glmerMod. Obtained by lmer() or
# glmer().
# BootStrRep = Number of bootstrap replications.
#
# Returns:
# bootBC = Bias correction (i.e. degrees of freedom) for a (generalized)
# linear mixed model.
#
dataMatrix <- simulate(object, nsim = BootStrRep, use.u = TRUE)
workingEta <- sapply(dataMatrix, function(x){
predict(refit(object, newresp = x))
})
if(is.factor(dataMatrix[[1]]))
dataMatrix <- sapply(dataMatrix, as.numeric) - 1
dataMatrix <- dataMatrix - rowMeans(dataMatrix)
bootBC <- sum(workingEta * dataMatrix) /
((BootStrRep - 1) * sigma(object)^2)
return(bootBC)
}
|