Skip to content

Commit

Permalink
version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar Alberto Quijano Xacur authored and cran-robot committed Jan 30, 2019
0 parents commit 7dd8f8f
Show file tree
Hide file tree
Showing 26 changed files with 3,298 additions and 0 deletions.
18 changes: 18 additions & 0 deletions DESCRIPTION
@@ -0,0 +1,18 @@
Package: unifed
Title: The Unifed Distribution
Version: 1.0
Date: 2018-12-23
Description: Introduced in Quijano Xacur (2018) <arXiv:1812.00251>. This package contains the density, distribution, quantile and random generation functions for the unifed. It also contains functions for the unifed family and quasifamily that can be used with the glm() function.
Depends: R (>= 3.1), methods
License: GPL (>= 3)
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.0
Suggests: knitr, rmarkdown
VignetteBuilder: knitr
Author: Oscar Alberto Quijano Xacur [aut,cre]
Maintainer: Oscar Alberto Quijano Xacur <oscar.quijano@use.startmail.com>
NeedsCompilation: yes
Packaged: 2019-01-21 15:22:43 UTC; oscar
Repository: CRAN
Date/Publication: 2019-01-30 18:40:03 UTC
25 changes: 25 additions & 0 deletions MD5
@@ -0,0 +1,25 @@
af487460752a22d74f19513d7fd9f154 *DESCRIPTION
1f14593fdae9328057e53441f20653e6 *NAMESPACE
dfa125ee5b266fd3e2a47a8da47bcfa1 *R/dirwin.hall.R
f2757132e44a7e2fc86e494e140e2fed *R/dunifed.R
e67fa11806ca3c759ac56553bd1f664c *R/summary_unifed_glm.R
9df00b055204c5756274f0044d4d9d74 *R/unifed.R
0fae5502964b42527b1f3ac3bd2146c3 *R/unifed.deviance.R
37e825f06579b4b2c758bcc6851d0cf0 *R/unifed.kappa.R
7aa7d160accd44e2bc4ca44adc6de39c *R/unifed.varf.R
d107da57f8fd4f8b5461dfda55901508 *R/zzz.R
8b88335e4b660ccd759564cc8fea7e33 *README.md
73aa477ccf3c7c59b857abc15da79794 *build/vignette.rds
0e57fd2f8b9ca3806b35e9e2b0164b97 *inst/doc/introduction_unifed.R
4e130758dd6d12318c4e24a57f9243ef *inst/doc/introduction_unifed.Rmd
6a45287d7991e5e06b634ab5956a13e0 *inst/doc/introduction_unifed.html
4e8c0a0cc72788425161fc37173b4ea7 *man/dirwin.hall.Rd
49c483775cff05601eefbaab98435570 *man/dunifed.Rd
7cfe0eaf19949070341752b444c40cd3 *man/summary_unifed_glm.Rd
58186ae61b2fb8ae4bc83cfb71eb6ce5 *man/unifed.Rd
a719316ec3c55cf10b08485d9d720ed5 *man/unifed.deviance.Rd
52832a88b93e87a388a99e873aa242f7 *man/unifed.kappa.Rd
fdbfca941463b82b7350772ab5fbabed *man/unifed.varf.Rd
217241e5407ed733438f7f3c6c0b5027 *src/unifed_kappa.c
2d8ce114754786b08468d15627a48cf0 *vignettes/bibliography.bib
aaaa8f6d17f32b4d0976394b3e7f23ec *vignettes/introduction_unifed.Rmd
24 changes: 24 additions & 0 deletions NAMESPACE
@@ -0,0 +1,24 @@
# Generated by roxygen2: do not edit by hand

export(dirwin.hall)
export(dunifed)
export(punifed)
export(quasiunifed)
export(qunifed)
export(runifed)
export(summary_unifed_glm)
export(unifed)
export(unifed.deviance)
export(unifed.kappa)
export(unifed.kappa.double.prime)
export(unifed.kappa.prime)
export(unifed.kappa.prime.inverse)
export(unifed.kappa.prime.inverse.one)
export(unifed.unit.deviance)
export(unifed.varf)
importFrom(methods,setMethod)
importFrom(stats,make.link)
importFrom(stats,runif)
useDynLib(unifed,unifed_kappa)
useDynLib(unifed,unifed_kappa_prime_inverse)
useDynLib(unifed,unit_deviance)
58 changes: 58 additions & 0 deletions R/dirwin.hall.R
@@ -0,0 +1,58 @@
#' Irwin-Hall density
#'
#' @param x A number between 0 and \code{n}.
#'
#' @param n Number of uniform distributions in the unit interval to sum.
#'
#' @param log If it evaluates to \code{TRUE} it returns the log of the
#' density instead of the density.
#'
#' @details Gives the density of the Irwin-Hall distribution. It is
#' the density of the sum of \code{n} uniform distributions on the
#' interval (0,1).
#'
#' \deqn{
#' h(y;n) = \frac{1}{(n-1)!}\sum_{k=0}^{ \left\lfloor y \right\rfloor } (-1)^k {n \choose k} (y-k)^{n-1}
#' }{
#' 1 __ |_y_| k / n \ n - 1
#' h(y;n) = --------- \ ( - 1) | | (y - k)
#' (n - 1)! /__ k = 0 \ k /
#' }
#'
#' where \eqn{x \in [0,1]} and \eqn{n} is a positive integer.
#'
#' This function is not numerically stable. The examples have some cases of this.
#'
#' @examples
#'
#' dirwin.hall(2,5)
#'
#' # Numerically unstable example
#' # Run the following one after the other
#' # See how it goes from positive to negative (which means overflowing )
#' dirwin.hall(35,50)
#' dirwin.hall(36,50)
#' dirwin.hall(37,50)
#' dirwin.hall(38,50)
#'
#' @export

