Skip to content

Commit

Permalink
updated triangle-cdfe options
Browse files Browse the repository at this point in the history
  • Loading branch information
bertcarnell committed Dec 13, 2022
1 parent d5ad16b commit 8672ff5
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ importFrom(stats,coef)
importFrom(stats,ecdf)
importFrom(stats,integrate)
importFrom(stats,nls)
importFrom(stats,nls.control)
importFrom(stats,optim)
importFrom(stats,plot.ecdf)
importFrom(stats,ppoints)
Expand Down
10 changes: 6 additions & 4 deletions R/cdfe.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
#' Triangle parameter estimates using a non-linear fit of the empirical CDF
#'
#' @param x the triangle distributed sample
#' @param control an object created by \code{stats::nls.control}
#'
#' @return an object of class \code{nls}
#' @export
#'
#' @importFrom stats nls
#' @importFrom stats nls nls.control
#'
#' @examples
#' set.seed(10304)
Expand All @@ -17,9 +18,9 @@
#' summary(cdfe)
#' coef(cdfe)
#' \dontrun{
#' MASS::confint(cdfe)
#' confint(cdfe)
#' }
triangle_cdfe <- function(x)
triangle_cdfe <- function(x, control = stats::nls.control(maxiter = 100, warnOnly = TRUE))
{
# x <- rtriangle(100, 0, 1, .3)
n <- length(x)
Expand All @@ -35,6 +36,7 @@ triangle_cdfe <- function(x)
c = 3*mean(x) - minx - maxx),
algorithm = "port",
lower = c(minx - 2*rangex, maxx, minx),
upper = c(minx, maxx + 2*rangex, maxx))
upper = c(minx, maxx + 2*rangex, maxx),
control = control)
return(nls1)
}
2 changes: 1 addition & 1 deletion docs/articles/triangledistributionmath.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ pkgdown: 2.0.6
pkgdown_sha: ~
articles:
triangledistributionmath: triangledistributionmath.html
last_built: 2022-12-12T02:13Z
last_built: 2022-12-13T00:58Z

8 changes: 6 additions & 2 deletions docs/reference/triangle_cdfe.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/triangle_cdfe.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions tests/testthat/test-fit-plots.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
test_that("qqtriangle works", {
xtest <- c(0.1, 0.25, 0.3, 0.4, 0.45, 0.6, 0.75, 0.8)
set.seed(10304)
xtest <- rtriangle(100, 1, 5, 2)
theta <- coef(triangle_mle(xtest))
expect_no_error(qqtriangle(xtest, theta[1], theta[2], theta[3]))
})

test_that("compare_triangle_fit works", {
xtest <- c(0.1, 0.25, 0.3, 0.4, 0.45, 0.6, 0.75, 0.8)
set.seed(10304)
xtest <- rtriangle(100, 1, 5, 2)
expect_no_error(compare_triangle_fit(xtest))
})

0 comments on commit 8672ff5

Please sign in to comment.