| Type: | Package |
| Title: | Owen's T Function and Bivariate Normal Integral |
| Version: | 1.1.0 |
| Date: | 2026-11-30 |
| Depends: | R (≥ 3.5.0), stats |
| Imports: | Rmpfr |
| Suggests: | JuliaConnectoR, JuliaCall |
| Description: | Computes Owen's T function or the bivariate normal integral using one of the following methods: the modified Euler's arctangent series, tetrachoric series, or Vasicek's series. For the methodology, see Komelj, J. (2023) <doi:10.4236/ajcm.2023.134026>, or the revised post-print version with corrected contents and improved typography at <doi:10.48550/arXiv.2312.00011>. Also see the alternative approach by Vasicek, O. A. (1998) <doi:10.21314/JCF.1998.015>. |
| License: | GPL-2 | GPL-3 |
| NeedsCompilation: | no |
| Packaged: | 2026-11-30 19:12:02 UTC; jkome |
| Author: | Janez Komelj |
| Maintainer: | Janez Komelj <jkomelj@siol.net> |
| Repository: | CRAN |
| Date/Publication: | 2026-11-30 21:20:02 UTC |
Owen's T Function and Bivariate Normal Integral
Description
Computes the Owen's T function or the bivariate normal integral.
Details
The DESCRIPTION file:
Package: Phi2rho
Type: Package
Title: Owen's T Function and Bivariate Normal Integral
Version: 1.1.0
Date: 2026-11-30
Authors@R: person("Janez", "Komelj", role = c("aut", "cre"),
email = "jkomelj@siol.net",
comment = c(ORCID = "0009-0002-3474-2654"))
Depends: R (>= 3.5.0), stats
Imports: Rmpfr
Suggests: JuliaConnectoR, JuliaCall
Description: Computes Owen's T function or the bivariate normal
integral using one of the following methods: the modified
Euler's arctangent series, tetrachoric series, or Vasicek's
series. For the methodology, see Komelj, J. (2023)
<doi:10.4236/ajcm.2023.134026>, or the revised post-print
version with corrected contents and improved typography at
<doi:10.48550/arXiv.2312.00011>. Also see the alternative
approach by Vasicek, O. A. (1998) <doi:10.21314/JCF.1998.015>.
License: GPL-2 | GPL-3
Note
Both OwenT and Phi2xy functions are ready to work with arbitrary-precision numbers as well as standard double-precision ones. Arbitrary-precision computations require that all arbitrary-precision input arguments have class ‘mpfr’ and share the same precision. Computations can be configured using the following options:
-
options(Phi2rho.engine = "Rmpfr")
The default engine, where calculations are performed entirely within R. It automatically dispatches the workload: standard double-precision arguments are evaluated using native R code, whereas ‘mpfr’ arguments are processed via the Rmpfr package. -
options(Phi2rho.engine = "JuliaFast")
An optional Julia engine powered by the JuliaCall package. It embeds Julia directly into the shared library space of the current R process. For standard double-precision (Float64) computations, it enables zero-allocation memory sharing by passing arguments by reference using direct C pointers, which eliminates data transfer overhead and maximizes performance. For arbitrary-precision computations, although the Rmpfr package (in R) andBigFloat(in Julia) both utilize the same underlying MPFR C library, they rely on different memory formats. Consequently, arguments and results are transferred between R and Julia via a hexadecimal text conversion. While this ensures no loss of precision, it makes the data transfer slower compared to standard precision. -
options(Phi2rho.engine = "JuliaSafe")
An optional Julia engine powered by the JuliaConnectoR package. It establishes a local TCP/IP socket connection to a separate, isolated Julia process. While ideal for safe debugging, this architecture makes communication significantly slower thanJuliaFastdue to the serialization overhead when transferring data between R and Julia. -
options(Phi2rho.double64 = FALSE)
When set toTRUE, this feature utilizes theDouble64type from the DoubleFloats package instead ofBigFloat, offering substantially faster execution with an effective precision of about 104 bits. This is effective exclusively when a Julia engine is active and the precision level of the ‘mpfr’ numbers is between 54 and 106 bits inclusive. While internal calculations usingDouble64are performed in this format across the entire precision interval, the returned ‘mpfr’ result is rounded back to the requested input precision.
Regardless of the chosen Julia engine, the internal evaluation type is automatically selected: standard double-precision arguments are computed using native Float64 hardware-accelerated types, whereas ‘mpfr’ numbers are converted into BigFloat objects for fast arbitrary-precision evaluation (unless overridden by the Phi2rho.double64 = TRUE option).
Note that the Rmpfr package is strictly required for arbitrary-precision computations. When running a Julia engine, the core computational pipeline is handled entirely internally by Julia, which independently executes all preprocessing, pnorm() evaluations, and core computations. The Rmpfr package is then utilized solely for initial argument preparation, data formatting, and final result reconstruction, while also serving as an essential fallback component.
Due to the initial just-in-time (JIT) compilation overhead in Julia, using the Julia engines may not be optimal for a small number of arbitrary-precision (‘mpfr’) calculations. It becomes highly beneficial and significantly faster when performing a larger volume of arbitrary-precision computations, where the compilation cost is quickly amortized.
Conversely, for standard double-precision (Float64) computations, the Rmpfr package is not utilized for evaluation. While the execution time within Julia itself is identical for both engines, the "JuliaFast" option provides significantly lower latency and communication overhead compared to "JuliaSafe" for large-scale datasets, due to its direct shared-memory management.
To eliminate the JIT compilation delay from the first active evaluation, the package features an automated initialization routine. A silent, dedicated warm-up sequence is automatically triggered upon the first activation of either the "JuliaSafe" or "JuliaFast" engine – either during package startup if pre-configured, or dynamically when switching the engine option later in the session – ensuring the respective internal Julia environments are pre-compiled and ready for immediate full-speed execution.
To use the "JuliaFast" or "JuliaSafe" engines, a working installation of Julia must be available on the system and discoverable by R (either via the system PATH or by explicitly setting the JULIA_BINDIR environment variable prior to initializing the engine). By default, Julia uses only a single worker thread; to enable multi-threaded execution, set the JULIA_NUM_THREADS environment variable before starting the engine (e.g., via Sys.setenv(JULIA_NUM_THREADS = "auto")).
Additionally, a complete, fully standalone Julia implementation is included within the ‘julia’ directory of the installed package space. Advanced users can run the entire high-performance computational pipeline directly inside a native Julia session, completely independent of R, using the source files ‘owent.jl’ and ‘Phi2xy.jl’ as the native entry points.
It is important to note that the core worker functions (mowent, towent, and vowent) function strictly as internal numerical engines and are never intended to be called directly by the user. When running a Julia engine, calculations are initiated via high-level Julia entry points which mirror the R functions, ensuring that argument preprocessing and execution flow remain completely within the Julia environment.
Although data transfer between R and Julia incurs no loss of precision, numerical results obtained in R (using standard double precision) and Julia (using Float64) are not always identical down to the last bit. The same holds for arbitrary-precision computations exceeding 53 bits performed with Rmpfr versus Julia's BigFloat; while MPFR guarantees correct rounding for elementary functions, minor discrepancies still arise from operation ordering and intermediate rounding in composite expressions (such as series summation and the cumulative normal distribution). Future versions may incorporate internal guard bits and Ziv's strategy for BigFloat evaluations in Julia to ensure correctly rounded results.
Author(s)
Janez Komelj
Maintainer: Janez Komelj <jkomelj@siol.net>
References
Komelj, J. (2023): The Bivariate Normal Integral via Owen's T Function as a Modified Euler's Arctangent Series, American Journal of Computational Mathematics, 13, 4, 476–504, doi:10.4236/ajcm.2023.134026, or the revised postprint version with corrected contents and improved typography at doi:10.48550/arXiv.2312.00011.
Owen, D. B. (1956): Tables for Computing Bivariate Normal Probabilities, The Annals of Mathematical Statistics, 27, 4, 1075–1090, doi:10.1214/aoms/1177728074.
Owen, D. B. (1980): A table of normal integrals, Communications in Statistics – Simulation and Computation, 9, 4, 389–419, doi:10.1080/03610918008812164.
Vasicek, O. A. (1998): A series expansion for the bivariate normal integral, The Journal of Computational Finance, 1, 4, 5–10, doi:10.21314/JCF.1998.015.
Examples
OwenT(2, 0.5)
OwenT(2, 0.5, fun = "mOwenT") # modified arctangent series (default)
OwenT(2, 0.5, fun = "tOwenT") # tetrachoric series
OwenT(2, 0.5, fun = "vOwenT") # Vasicek's series
rho <- 0.6
a <- rho/sqrt(1 - rho^2)
OwenT(0.3, a)
OwenT(0.3, a, fun = "tOwenT")
OwenT(c(-1, 0.5, 4), a, fun = "vOwenT")
OwenT(2, c(-1, -0.5, 0, 0.5, 1), fun = "vOwenT")
Phi2xy(2, 1.3, 0.5)
Phi2xy(-2, 0.5, -0.3, fun = "tOwenT")
Phi2xy(c(1, 2, -1.5), c(-1, 1, 2.3), 0.5, fun = "vOwenT")
Phi2xy(1, 2, c(-1, -0.5, 0, 0.5, 1))
Phi2xy(c(1, 2), c(-1,3), c(-0.5, 0.8))
## Not run:
# --- Examples of arbitrary-precision engine configuration ---
prec <- 256
rho <- 0.6
# 1) Using the optional Julia engine:
# Note: For short arguments, this is for demonstration only, as the
# computational benefit of Julia is realized with larger workloads.
options(Phi2rho.engine = "JuliaFast")
h_mpfr <- mpfr(c(-1, 0.5, 4), precBits = prec)
a_mpfr <- mpfr(rho/sqrt(1 - rho^2), precBits = prec)
OwenT(h_mpfr, a_mpfr)
x_mpfr <- mpfr(c(1, 2, -1.5), precBits = prec)
y_mpfr <- mpfr(c(-1, 1, 2.3), precBits = prec)
rho_mpfr <- mpfr(rho, precBits = prec)
Phi2xy(x_mpfr, y_mpfr, rho_mpfr, fun = "vOwenT")
# 2) Switching back to the default Rmpfr engine:
# (Useful to switch back, as 'Rmpfr' is already the package default)
options(Phi2rho.engine = "Rmpfr")
OwenT(mpfr(2, precBits = prec), mpfr(0.5, precBits = prec))
Phi2xy(mpfr(2, precBits = prec), mpfr(1.3, precBits = prec), mpfr(rho, precBits = prec))
## End(Not run)
Owen's T Function
Description
Computes Owen's T function using the modified Euler's arctangent series, tetrachoric series or Vasicek's series. Includes user-configurable controls for maximum iterations and silent modes to safeguard extreme numerical edge cases.
Usage
OwenT(h, a, opt = TRUE, fun = c("mOwenT", "tOwenT", "vOwenT"))
Arguments
h |
Numeric scalar or vector. |
a |
Numeric scalar or vector. |
opt |
If TRUE, an optimized calculation is performed. |
fun |
The name of the internal function being used. |
Details
If h and a are both vectors, they must be of the same length. If one of h and a is a vector and the other is a scalar, the latter is replicated to the length of the former. The calculation is performed component-wise.
The parameter fun specifies which series is used:
- “mOwenT”:
modified Euler's arctangent series (default).
- “tOwenT”:
tetrachoric series.
- “vOwenT”:
Vasicek's series.
The opt parameter enables verification of results in the published article; otherwise, it is no longer necessary and may be removed at a later date.
If fun = "mOwenT" and opt = TRUE, the external arctangent function is used, otherwise all necessary values are calculated on the fly, but usually more iterations are needed.
If fun = "tOwenT" or fun = "vOwenT", and opt = TRUE, then the parameters transformation is performed when it makes sense, which significantly reduces the number of iterations.
The maximum number of allowed iterations can be controlled globally via options(Phi2rho.maxIter = value), which defaults to 5000. If a component fails to converge within this limit, its iteration counter in the ‘nIter’ attribute is set to -1 and a warning is issued. Warnings can be suppressed globally by setting options(Phi2rho.silent = TRUE).
Value
The value of computed function is returned, scalar or vector. The attribute ‘nIter’ of returned value means the number of iterations. If a component does not converge within the maximum iteration limit, its ‘nIter’ value is set to -1.
Note
Function is ready to work with arbitrary precision numbers via the Rmpfr package, as well as standard double precision numbers. Assuming Rmpfr is loaded, it is sufficient to be called with parameters ‘h’ and ‘a’, which have class ‘mpfr’ and the same precision. Alternatively, computations for both precision types can be performed via the Julia engine. When processing ‘mpfr’ arguments, Julia handles them using high-performance BigFloat structures in combination with internal Rmpfr layers; for standard numbers, it utilizes native hardware-accelerated Float64 types. For configuration details and performance considerations, see the ‘Note’ section in Phi2rho-package.
Author(s)
Janez Komelj
References
Komelj, J. (2023): The Bivariate Normal Integral via Owen's T Function as a Modified Euler's Arctangent Series, American Journal of Computational Mathematics, American Journal of Computational Mathematics, 13, 4, 476–504, doi:10.4236/ajcm.2023.134026, or the revised postprint version with corrected contents and improved typography at doi:10.48550/arXiv.2312.00011.
Owen, D. B. (1956): Tables for Computing Bivariate Normal Probabilities, The Annals of Mathematical Statistics, 27, 4, 1075–1090, doi:10.1214/aoms/1177728074.
Owen, D. B. (1980): A table of normal integrals, Communications in Statistics – Simulation and Computation, 9, 4, 389–419, doi:10.1080/03610918008812164.
See Also
Examples
OwenT(2, 0.5)
OwenT(2, 0.5, fun = "mOwenT") # modified arctangent series (default)
OwenT(2, 0.5, fun = "tOwenT") # tetrachoric series
OwenT(2, 0.5, fun = "vOwenT") # Vasicek's series
rho <- 0.6
a <- rho/sqrt(1 - rho^2)
OwenT(0.3, a)
OwenT(0.3, a, fun = "tOwenT")
OwenT(c(-1, 0.5, 4), a, fun = "vOwenT")
OwenT(2, c(-1, -0.5, 0, 0.5, 1), fun = "vOwenT")
## Not run:
# --- Examples of high-precision engine configuration ---
prec <- 256
rho <- 0.6
# 1) Using the optional Julia engine:
# Note: For short arguments, this is for demonstration only, as the
# computational benefit of Julia is realized with larger workloads.
options(Phi2rho.engine = "JuliaFast")
h_mpfr <- mpfr(c(-1, 0.5, 4), precBits = prec)
a_mpfr <- mpfr(rho/sqrt(1 - rho^2), precBits = prec)
OwenT(h_mpfr, a_mpfr)
# 2) Switching back to the default Rmpfr engine:
# (Useful to switch back, as 'Rmpfr' is already the package default)
options(Phi2rho.engine = "Rmpfr")
OwenT(mpfr(2, precBits = prec), mpfr(0.5, precBits = prec))
## End(Not run)
Bivariate Normal Integral
Description
Computes the bivariate normal integral Phi2(x, y, rho).
Usage
Phi2xy(x, y, rho, opt = TRUE, fun = c("mOwenT", "tOwenT", "vOwenT"))
Arguments
x |
Numeric scalar or vector. |
y |
Numeric scalar or vector. |
rho |
Numeric scalar or vector. |
opt |
If TRUE, an optimized calculation is performed. |
fun |
The name of the internal function being used. |
Details
The parameter ‘rho’ (or at least one of its components) must be from the interval [-1,1].
Vector parameters must be of the same length, and any scalar parameters are replicated to the same length. The calculation is performed component-wise.
The parameter fun specifies which series is used:
- “mOwenT”:
modified Euler's arctangent series (default).
- “tOwenT”:
tetrachoric series.
- “vOwenT”:
Vasicek's series.
The opt parameter enables checking the results in the submitted article and may be dropped later.
If fun = "mOwenT" and opt = TRUE, the external arctangent function is used, otherwise all necessary values are calculated on the fly, but usually more iterations are needed.
If fun = "tOwenT" or fun = "vOwenT", and opt = TRUE, then the parameters transformation is performed when it makes sense, which significantly reduces the number of iterations.
The maximum number of allowed iterations can be controlled globally via options(Phi2rho.maxIter = value), which defaults to 5000. If a component fails to converge within this limit, its iteration counter in the ‘nIter’ attribute is set to -1 and a warning is issued. Warnings can be suppressed globally by setting options(Phi2rho.silent = TRUE).
Value
The value of computed function is returned, scalar or vector. The attribute ‘nIter’ of returned value means the number of iterations. If a component does not converge within the maximum iteration limit, its ‘nIter’ value is set to -1.
Note
Function is ready to work with arbitrary precision numbers via the Rmpfr package, as well as standard double precision numbers. Assuming Rmpfr is loaded, it is sufficient to be called with parameters ‘x’, ‘y’ and ‘rho’, which have class ‘mpfr’ and the same precision. Alternatively, computations for both precision types can be performed via the Julia engine. When processing ‘mpfr’ arguments, Julia handles them using high-performance BigFloat structures in combination with internal Rmpfr layers; for standard numbers, it utilizes native hardware-accelerated Float64 types. For configuration details and performance considerations, see the ‘Note’ section in Phi2rho-package.
Author(s)
Janez Komelj
References
Komelj, J. (2023): The Bivariate Normal Integral via Owen's T Function as a Modified Euler's Arctangent Series, American Journal of Computational Mathematics, 13, 4, 476–504, doi:10.4236/ajcm.2023.134026, or the revised postprint version with corrected contents and improved typography at doi:10.48550/arXiv.2312.00011.
Owen, D. B. (1956): Tables for Computing Bivariate Normal Probabilities, The Annals of Mathematical Statistics, 27, 4, 1075–1090, doi:10.1214/aoms/1177728074.
Owen, D. B. (1980): A table of normal integrals, Communications in Statistics – Simulation and Computation, 9, 4, 389–419, doi:10.1080/03610918008812164.
See Also
Examples
Phi2xy(2, 1.3, 0.5)
Phi2xy(-2, 0.5, -0.3, fun = "tOwenT")
Phi2xy(c(1, 2, -1.5), c(-1, 1, 2.3), 0.5, fun = "vOwenT")
Phi2xy(1, 2, c(-1, -0.5, 0, 0.5, 1))
Phi2xy(c(1, 2), c(-1,3), c(-0.5, 0.8))
## Not run:
# --- Examples of high-precision engine configuration ---
prec <- 256
rho <- 0.5
# 1) Using the optional Julia engine:
# Note: For short arguments, this is for demonstration only, as the
# computational benefit of Julia is realized with larger workloads.
options(Phi2rho.engine = "JuliaFast")
x_mpfr <- mpfr(c(1, 2, -1.5), precBits = prec)
y_mpfr <- mpfr(c(-1, 1, 2.3), precBits = prec)
rho_mpfr <- mpfr(rho, precBits = prec)
Phi2xy(x_mpfr, y_mpfr, rho_mpfr, fun = "vOwenT")
# 2) Switching back to the default Rmpfr engine:
# (Useful to switch back, as 'Rmpfr' is already the package default)
options(Phi2rho.engine = "Rmpfr")
Phi2xy(mpfr(2, precBits = prec), mpfr(1.3, precBits = prec), rho_mpfr)
## End(Not run)