R/sn.R

Defines functions sn_test

Documented in sn_test

# Transformation test for univariate skew-normal distributions
sn_test <- function(x, method = "transf"){  
  DNAME <- deparse(substitute(x))
  stopifnot(is.numeric(x))
  if (sum(is.na(x)) > 0) warning("NA values have been deleted.")
  x <- x[is.na(x) == FALSE]
  n <- length(x)   # adjusted sample size without NA values
  samplerange <- max(x) - min(x)
  if (samplerange == 0) stop("all observations are identical")
  estim <- sn.mple(y = x, penalty = "Qpenalty", opt.method = "nlminb")$cp
  xi.hat <- cp2dp(estim, family = "SN")[1] 
  y      <- abs(x - xi.hat) * sign(rnorm(n))
  p.value <- shapiro.test(y)$p.value
  results <- list(p.value = p.value, 
                  method = "Shapiro-Wilk test for skew-normal distributions", 
                  data.name = DNAME, alternative = paste(DNAME, "does not follow a skew-normal distribution."))
  class(results) <- "htest"
  return(results)
}

Try the goft package in your browser

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

goft documentation built on July 1, 2020, 5:56 p.m.