R/CensoredStudentsT.R

Defines functions is_continuous.CensoredStudentsT is_discrete.CensoredStudentsT support.CensoredStudentsT crps.CensoredStudentsT quantile.CensoredStudentsT cdf.CensoredStudentsT log_pdf.CensoredStudentsT pdf.CensoredStudentsT random.CensoredStudentsT kurtosis.CensoredStudentsT skewness.CensoredStudentsT variance.CensoredStudentsT mean.CensoredStudentsT CensoredStudentsT

Documented in cdf.CensoredStudentsT CensoredStudentsT crps.CensoredStudentsT is_continuous.CensoredStudentsT is_discrete.CensoredStudentsT kurtosis.CensoredStudentsT log_pdf.CensoredStudentsT mean.CensoredStudentsT pdf.CensoredStudentsT quantile.CensoredStudentsT random.CensoredStudentsT skewness.CensoredStudentsT support.CensoredStudentsT variance.CensoredStudentsT

CensoredStudentsT <- function(df, location = 0, scale = 1, left = -Inf, right = Inf) {
  n <- c(length(df), length(location), length(scale), length(left), length(right))
  stopifnot("parameter lengths do not match (only scalars are allowed to be recycled)" = all(n %in% c(1L, max(n))))
  d <- data.frame(df = df, location = location, scale = scale, left = left, right = right)
  class(d) <- c("CensoredStudentsT", "distribution")
  d
}

mean.CensoredStudentsT <- function(x, ...) {
  m <- ect(df = x$df, location = x$location, scale = x$scale, left = x$left, right = x$right)
  setNames(m, names(x))
}

variance.CensoredStudentsT <- function(x, ...) {
  stop("not yet implemented")
}

skewness.CensoredStudentsT <- function(x, ...) {
  stop("not yet implemented")
}

kurtosis.CensoredStudentsT <- function(x, ...) {
  stop("not yet implemented")
}

random.CensoredStudentsT <- function(x, n = 1L, drop = TRUE, ...) {
  stopifnot(requireNamespace("distributions3"))
  n <- distributions3::make_positive_integer(n)
  if (n == 0L) return(numeric(0L))
  FUN <- function(at, d) rct(n = at, df = d$df, location = d$location, scale = d$scale, left = d$left, right = d$right)
  distributions3::apply_dpqr(d = x, FUN = FUN, at = n, type = "random", drop = drop)
}

pdf.CensoredStudentsT <- function(d, x, drop = TRUE, elementwise = NULL, ...) {
  stopifnot(requireNamespace("distributions3"))
  FUN <- function(at, d) dct(x = at, df = d$df, location = d$location, scale = d$scale, left = d$left, right = d$right, ...)
  distributions3::apply_dpqr(d = d, FUN = FUN, at = x, type = "density", drop = drop, elementwise = elementwise)
}

log_pdf.CensoredStudentsT <- function(d, x, drop = TRUE, elementwise = NULL, ...) {
  stopifnot(requireNamespace("distributions3"))
  FUN <- function(at, d) dct(x = at, df = d$df, location = d$location, scale = d$scale, left = d$left, right = d$right, log = TRUE)
  distributions3::apply_dpqr(d = d, FUN = FUN, at = x, type = "logLik", drop = drop, elementwise = elementwise)
}

cdf.CensoredStudentsT <- function(d, x, drop = TRUE, elementwise = NULL, ...) {
  stopifnot(requireNamespace("distributions3"))
  FUN <- function(at, d) pct(q = at, df = d$df, location = d$location, scale = d$scale, left = d$left, right = d$right, ...)
  distributions3::apply_dpqr(d = d, FUN = FUN, at = x, type = "probability", drop = drop, elementwise = elementwise)
}

quantile.CensoredStudentsT <- function(x, probs, drop = TRUE, elementwise = NULL, ...) {
  stopifnot(requireNamespace("distributions3"))
  FUN <- function(at, d) qct(at, df = d$df, location = d$location, scale = d$scale, left = d$left, right = d$right, ...)
  distributions3::apply_dpqr(d = x, FUN = FUN, at = probs, type = "quantile", drop = drop, elementwise = elementwise)
}

crps.CensoredStudentsT <- function(y, x, drop = TRUE, elementwise = NULL, ...) {
  stopifnot(requireNamespace("distributions3"))
  FUN <- function(at, d) scoringRules::crps_ct(y = at, df = d$df, location = d$location, scale = d$scale, lower = d$left, upper = d$right)
  distributions3::apply_dpqr(d = y, FUN = FUN, at = x, type = "crps", drop = drop, elementwise = elementwise)
}

support.CensoredStudentsT <- function(d, drop = TRUE, ...) {
  stopifnot(requireNamespace("distributions3"))
  distributions3::make_support(d$left, d$right, d, drop = drop)
}

is_discrete.CensoredStudentsT <- function(d, ...) {
  setNames(rep.int(FALSE, length(d)), names(d))
}

is_continuous.CensoredStudentsT <- function(d, ...) {
  setNames(!is.finite(d$left) & !is.finite(d$right), names(d))
}

Try the crch package in your browser

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

crch documentation built on March 31, 2023, 11:08 p.m.