Skip to content

Commit

Permalink
version 1.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 May 20, 2019
1 parent 0b77416 commit 76a687a
Show file tree
Hide file tree
Showing 22 changed files with 1,045 additions and 166 deletions.
13 changes: 13 additions & 0 deletions ChangeLog
@@ -0,0 +1,13 @@
Version 1.1:
* Added function unifed.canonical.link to R/unifed.R
* Added "canonical" to the possible links of unifed().
* Added unifed functions to use with stan
* Added R/unifed.stan.path.R for getting the path to include in stan files.

Version 1.0.2:
* Fixed roxygen comments of R/unifed.kappa.R and
R/unifed.deviance.R that were generating wrong Rd files.

Version 1.0.1:
* Fixed bug in function unifed.kappa.prime.inverse. It was giving
the wrong sign for values smaller than 0.1
12 changes: 6 additions & 6 deletions DESCRIPTION
@@ -1,18 +1,18 @@
Package: unifed
Title: The Unifed Distribution
Version: 1.0.2
Date: 2019-03-11
Version: 1.1.0
Date: 2019-05-17
Description: Probability functions and family for glm() of the unifed distribution (Quijano Xacur, 2018; <arXiv:1812.00251>).
Depends: R (>= 3.1), methods
License: GPL (>= 3)
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.0
Suggests: knitr, rmarkdown, testthat, rstan
RoxygenNote: 6.1.1
Suggests: knitr, rmarkdown, testthat, rstan, data.table
VignetteBuilder: knitr
Author: Oscar Alberto Quijano Xacur [aut,cre]
Maintainer: Oscar Alberto Quijano Xacur <oscar.quijano@use.startmail.com>
NeedsCompilation: yes
Packaged: 2019-03-12 02:57:31 UTC; oscar
Packaged: 2019-05-20 13:53:41 UTC; oscar
Repository: CRAN
Date/Publication: 2019-03-12 06:00:03 UTC
Date/Publication: 2019-05-20 17:20:03 UTC
34 changes: 21 additions & 13 deletions MD5
@@ -1,27 +1,35 @@
c4f7508e463c615351eb92065226212a *DESCRIPTION
1f14593fdae9328057e53441f20653e6 *NAMESPACE
fae84e5c585849b94446655fa95d6922 *ChangeLog
4a405ba69cfa97b0d4cae9cd2e28dc8c *DESCRIPTION
4d4d69c000d86b1b9f3c735181c288ca *NAMESPACE
dfa125ee5b266fd3e2a47a8da47bcfa1 *R/dirwin.hall.R
f2757132e44a7e2fc86e494e140e2fed *R/dunifed.R
df13e6d7622d04f973aa7664ca130227 *R/doc-unifed_stan.R
3810c704e8d8294233f8aabc3ea269b4 *R/dunifed.R
e67fa11806ca3c759ac56553bd1f664c *R/summary_unifed_glm.R
9df00b055204c5756274f0044d4d9d74 *R/unifed.R
97048cb4ab69a87084e6e1c8df575e84 *R/unifed.R
61adc440861f4334cb98cd158eb1f536 *R/unifed.deviance.R
e436bbef2c1433749a3e26be7ca08c4c *R/unifed.kappa.R
36631861ede43aec23726456eb859984 *R/unifed.stan.path.R
7aa7d160accd44e2bc4ca44adc6de39c *R/unifed.varf.R
d107da57f8fd4f8b5461dfda55901508 *R/zzz.R
094d2e28bae1cf7c28860266973290b0 *README.md
89fccd567e926662d80feaadf6998311 *build/vignette.rds
0e57fd2f8b9ca3806b35e9e2b0164b97 *inst/doc/introduction_unifed.R
aaaa8f6d17f32b4d0976394b3e7f23ec *inst/doc/introduction_unifed.Rmd
153e5c2b117d6fc4821709cc5e50bab7 *inst/doc/introduction_unifed.html
c44f50d6b6e3e778143d1eb546c148f7 *README.md
1a4fc81a0a84a7b2213ee4a85e9fc001 *build/vignette.rds
b055e618049cefa7ccae8c5c3a7207d9 *inst/doc/introduction_unifed.R
1b245b107bcc83d963170693712efed3 *inst/doc/introduction_unifed.Rmd
ec26f63b60c695f74d68352a4711e4a6 *inst/doc/introduction_unifed.html
48764658f90c2ecc23dbaab161d73eca *inst/stan/unifed.stan
4e8c0a0cc72788425161fc37173b4ea7 *man/dirwin.hall.Rd
49c483775cff05601eefbaab98435570 *man/dunifed.Rd
1d9a033a7ad29fdce341677cfde69dd9 *man/dunifed.Rd
7cfe0eaf19949070341752b444c40cd3 *man/summary_unifed_glm.Rd
58186ae61b2fb8ae4bc83cfb71eb6ce5 *man/unifed.Rd
794dbd69adf63b38fa66f23d9c18ef86 *man/unifed.Rd
7ec848a088f49baed7e0306d7b92f824 *man/unifed.deviance.Rd
d947d0d1eeffacf630a71777278aa001 *man/unifed.kappa.Rd
f23247936487979bba2a17db60723e2a *man/unifed.stan.Rd
63d2733b217abfab8f6aa63c4439cb24 *man/unifed.stan.path.Rd
fdbfca941463b82b7350772ab5fbabed *man/unifed.varf.Rd
397dedc00189410e0157beab1cfb8b9b *src/unifed_kappa.c
e2241c5c92234698d7ae027b0f24b5f6 *src/unifed_kappa.c
1c790fe953ea9463feee4ca9e12e77be *tests/testthat.R
bef324c7f169fb8c914dd9d2e9e8cc95 *tests/testthat/tests.r
2d8ce114754786b08468d15627a48cf0 *vignettes/bibliography.bib
aaaa8f6d17f32b4d0976394b3e7f23ec *vignettes/introduction_unifed.Rmd
1b245b107bcc83d963170693712efed3 *vignettes/introduction_unifed.Rmd
6b472202745e012ac175c3e6f3769749 *vignettes/unifed_example.stan
6774582fd69a5ec5cae7545a23f882ff *vignettes/unifed_test.r
4 changes: 4 additions & 0 deletions NAMESPACE
Expand Up @@ -8,12 +8,16 @@ export(qunifed)
export(runifed)
export(summary_unifed_glm)
export(unifed)
export(unifed.canonical.link)
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.lcdf)
export(unifed.stan.folder)
export(unifed.stan.path)
export(unifed.unit.deviance)
export(unifed.varf)
importFrom(methods,setMethod)
Expand Down
55 changes: 55 additions & 0 deletions R/doc-unifed_stan.R
@@ -0,0 +1,55 @@
#' Stan functions for working with the unifed distribution
#'
#' @name unifed.stan
#'
#' @details
#'
#' A script with stan functions of the unifed is provided. The script
#' can be included in stan code. The full path to the script can be
#' obtained with the function \code{\link{unifed.stan.path}}. The
#' following list are the names of functions that take one real value:
#'
#' \describe{
#' \item{\code{real unifed_kappa(real theta)}}{Computes the cumulant generator of the
#' unifed distribution.}
#' \item{\code{real unifed_kappa_prime(real theta)}}{Computes the first derivative of
#' the cumulant generator.}
#' \item{\code{real unifed_kappa_double_prime(real theta)}}{Computes the second
#' derivative of the cumulant generator.}
#' \item{\code{real unifed_lpdf(real x,real theta)}}{Computes the
#' logarithm of the probability density function of a unifed
#' distribution. \code{theta} is the value of the canonical
#' parameter of the unifed and \code{x} if the value where the
#' density is evaluated.}
#' \item{\code{real unifed_quantile(real p,real theta)}}{Returns the
#' p-th quantile of a unifed distribution with canonical parameter
#' \code{theta}}.
#' \item{\code{real unifed_rng(real theta)}}{Returns a simulated value
#' of a unifed distribution with canonical parameter
#' \code{theta}.}
#' \item{\code{real unifed_lcdf(real x,real theta)}}{Computes the
#' logarithm of the cumulative density function of a unifed
#' distribution. \code{theta} is the value of the canonical
#' parameter of the unifed and \code{x} if the value where the
#' density is evaluated.}
#' \item{\code{real unifed_kappa_prime_inverse(real mu)}}{Returns the
#' inverse of the derivative of the unifed cumulant generator}
#' \item{\code{real unifed_unit_deviance(real y,real mu)}}{Unit
#' deviance function of the unifed.}
#' }
#'
#' The following functions take vectors as arguments
#'
#' \describe{
#' \item{\code{vector unifed_kappa_v(vector theta)}}{Vectorized
#' version of \code{unifed_kappa}.}
#' \item{\code{vector unifed_kappa_prime_inverse_v(vector
#' mu)}}{Vectorized version of \code{unifed_kappa_prime_inverse}.}
#' \item{\code{void unifed_glm_lp(vector y, vector theta, vector
#' weights)}}{Adds to the Log Probability Accumulator the
#' logarithm of the likelihood function of a GLM with observed
#' response \code{y}, estimated canonical parameter \code{theta}
#' and weights \code{weights}.} }
NULL

