R/bootStat.R

Defines functions typeIerror critValue

Documented in critValue typeIerror

# $Id: bootStat.R 265 2024-07-28 09:45:12Z larso $

# Calculates the critical value at level |alpha| for the vector of
# trials |s|
critValue <- function(s, alpha=0.05) {
  if ( alpha <= 0 || alpha >= 1 ) 
     stop("The argument alpha must be between 0 and 1")
  ss_ <- sort(s)
  mean( c(ss_[floor(alpha*length(s))], ss_[ceiling(alpha*length(s))]), 
        na.rm=TRUE )
}


# Calculate the probability of a larger value than |shat| in the vector 
# of trials |s|
typeIerror <- function(shat,s) {
  reject <- function(alfa)  {
    quantile(s, alfa, na.rm=TRUE, names=F) - shat
  }
  if ( reject(0) * reject(1) > 0 )  {
      # Ingen loesning til unitroot, saa enten 0% eller 100%
      if ( shat <= min(s) )  return(0)
      if ( shat >= max(s) )  return(1)
  }
  uniroot(reject,c(0,1), tol=.Machine$double.eps^.5)$root
}

Try the Benchmarking package in your browser

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

Benchmarking documentation built on April 4, 2025, 5:07 a.m.