Title: | Distribution Functions and Parameter Estimates for the Triangle Distribution |
---|---|
Description: | Provides the "r, q, p, and d" distribution functions for the triangle distribution. Also includes maximum likelihood estimation of parameters. |
Authors: | Rob Carnell [aut, cre] |
Maintainer: | Rob Carnell <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.1 |
Built: | 2024-11-10 05:45:43 UTC |
Source: | https://github.com/bertcarnell/triangle |
Compare multiple triangle distributions fits
compare_triangle_fit( y, cols = c("red", "blue", "green"), main = "Triangle Fit Comparison", ... )
compare_triangle_fit( y, cols = c("red", "blue", "green"), main = "Triangle Fit Comparison", ... )
y |
the triangle distributed sample |
cols |
the colors of the CDF-based estimates, the maximum likelihood estimates, and the method of moments estimates |
main |
the plot title |
... |
other parameters passed to |
set.seed(10304) xtest <- rtriangle(100, 1, 5, 2) compare_triangle_fit(xtest)
set.seed(10304) xtest <- rtriangle(100, 1, 5, 2) compare_triangle_fit(xtest)
These functions provide information about the triangle distribution on the
logarithmic interval from a
to b
with a maximum at c
. dltriangle
gives the density, pltriangle
gives the distribution function,
qltriangle
gives the quantile function, and rltriangle
generates
n
random deviates.
rltriangle( n = 1, a = 1, b = 100, c = 10^((log10(a) + log10(b))/2), logbase = 10 ) dltriangle(x, a = 1, b = 100, c = 10^((log10(a) + log10(b))/2), logbase = 10) pltriangle(q, a = 1, b = 100, c = 10^((log10(a) + log10(b))/2), logbase = 10) qltriangle(p, a = 1, b = 100, c = 10^((log10(a) + log10(b))/2), logbase = 10)
rltriangle( n = 1, a = 1, b = 100, c = 10^((log10(a) + log10(b))/2), logbase = 10 ) dltriangle(x, a = 1, b = 100, c = 10^((log10(a) + log10(b))/2), logbase = 10) pltriangle(q, a = 1, b = 100, c = 10^((log10(a) + log10(b))/2), logbase = 10) qltriangle(p, a = 1, b = 100, c = 10^((log10(a) + log10(b))/2), logbase = 10)
n |
number of observations. If |
a |
lower limit of the distribution. |
b |
upper limit of the distribution. |
c |
mode of the distribution. |
logbase |
the base of the logarithmic scale to use (default to 10) |
x , q
|
vector of quantiles. |
p |
vector of probabilities. |
All probabilities are lower tailed probabilties. a
,
b
, and c
may be appropriate length vectors except in the
case of rtriangle
.
dltriangle
gives the density, pltriangle
gives the
distribution function, qltriangle
gives the quantile function, and
rltraingle
generates random deviates. Invalid arguments will
result in return value NaN
or NA
.
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
.Random.seed
about random number generation,
runif
, etc for other distributions.
tri <- rltriangle(100000, 1, 100, 10) hist(log10(tri), breaks=100, main="Triangle Distribution", xlab="x") dltriangle(10, 1, 100, 10) # 2/(log10(b)-log10(a)) = 1 qltriangle(pltriangle(10)) # 10
tri <- rltriangle(100000, 1, 100, 10) hist(log10(tri), breaks=100, main="Triangle Distribution", xlab="x") dltriangle(10, 1, 100, 10) # 2/(log10(b)-log10(a)) = 1 qltriangle(pltriangle(10)) # 10
Quantile-Quantile Plot for Triangle Distributed Data
qqtriangle( y, a, b, c, main = "Triangle Q-Q Plot", xlab = "Theoretical Quantiles", ylab = "Sample Quantiles", ... )
qqtriangle( y, a, b, c, main = "Triangle Q-Q Plot", xlab = "Theoretical Quantiles", ylab = "Sample Quantiles", ... )
y |
the triangle distributed sample |
a |
the theoretical distribution triangle minimum parameter |
b |
the theoretical distribution triangle maximum parameter |
c |
the theoretical distribution triangle mode parameter |
main |
the plot title |
xlab |
the x-axis label |
ylab |
the y-axis label |
... |
other parameters passed to |
a list of x-y coordinates on the plot
set.seed(10304) xtest <- rtriangle(100, 1, 5, 2) theta <- coef(triangle_mle(xtest)) qqtriangle(xtest, theta[1], theta[2], theta[3])
set.seed(10304) xtest <- rtriangle(100, 1, 5, 2) theta <- coef(triangle_mle(xtest)) qqtriangle(xtest, theta[1], theta[2], theta[3])
Maximum likelihood estimate of the standard triangle distribution mode
standard_triangle_mle(x, debug = FALSE)
standard_triangle_mle(x, debug = FALSE)
x |
sample from a triangle distribution |
debug |
if |
an object of S3 class triangle_mle
containing a list with the call, coefficients,
variance co-variance matrix, minimum negative log likelihood,
number of observations, and the sample
Samuel Kotz and Johan Rene van Dorp. Beyond Beta doi:10.1142/5720
xtest <- c(0.1, 0.25, 0.3, 0.4, 0.45, 0.6, 0.75, 0.8) standard_triangle_mle(xtest) xtest <- rtriangle(20, 0, 1, 0.63) standard_triangle_mle(xtest)
xtest <- c(0.1, 0.25, 0.3, 0.4, 0.45, 0.6, 0.75, 0.8) standard_triangle_mle(xtest) xtest <- rtriangle(20, 0, 1, 0.63) standard_triangle_mle(xtest)
Utility Methods for S3 class triangle_mle
## S3 method for class 'triangle_mle' summary(object, ...) ## S3 method for class 'triangle_mle' print(x, ...) ## S3 method for class 'triangle_mle' coef(object, ...) ## S3 method for class 'triangle_mle' logLik(object, ...) ## S3 method for class 'triangle_mle' AIC(object, ..., k = 2) ## S3 method for class 'triangle_mle' BIC(object, ...) ## S3 method for class 'triangle_mle' vcov(object, ...) ## S3 method for class 'triangle_mle' profile(fitted, ...) ## S3 method for class 'triangle_mle' confint(object, parm, level = 0.95, ...)
## S3 method for class 'triangle_mle' summary(object, ...) ## S3 method for class 'triangle_mle' print(x, ...) ## S3 method for class 'triangle_mle' coef(object, ...) ## S3 method for class 'triangle_mle' logLik(object, ...) ## S3 method for class 'triangle_mle' AIC(object, ..., k = 2) ## S3 method for class 'triangle_mle' BIC(object, ...) ## S3 method for class 'triangle_mle' vcov(object, ...) ## S3 method for class 'triangle_mle' profile(fitted, ...) ## S3 method for class 'triangle_mle' confint(object, parm, level = 0.95, ...)
object |
class triangle_mle from a call to |
... |
not used except for |
x |
the |
k |
the penalty per parameter to be used; the default |
fitted |
an object of class triangle_mle |
parm |
parameters to be given confidence intervals passed to |
level |
confidence interval level passed to |
an object of class summary.mle
print.triangle_mle
: x
invisibly
coef.triangle_mle
: a vector of coefficients
logLik.triangle_mle
: an object of class logLik
AIC.triangle_mle
: the AIC
BIC.triangle_mle
: the BIC
vcov.triangle_mle
: the variance co-variance matrix
profile.triangle_mle
: an object of class profile.mle
confint.triangle_mle
: a matrix of parameter confidence intervals
set.seed(1234) x <- rtriangle(100, 0, 1, 0.5) mle1 <- triangle_mle(x) summary(mle1) print(mle1) coef(mle1) logLik(mle1) AIC(mle1) BIC(mle1) vcov(mle1) ## Not run: prof <- profile(mle1) stats4::plot(prof) confint(mle1, 1:3, level = 0.95) ## End(Not run)
set.seed(1234) x <- rtriangle(100, 0, 1, 0.5) mle1 <- triangle_mle(x) summary(mle1) print(mle1) coef(mle1) logLik(mle1) AIC(mle1) BIC(mle1) vcov(mle1) ## Not run: prof <- profile(mle1) stats4::plot(prof) confint(mle1, 1:3, level = 0.95) ## End(Not run)
These functions provide information about the triangle
distribution on the interval from a
to b
with a maximum at
c
. dtriangle
gives the density, ptriangle
gives the
distribution function, qtriangle
gives the quantile function, and
rtriangle
generates n
random deviates.
dtriangle(x, a = 0, b = 1, c = (a + b)/2) ptriangle(q, a = 0, b = 1, c = (a + b)/2) qtriangle(p, a = 0, b = 1, c = (a + b)/2) rtriangle(n = 1, a = 0, b = 1, c = (a + b)/2)
dtriangle(x, a = 0, b = 1, c = (a + b)/2) ptriangle(q, a = 0, b = 1, c = (a + b)/2) qtriangle(p, a = 0, b = 1, c = (a + b)/2) rtriangle(n = 1, a = 0, b = 1, c = (a + b)/2)
x , q
|
vector of quantiles. |
a |
lower limit of the distribution. |
b |
upper limit of the distribution. |
c |
mode of the distribution. |
p |
vector of probabilities. |
n |
number of observations. If |
All probabilities are lower tailed probabilities.
a
, b
, and c
may be appropriate length vectors except in
the case of rtriangle
. rtriangle
is derived from a draw from
runif
. The triangle distribution has density:
for .
for .
elsewhere.
The mean and variance are:
dtriangle
gives the density, ptriangle
gives the
distribution function, qtriangle
gives the quantile function, and
rtriangle
generates random deviates. Invalid arguments will result
in return value NaN
or NA
.
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
.Random.seed
about random number generation,
runif
, etc for other distributions.
## view the distribution tri <- rtriangle(100000, 1, 5, 3) hist(tri, breaks=100, main="Triangle Distribution", xlab="x") mean(tri) # 1/3*(1 + 5 + 3) = 3 var(tri) # 1/18*(1^2 + 3^2 + 5^2 - 1*5 - 1*3 - 5*3) = 0.666667 dtriangle(0.5, 0, 1, 0.5) # 2/(b-a) = 2 qtriangle(ptriangle(0.7)) # 0.7
## view the distribution tri <- rtriangle(100000, 1, 5, 3) hist(tri, breaks=100, main="Triangle Distribution", xlab="x") mean(tri) # 1/3*(1 + 5 + 3) = 3 var(tri) # 1/18*(1^2 + 3^2 + 5^2 - 1*5 - 1*3 - 5*3) = 0.666667 dtriangle(0.5, 0, 1, 0.5) # 2/(b-a) = 2 qtriangle(ptriangle(0.7)) # 0.7
Triangle parameter estimates using a non-linear fit of the empirical CDF
triangle_cdfe(x, control = stats::nls.control(maxiter = 100, warnOnly = TRUE))
triangle_cdfe(x, control = stats::nls.control(maxiter = 100, warnOnly = TRUE))
x |
the triangle distributed sample |
control |
an object created by |
an object of class nls
set.seed(10304) xtest <- rtriangle(100, 1, 5, 2) cdfe <- triangle_cdfe(xtest) print(cdfe) summary(cdfe) coef(cdfe) ## Not run: confint(cdfe) ## End(Not run)
set.seed(10304) xtest <- rtriangle(100, 1, 5, 2) cdfe <- triangle_cdfe(xtest) print(cdfe) summary(cdfe) coef(cdfe) ## Not run: confint(cdfe) ## End(Not run)
Maximum likelihood estimate of the triangle distribution parameters
triangle_mle(x, debug = FALSE, maxiter = 100)
triangle_mle(x, debug = FALSE, maxiter = 100)
x |
sample from a triangle distribution |
debug |
if |
maxiter |
the maximum number of cycles of optimization between maximizing |
an object of S3 class triangle_mle
containing a list with the call, coefficients,
variance co-variance matrix, minimum negative log likelihood, details of the optimization
number of observations, and the sample
Samuel Kotz and Johan Rene van Dorp. Beyond Beta doi:10.1142/5720
xtest <- c(0.1, 0.25, 0.3, 0.4, 0.45, 0.6, 0.75, 0.8) triangle_mle(xtest) xtest <- rtriangle(20, 1, 5, 3.5) triangle_mle(xtest)
xtest <- c(0.1, 0.25, 0.3, 0.4, 0.45, 0.6, 0.75, 0.8) triangle_mle(xtest) xtest <- rtriangle(20, 1, 5, 3.5) triangle_mle(xtest)
Triangle distribution method of moments estimate
triangle_mom(x)
triangle_mom(x)
x |
triangle distribution sample |
a named vector of the parameter estimates
set.seed(1204) x <- rtriangle(20, 0, 2, 1.5) triangle_mom(x)
set.seed(1204) x <- rtriangle(20, 0, 2, 1.5) triangle_mom(x)