dirwin.hall <- function(x,n,log=FALSE){

ret1 <- 0
if ( x < 0 | x > n)
stop("x must be greater or equal to 0 and less or equal to n")
for(k in 0:floor(x))
ret1 <- ret1+ (-1)^k*choose(n,k)*(x-k)^(n-1)
if(log){
if( n==1)
return( log(ret1) )
else
return( log(ret1)-sum(log(1:(n-1))) )
}else{
if( n==1)
return( ret1 )
else
return( ret1 / (factorial(n-1)) )
}
}
107 changes: 107 additions & 0 deletions R/dunifed.R
@@ -0,0 +1,107 @@
#' The unifed distribution
#'
#' @description Density, distribution function, quantile function and
#' random generation for the unifed distribution.
#'
#' @param x A vector of quantiles. They must be numbers between 0 and 1.
#'
#' @param theta The value of the canonical parameter. It must be of length one.
#'
#' @return \code{dunifed} gives the density function.
#'
#' @references{
#' Quijano Xacur, Oscar Alberto (2018). The Unifed Distribution. ArXiv. \url{http://arxiv.org/abs/1812.00251}.
#'
#' }
#'
#' @examples
#'
#' dunifed( c(0.1,0.3,0.7), 10)
#'
#' @export
dunifed <- function(x,theta){
if(length(theta) > 1)
stop("thetha must be of length one")
ifelse( x < 0 | x > 1,
0,
exp( x * theta - unifed.kappa(theta) ))
}

#' @rdname dunifed
#' @name punifed
#'
#' @param q A vector of quantiles.
#'
#' @return \code{punifed} gives the distribution function.
#'
#' @examples
#'
#' x <- c(0.1,0.4,0.7,1)
#' punifed(x,-5)
#'
#' @export
punifed <- function(q,theta){

if(length(theta) > 1)
stop("thetha must be of length one")
ret <- numeric(length(q))
less.than.zerop <- q<=0
greater.than.onep <- q>=1
between.zero.and.onep <- !( less.than.zerop | greater.than.onep )
ret[less.than.zerop] <- 0
ret[greater.than.onep] <- 1

if ( abs(theta) <= sqrt(.Machine$double.eps) )
ret[ between.zero.and.onep ] <- q[between.zero.and.onep]
else{
q.subset <- q[between.zero.and.onep]
ret[ between.zero.and.onep ] <- ( ( exp(q.subset*theta) -1 ) / ( exp(theta) -1 ) )
}

ret
}


#' @rdname dunifed
#' @name qunifed
#'
#' @param p A vector of probabilities.
#'
#' @return \code{qunifed} gives the quantile function.
#'
#' @examples
#'
#' p <- 1:9/10
#' qunifed(p,5)
#'
#' @export
#'
qunifed <- function(p,theta){
if( T %in% (p<0 | p>1) )
stop("The values of p must be a number between 0 and 1")
if(length(theta) > 1)
stop("thetha must be of length one")
if ( abs(theta) <= sqrt(.Machine$double.eps) )
p
else
log(p * ( exp(theta) -1 ) + 1 ) / theta

}

#' @rdname dunifed
#' @name runifed
#'
#' @param n number of observations
#'
#' @return \code{runifed} generates random observations.
#'
#' @examples
#'
#' runifed(20,-3.3)
#'
#' @export
runifed <- function(n,theta){
qunifed( runif(n) , theta )
}

## LocalWords: quantile
23 changes: 23 additions & 0 deletions R/summary_unifed_glm.R
@@ -0,0 +1,23 @@
#' Summarizing Generalized Linear Model Fits
#'
#' Wrapper function for summary.glm.
#'
#' @param object an object of class "glm".
#'
#' @param ... Other arguments for \code{stats::summary.glm}.
#'
#' This wrapper function was created in order to automatically set to
#' 1 the dispersion parameter of a fitted unifed GLM. When the package
#' is loaded the summary method of the glm class is rewritten using
#' this function.
#'
#' @export
summary_unifed_glm<- function(object,...){
args.list <- list(...)
if( object$family$family=="unifed" &
( !("dispersion" %in% names(args.list)) | is.null(args.list$dispersion)) ){
stats::summary.glm(object,dispersion=1,...)
}else{
stats::summary.glm(object,...)
}
}

0 comments on commit 7dd8f8f

Please sign in to comment.