File: conditionalBootstrap.R

package info (click to toggle)
r-cran-caic4 1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, trixie
  • size: 356 kB
  • sloc: makefile: 2
file content (27 lines) | stat: -rw-r--r-- 912 bytes parent folder | download | duplicates (3)
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)
}