knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

triangulr

Build Codecov CRAN Downloads Downloads Overall Lifecycle: stable

Introduction

The triangulr package provides high-performance triangular distribution functions which includes density function, distribution function, quantile function, random variate generator, moment generating function, and expected shortfall function for the triangular distribution.

Installation

You can install the released version of triangulr from CRAN with:

install.packages("triangulr")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("irkaal/triangulr")

Example

These are basic examples of using the included functions:

library(triangulr)

Using the density function, dtri().

x <- c(0.1, 0.5, 0.9)

dtri(x,
     min = 0,
     max = 1,
     mode = 0.5)

dtri(x,
     min = c(0, 0, 0),
     max = 1,
     mode = 0.5)

Using the distribution function, ptri().

q <- c(0.1, 0.5, 0.9)

1 - ptri(q, lower_tail = FALSE)

ptri(q, lower_tail = TRUE)

ptri(q, log_p = TRUE)

log(ptri(q, log_p = FALSE))

Using the quantile function, qtri().

p <- c(0.1, 0.5, 0.9)

qtri(1 - p, lower_tail = FALSE)

qtri(p, lower_tail = TRUE)

qtri(log(p), log_p = TRUE)

qtri(p, log_p = FALSE)

Using the random variate generator, rtri().

n <- 3

set.seed(1)
rtri(n,
     min = 0,
     max = 1,
     mode = 0.5)

set.seed(1)
rtri(n,
     min = c(0, 0, 0),
     max = 1,
     mode = 0.5)

Using the moment generating function, mgtri().

t <- c(1, 2, 3)

mgtri(t,
      min = 0,
      max = 1,
      mode = 0.5)

mgtri(t,
      min = c(0, 0, 0),
      max = 1,
      mode = 0.5)

Using the expected shortfall function, estri().

p <- c(0.1, 0.5, 0.9)

estri(p,
      min = 0,
      max = 1,
      mode = 0.5)

estri(p,
      min = c(0, 0, 0),
      max = 1,
      mode = 0.5)


irkaal/triangulr documentation built on Aug. 27, 2023, 2:30 a.m.