-
Couldn't load subscription status.
- Fork 104
Adds Owen's T function #242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| """ | ||
| owens_t(x, a) | ||
|
|
||
| Owen's T function | ||
|
|
||
| Ported from Matlab implementation of John Burkardt, which is distributed under the GNU LGPL license. | ||
|
|
||
| Reference: | ||
| MA Porter, DJ Winstanley, Remark AS R30: A Remark on Algorithm AS76: An Integral Useful in | ||
| Calculating Noncentral T and Bivariate Normal Probabilities, Applied Statistics, Volume 28, | ||
| Number 1, 1979, page 113. | ||
|
|
||
| JC Young, Christoph Minder, Algorithm AS 76: An Algorithm Useful in Calculating Non-Central T and | ||
| Bivariate Normal Distributions, Applied Statistics, Volume 23, Number 3, 1974, pages 455-457. | ||
| """ | ||
| function owens_t(x::Real, a::Real) | ||
| ng = 5 | ||
| r = [0.1477621, 0.1346334, 0.1095432, 0.0747257, 0.0333357] | ||
| tp = 0.159155 | ||
| tv1 = 1.0E-35 | ||
| tv2 = 15.0 | ||
| tv3 = 15.0 | ||
| tv4 = 1.0E-05 | ||
| u = [0.0744372, 0.2166977, 0.3397048, 0.4325317, 0.4869533] | ||
| # Test for X near zero. | ||
| if abs(x) < tv1 | ||
| return tp * atan(a) | ||
| end | ||
| # Test for large values of abs(X). | ||
| if tv2 < abs(x) | ||
| return 0. | ||
| end | ||
| # Test for `a` near zero. | ||
| if abs(a) < tv1 | ||
| return 0. | ||
| end | ||
| # Test whether abs(`a`) is so large that it must be truncated. | ||
| xs = -0.5 * x * x | ||
| x2 = a | ||
| fxs = a * a | ||
| # Computation of truncation point by Newton iteration. | ||
| if tv3 <= log(1.0 + fxs) - xs * fxs | ||
| x1 = 0.5 * a | ||
| fxs = 0.25 * fxs | ||
| while true | ||
| rt = fxs + 1. | ||
| x2 = x1 + (xs * fxs + tv3 - log(rt)) / (2. * x1 * ( 1. / rt - xs)) | ||
| fxs = x2 * x2 | ||
| if abs(x2 - x1) < tv4 | ||
| break | ||
| end | ||
| x1 = x2 | ||
| end | ||
| end | ||
| # Gaussian quadrature. | ||
| rt = 0.0 | ||
| for i in 1:ng | ||
| r1 = 1.0 + fxs * (0.5 + u[i])^2 | ||
| r2 = 1.0 + fxs * (0.5 - u[i])^2 | ||
| rt = rt + r[i] * (exp(xs * r1) / r1 + exp(xs * r2) / r2) | ||
| end | ||
| return rt * x2 * tp | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| @testset "Owen's T function" begin | ||
| @test all(owens_t.(-3:0.1:3, 0) .== 0.) | ||
| @test all(isapprox.(owens_t.(0, -3:0.1:3), 1 ./ (2 .* pi) .* atan.(-3:0.1:3), rtol=1e-6)) | ||
| @test all(isapprox.([owens_t(-h, a) for h in -3:0.1:3, a in -3:0.1:3], [owens_t(h, a) for h in -3:0.1:3, a in -3:0.1:3], rtol=1e-6)) | ||
| @test all(isapprox.([owens_t(h, -a) for h in -3:0.1:3, a in -3:0.1:3], [-owens_t(h, a) for h in -3:0.1:3, a in -3:0.1:3], rtol=1e-6)) | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more restrictive than the SpecialFunctions.jl license, which also disqualifies anything derived from that code.