## LocalWords: unifed cumulant stan lpdf Vectorized contant
54 changes: 36 additions & 18 deletions R/dunifed.R
Expand Up @@ -27,6 +27,41 @@ dunifed <- function(x,theta){
exp( x * theta - unifed.kappa(theta) ))
}

#' @rdname dunifed
# @name unifed.lcdf
#'
#' @return \code{unifed.lcdf} returns the log of the cumulative
#' distribution function of the unifed.
#'
#' @examples
#'
#' x <- c(0.3,0.6,0.9)
#' unifed.lcdf(x,5)
#'
#' @export
unifed.lcdf <- function(x,theta){
if(length(theta) > 1)
stop("theta must be of length one")
ret <- numeric(length(x))
less.than.zerop <- x<=0
greater.than.onep <- x>=1
between.zero.and.onep <- !( less.than.zerop | greater.than.onep )
ret[less.than.zerop] <- -Inf
ret[greater.than.onep] <- 0

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

ret
}

#' @rdname dunifed
#' @name punifed
#'
Expand All @@ -41,24 +76,7 @@ dunifed <- function(x,theta){
#'
#' @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
exp(unifed.lcdf(q,theta))
}


Expand Down
59 changes: 53 additions & 6 deletions R/unifed.R
Expand Up @@ -4,14 +4,28 @@
#' be a name/expression, a literal character string, a length-one
#' character vector or an object of class ‘"link-glm"’ (such as
#' generated by ‘make.link’) provided it is not specified via one
#' of the standard names. The \code{unifed} family accepts the
#' links (as names) 'logit', 'probit', 'cloglog' and 'cauchit'.
#'
#' of the accepted names. The \code{unifed} family accepts the
#' links (as names) 'canonical', 'logit', 'probit', 'cloglog' and
#' 'cauchit'.
#'
#' @param ... Optional \code{tol} and \code{maxit} arguments for
#' \code{\link{unifed.unit.deviance}}.
#'
#'
#' @details
#' The link 'canonical' is not part of the standard names accepted by
#' \code{make.link()} from the stats package. It corresponds to the
#' canonical link function for the unifed distribution, which is the
#' inverse of the derivative of its cumulant generator. There is no
#' explicit formula for it. The function
#' \code{\link{unifed.kappa.prime.inverse}()} implements it using the
#' Newthon-Raphson method.
#'
#'
#' @return \code{unifed} returns a family object for using the unifed
#' distribution with the \code{glm} function.
#'
#' @seealso \code{Gamma} \code{\link{unifed.kappa.prime.inverse}}
#'
#' @references{
#'
Expand All @@ -27,7 +41,7 @@ unifed <- function(link="logit",...){
linktemp <- substitute(link)
if (!is.character(linktemp))
linktemp <- deparse(linktemp)
okLinks <- c("logit", "probit", "cloglog", "cauchit")
okLinks <- c("logit", "probit", "cloglog", "cauchit","canonical")
if (linktemp %in% okLinks)
stats <- make.link(linktemp)
else if (is.character(link)) {
Expand Down Expand Up @@ -103,7 +117,7 @@ quasiunifed <- function(link="logit",...){
linktemp <- substitute(link)
if (!is.character(linktemp))
linktemp <- deparse(linktemp)
okLinks <- c("logit", "probit", "cloglog", "cauchit")
okLinks <- c("logit", "probit", "cloglog", "cauchit","canonical")
if (linktemp %in% okLinks)
stats <- make.link(linktemp)
else if (is.character(link)) {
Expand Down Expand Up @@ -154,4 +168,37 @@ quasiunifed <- function(link="logit",...){

}

## LocalWords: logit cauchit cloglog probit param
#' @rdname unifed
#' @name unifed.canonical.link
#'
#' This function is used inside of \code{unifed()} when the link
#' parameter is set to \code{"canonical"}. It returns the link
#' function, inverse link function, the derivative dmu/deta and a
#' function for domain checking for the unifed distribution canonical
#' link.
#'
#' @return An object of class \code{"link-glm"}.
#'
#' @seealso \code{make.link}
#'
#' @export
unifed.canonical.link <- function(){
structure(list(
linkfun=unifed.kappa.prime.inverse,
linkinv=unifed.kappa.prime,
mu.eta=unifed.kappa.double.prime,
valideta=function(eta) TRUE
),
class="link-glm")
}


make.link <- function(link){
if(link=="canonical")
unifed.canonical.link()
else
stats::make.link(link)
}


## LocalWords: logit cauchit cloglog probit param unifed cumulant
25 changes: 25 additions & 0 deletions R/unifed.stan.path.R
@@ -0,0 +1,25 @@
#' Unifed Stan function paths
#'
#' The unifed.stan provided by the file contains functions for using
#' the unifed distribution in stan. The file can be included (with
#' #include) insided the functions block of a stan program or its
#' contents can be copied and pasted.
#'
#' @return The full path to the unifed.stan file provided by the
#' package.
#'
#' @export
unifed.stan.path <- function(){
system.file("stan/unifed.stan",package="unifed")
}

#' @rdname unifed.stan.path
#' @name unifed.stan.folder
#'
#' @return \code{unifed.stan.folder} returns a string containing the
#' path to the folder containing the unifed.stan file. This can be
#' used as the \code{isystem} parameter in stan functions.
#' @export
unifed.stan.folder <- function(){
system.file("stan/",package="unifed")
}
6 changes: 4 additions & 2 deletions README.md
@@ -1,8 +1,10 @@
# Unifed

The unifed distribution is the only exponential dispersion family
containing the exponential distribution. This R package contains
function for working with this distribution.
containing the exponential distribution. This repository contains an R
package for working with this
distribution. [stan](https://mc-stan.org/) functions for the unifed
distribution are also provided.

An R vignette introducing the unifed distribution and examples of how
to use this package can be found at
Expand Down
Binary file modified build/vignette.rds
Binary file not shown.

0 comments on commit 76a687a

Please sign in to comment.