R/xxx.R

Defines functions dztpois pztpois cv cvxh skewness

Documented in cv cvxh cvxh dztpois pztpois skewness

#' @aliases pztpois
#' @title Zero-truncated Poisson distribution
#' 
#' @description Density for the zero-truncated Poisson distribution with parameter 
#' \code{lambda}    
#' 
#' @param x a vector of positive integers
#' @param ... other parameters 
#' 
#' @note
#' \code{pztpois} is not vectorized yet.
#' 
#' @section TODO:
#' \code{pztpois} will be vectorized in the near future.
#'
#' @return write a returning value
#' @author Chel Hee Lee <\email{gnustats@@gmail.com}>
#' @export
dztpois <- function(x, ...){
  if(any(x == 0)) stop("'x' must be a positive integer")
  sf <- ppois(q=0, ..., lower.tail=FALSE)
  rval <- 1/sf*dpois(x=x, ...)
  return(rval)
}
NULL

#' @rdname dztpois
#' @param q quantile
#' @export
pztpois <- function(q, ...){

  if(length(q) != 1) stop("length(q) should be 1")
  if(q==0) stop("'q' must be a positive integer")

  vals <- cumsum(dztpois(seq_len(q), ...))
  rval <- vals[q]                                                    
  return(rval)
}
NULL

#' @title Coefficient of Variation (CV)
#' @description Coefficient of variation
#' @param x a numeric vector
#' @return write a returning value
#' @author Chel Hee Lee <\email{gnustats@@gmail.com}>
#' @export
cv <- function(x){
  stopifnot(is.vector(x), is.numeric(x))
  return(sqrt(var(x))/mean(x))
}
NULL


#' @title Sorting data points of convex hull in clockwiswe order
#'
#' @description Sort rows of a matrix or a data frame in clockwise
#' 
#' @param obj list or matrix
#' @param clockwise arrange obj in clockwise order
#' @param ... other arguments
#'
#' @note
#' \code{cvxh} may be deprecated in the near future.
#' \code{demo/lgamma-translation.R} does not use this function anymore. 
#'
#' @author Chel Hee Lee <\email{gnustats@@gmail.com}>
#' @export
cvxh <- function(obj, clockwise=FALSE, ...){

  stopifnot(is.logical(clockwise), any(is.matrix(obj), is.list(obj)))
  
  if(is.list(obj)) xy <- do.call(rbind, obj)
  if(is.matrix(obj)) xy <- obj
  
  if(clockwise){
    centered <- scale(xy, center=TRUE, scale=FALSE)
    xy <- centered[order(centered),]
  } else xy <- xy[chull(xy),]
  
  return(xy)
}
NULL

#' @title Skewness
#' @description Skewness
#' @param y a numeric vector
#' @return a numeric value
#' @author Chel Hee Lee <\email{gnustats@@gmail.com}>
#' @export
skewness <- function(y){
  val <- mean((y-mean(y))^3)/(var(y))^{3/2}
  return(val)
}
NULL

Try the ipeglim package in your browser

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

ipeglim documentation built on May 2, 2019, 4:31 p.m.