R/f_copulacorrectionpstar_discrete.R

Defines functions copulaCorrectionDiscrete_pstar

#' @importFrom stats ecdf runif qnorm
copulaCorrectionDiscrete_pstar <- function(vec.data.endo){

  # Fit empirical CDF to data
  H.p  <- ecdf(vec.data.endo)
  n <- length(vec.data.endo)

  # Caluclate H.pX
  H.p1 <- H.p(vec.data.endo)
  H.p0 <- H.p(vec.data.endo-1)
  H.p0[H.p0 == 0] <- 1- n/(n+1) #0.0000001
  H.p0[H.p0 == 1] <- n/(n+1)    #0.9999999
  H.p1[H.p1 == 0] <- 1- n/(n+1) #0.0000001
  H.p1[H.p1 == 1] <- n/(n+1)    #0.9999999

  # Calculate U.p
  U.p <- runif(n = length(vec.data.endo), min=H.p0, max=H.p1)

  # Calculate p.star
  return(qnorm(U.p))
}

Try the REndo package in your browser

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

REndo documentation built on July 3, 2024, 1:06 a.m.