Git Product home page Git Product logo

triangle's Introduction

© Copyright 2024 Robert Carnell

triangle

An R package to work with the triangle distribution and logarithmic triangle distribution

Github Actions Windows Code Coverage CRAN Downloads CRAN
R-CMD-check AppVeyor build status Coverage status CRAN status

See the package documentation here:

Getting Started

Install the R package:

# Stable CRAN version
install.packages("triangle")

# OR development version from GitHub
require(devtools)
devtools::install_github("bertcarnell/triangle")

use the functions:

  • a = minimum
  • b = maximum
  • c = mode
require(triangle)

Triangle distribution

# rtriangle(n, a, b, c)
set.seed(42)
rtriangle(5, 1, 5, 2)
## [1] 3.988898 4.131038 2.073171 3.573596 2.926584
# ptriangle(x, a, b, c)
ptriangle(0:5, 0, 10, 5)
## [1] 0.00 0.02 0.08 0.18 0.32 0.50
# qtriangle(p, a, b, c)
qtriangle(seq(0, 1, by = 0.2), 1, 10, 3)
## [1]  1.000000  2.897367  3.851830  4.980040  6.450352 10.000000
# dtriangle(x, a, b, c)
dtriangle(0:4, 0, 10, 5)
## [1] 0.00 0.04 0.08 0.12 0.16

Logarithmic triangle distribution

# rltriangle(n, a, b, c, logbase)
set.seed(2001)
rltriangle(5, 1, 100, 10)
## [1] 20.195183 13.001831  4.579489  4.753026  3.572658
# pltriangle(x, a, b, c, logbase)
pltriangle(10^(0:3), 1, 1000, 10)
## [1] 0.0000000 0.3333333 0.8333333 1.0000000
# qltriangle(p, a, b, c, logbase)
qltriangle(seq(0, 1, by = 0.2), 1, 100, 20)
## [1]   1.00000   5.26497  10.47630  17.76210  29.59642 100.00000
# dltriangle(x, a, b, c, logbase)
dltriangle(0:5, 1, 10, 5)
## [1] 0.0000000 0.0000000 0.8613531 1.3652124 1.7227062 2.0000000

Parameter estimates

triangle method of moments estimates

x <- rtriangle(20, 0, 2, 1.5)
triangle_mom(x)
##         a         b         c 
## 0.6341961 1.9096262 1.4197678

triangle maximum likelihood estimates

x <- c(0.1, 0.25, 0.3, 0.4, 0.45, 0.6, 0.75, 0.8)
# triangle_mle(x, debug = FALSE, maxiter = 100)
triangle_mle(x)
## Triangle Maximum Likelihood Estimates
## 
## Call:  triangle_mle(x = x) 
## 
## Estimates:
##    Estimate Std.Err
## a 0.0076277  0.0996
## b 0.9939370  0.1649
## c 0.3000000  0.0861
## 
## Convergence Code:  0
##   CONVERGENCE: REL_REDUCTION_OF_F <= FACTR*EPSMCH
# standard triangle (0,1) likelihood estimates
standard_triangle_mle(x)
## Triangle Maximum Likelihood Estimates
## 
## Call:  standard_triangle_mle(x = x) 
## 
## Estimates:
##   Estimate Std.Err
## a      0.0  0.0000
## b      1.0  0.0000
## c      0.3  0.0871
## 
## Convergence Code:  NA
##  
set.seed(1976)
x <- rtriangle(100, 1, 5, 3.5)
triangle_mle(x)
## Triangle Maximum Likelihood Estimates
## 
## Call:  triangle_mle(x = x) 
## 
## Estimates:
##   Estimate Std.Err
## a   0.9060  0.1259
## b   4.8254  0.0770
## c   3.6853  0.0924
## 
## Convergence Code:  0
##   CONVERGENCE: REL_REDUCTION_OF_F <= FACTR*EPSMCH

triangle's People

Contributors

bertcarnell avatar

Stargazers

Steven Paul Sanderson II, MPH avatar Maciej Nasinski avatar Tanner Stauss avatar

Watchers

James Cloos avatar  avatar

triangle's Issues

Explicit comparison to runif

make more effort to determine if the operation of the triangle parameters work just like the uniform parameters

plotting the voronoi tessellation

Wonder if RTriangle also provides information to plot the corresponding voronoi tessellation and if there is a simple way of generating these plots?

parameter estimators

Write a maximum likelihood and method of moments estimator function for the triangle distribution

Fix README typos

“Rlriangle”
Dltriangle does not have the log base specified

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.