R/var.R

Defines functions var.Bolstad var.default var

Documented in var

#' Variance generic
#'
#' @param x an object for which we want to compute the variance
#' @param \dots Any additional arguments to be passed to \code{var}.
#' @export
var = function(x, ...){
  UseMethod("var")
}
#' @export
var.default = function(x, ...){
  stats::var(x, ...)
}
#' @export
var.Bolstad = function(x, ...){
  if(any(grepl("var", names(x))))
    return(x$var)
  
  xVals = x$param.x
  mx = mean(x, ...)
  fx = approxfun(xVals, (xVals - mx)^2 * x$posterior)
  
  return(integrate(fx, min(xVals), max(xVals))$value)
}

Try the Bolstad package in your browser

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

Bolstad documentation built on Jan. 8, 2021, 2:03 a.m.