R/conditionalBootstrap.R

Defines functions conditionalBootstrap

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)
}

Try the cAIC4 package in your browser

Any scripts or data that you put into this service are public.

cAIC4 documentation built on Sept. 22, 2021, 5:07 p.m.