Skip to content

Commit 67d8177

Browse files
committed
Remove .RFunctions submodule
1 parent 111a448 commit 67d8177

File tree

15 files changed

+472
-405
lines changed

15 files changed

+472
-405
lines changed

src/StatsFuns.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module StatsFuns
22

33
using Base: Math.@horner
44
using Reexport: @reexport
5+
using Rmath: Rmath
56
using SpecialFunctions: beta_inc, beta_inc_inv, digamma,
67
erfc, erfcinv, erfcx, gamma_inc, gamma_inc_inv, logbeta, loggamma
78

@@ -264,11 +265,8 @@ export
264265

265266
## source files
266267
include("misc.jl")
267-
include("rmath.jl")
268268
include("tvpack.jl")
269269

270-
using .RFunctions
271-
272270
include("distrs/beta.jl")
273271
include("distrs/binom.jl")
274272
include("distrs/chisq.jl")

src/distrs/beta.jl

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,6 @@
22

33
using HypergeometricFunctions: _₂F₁
44

5-
# R implementations
6-
using .RFunctions:
7-
# betapdf,
8-
# betalogpdf,
9-
# betacdf,
10-
# betaccdf,
11-
# betalogcdf,
12-
# betalogccdf,
13-
# betainvcdf,
14-
# betainvccdf,
15-
betainvlogcdf,
16-
betainvlogccdf
17-
185
# Julia implementations
196
betapdf::Real, β::Real, x::Real) = exp(betalogpdf(α, β, x))
207

@@ -113,3 +100,13 @@ function betainvccdf(α::Real, β::Real, p::Real)
113100

114101
return last(beta_inc_inv(β, α, p))
115102
end
103+
104+
# Rmath implementations
105+
function betainvlogcdf::Real, β::Real, lq::Real)
106+
T = float(Base.promote_typeof(α, β, lq))
107+
return convert(T, Rmath.qbeta(lq, α, β, true, true))
108+
end
109+
function betainvlogccdf::Real, β::Real, lq::Real)
110+
T = float(Base.promote_typeof(α, β, lq))
111+
return convert(T, Rmath.qbeta(lq, α, β, false, true))
112+
end

src/distrs/binom.jl

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
# functions related to binomial distribution
22

3-
# R implementations
4-
using .RFunctions:
5-
# binompdf,
6-
# binomlogpdf,
7-
# binomcdf,
8-
# binomccdf,
9-
# binomlogcdf,
10-
# binomlogccdf,
11-
binominvcdf,
12-
binominvccdf,
13-
binominvlogcdf,
14-
binominvlogccdf
15-
163
# Julia implementations
174
binompdf(n::Real, p::Real, k::Real) = exp(binomlogpdf(n, p, k))
185

@@ -42,3 +29,21 @@ for l in ("", "log"), compl in (false, true)
4229
end
4330
end
4431
end
32+
33+
# Rmath implementations
34+
function binominvcdf(n::Real, p::Real, q::Real)
35+
T = float(Base.promote_typeof(n, p, q))
36+
return convert(T, Rmath.qbinom(q, n, p, true, false))
37+
end
38+
function binominvccdf(n::Real, p::Real, q::Real)
39+
T = float(Base.promote_typeof(n, p, q))
40+
return convert(T, Rmath.qbinom(q, n, p, false, false))
41+
end
42+
function binominvlogcdf(n::Real, p::Real, lq::Real)
43+
T = float(Base.promote_typeof(n, p, lq))
44+
return convert(T, Rmath.qbinom(lq, n, p, true, true))
45+
end
46+
function binominvlogccdf(n::Real, p::Real, lq::Real)
47+
T = float(Base.promote_typeof(n, p, lq))
48+
return convert(T, Rmath.qbinom(lq, n, p, false, true))
49+
end

src/distrs/gamma.jl

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,6 @@
22

33
using HypergeometricFunctions: _₁F₁
44

5-
# R implementations
6-
using .RFunctions:
7-
# gammapdf,
8-
# gammalogpdf,
9-
# gammacdf,
10-
# gammaccdf,
11-
# gammalogcdf,
12-
# gammalogccdf,
13-
# gammainvcdf,
14-
# gammainvccdf,
15-
gammainvlogcdf,
16-
gammainvlogccdf
17-
185
# Julia implementations
196
gammapdf(k::Real, θ::Real, x::Real) = exp(gammalogpdf(k, θ, x))
207

@@ -107,3 +94,13 @@ function gammainvccdf(k::Real, θ::Real, p::Real)
10794
_k, _θ, _p = promote(k, θ, p)
10895
return* gamma_inc_inv(_k, 1 - _p, _p)
10996
end
97+
98+
# Rmath implementations
99+
function gammainvlogcdf(k::Real, θ::Real, lq::Real)
100+
T = float(Base.promote_typeof(k, θ, lq))
101+
return convert(T, Rmath.qgamma(lq, k, θ, true, true))
102+
end
103+
function gammainvlogccdf(k::Real, θ::Real, lq::Real)
104+
T = float(Base.promote_typeof(k, θ, lq))
105+
return convert(T, Rmath.qgamma(lq, k, θ, false, true))
106+
end

src/distrs/hyper.jl

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,45 @@
11
# functions related to hyper-geometric distribution
22

3-
# R implementations
4-
using .RFunctions:
5-
hyperpdf,
6-
hyperlogpdf,
7-
hypercdf,
8-
hyperccdf,
9-
hyperlogcdf,
10-
hyperlogccdf,
11-
hyperinvcdf,
12-
hyperinvccdf,
13-
hyperinvlogcdf,
14-
hyperinvlogccdf
3+
# Rmath implementations
4+
function hyperpdf(ms::Real, mf::Real, n::Real, x::Real)
5+
T = float(Base.promote_typeof(ms, mf, n, x))
6+
return convert(T, Rmath.dhyper(x, ms, mf, n, false))
7+
end
8+
function hyperlogpdf(ms::Real, mf::Real, n::Real, x::Real)
9+
T = float(Base.promote_typeof(ms, mf, n, x))
10+
return convert(T, Rmath.dhyper(x, ms, mf, n, true))
11+
end
12+
13+
function hypercdf(ms::Real, mf::Real, n::Real, x::Real)
14+
T = float(Base.promote_typeof(ms, mf, n, x))
15+
return convert(T, Rmath.phyper(x, ms, mf, n, true, false))
16+
end
17+
function hyperccdf(ms::Real, mf::Real, n::Real, x::Real)
18+
T = float(Base.promote_typeof(ms, mf, n, x))
19+
return convert(T, Rmath.phyper(x, ms, mf, n, false, false))
20+
end
21+
function hyperlogcdf(ms::Real, mf::Real, n::Real, x::Real)
22+
T = float(Base.promote_typeof(ms, mf, n, x))
23+
return convert(T, Rmath.phyper(x, ms, mf, n, true, true))
24+
end
25+
function hyperlogccdf(ms::Real, mf::Real, n::Real, x::Real)
26+
T = float(Base.promote_typeof(ms, mf, n, x))
27+
return convert(T, Rmath.phyper(x, ms, mf, n, false, true))
28+
end
29+
30+
function hyperinvcdf(ms::Real, mf::Real, n::Real, q::Real)
31+
T = float(Base.promote_typeof(ms, mf, n, q))
32+
return convert(T, Rmath.qhyper(q, ms, mf, n, true, false))
33+
end
34+
function hyperinvccdf(ms::Real, mf::Real, n::Real, q::Real)
35+
T = float(Base.promote_typeof(ms, mf, n, q))
36+
return convert(T, Rmath.qhyper(q, ms, mf, n, false, false))
37+
end
38+
function hyperinvlogcdf(ms::Real, mf::Real, n::Real, lq::Real)
39+
T = float(Base.promote_typeof(ms, mf, n, lq))
40+
return convert(T, Rmath.qhyper(lq, ms, mf, n, true, true))
41+
end
42+
function hyperinvlogccdf(ms::Real, mf::Real, n::Real, lq::Real)
43+
T = float(Base.promote_typeof(ms, mf, n, lq))
44+
return convert(T, Rmath.qhyper(lq, ms, mf, n, false, true))
45+
end

src/distrs/nbeta.jl

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,45 @@
11
# functions related to noncentral beta distribution
22

3-
# R implementations
4-
using .RFunctions:
5-
nbetapdf,
6-
nbetalogpdf,
7-
nbetacdf,
8-
nbetaccdf,
9-
nbetalogcdf,
10-
nbetalogccdf,
11-
nbetainvcdf,
12-
nbetainvccdf,
13-
nbetainvlogcdf,
14-
nbetainvlogccdf
3+
# Rmath implementations
4+
function nbetapdf::Real, β::Real, λ::Real, x::Real)
5+
T = float(Base.promote_typeof(α, β, λ, x))
6+
return convert(T, Rmath.dnbeta(x, α, β, λ, false))
7+
end
8+
function nbetalogpdf::Real, β::Real, λ::Real, x::Real)
9+
T = float(Base.promote_typeof(α, β, λ, x))
10+
return convert(T, Rmath.dnbeta(x, α, β, λ, true))
11+
end
12+
13+
function nbetacdf::Real, β::Real, λ::Real, x::Real)
14+
T = float(Base.promote_typeof(α, β, λ, x))
15+
return convert(T, Rmath.pnbeta(x, α, β, λ, true, false))
16+
end
17+
function nbetaccdf::Real, β::Real, λ::Real, x::Real)
18+
T = float(Base.promote_typeof(α, β, λ, x))
19+
return convert(T, Rmath.pnbeta(x, α, β, λ, false, false))
20+
end
21+
function nbetalogcdf::Real, β::Real, λ::Real, x::Real)
22+
T = float(Base.promote_typeof(α, β, λ, x))
23+
return convert(T, Rmath.pnbeta(x, α, β, λ, true, true))
24+
end
25+
function nbetalogccdf::Real, β::Real, λ::Real, x::Real)
26+
T = float(Base.promote_typeof(α, β, λ, x))
27+
return convert(T, Rmath.pnbeta(x, α, β, λ, false, true))
28+
end
29+
30+
function nbetainvcdf::Real, β::Real, λ::Real, q::Real)
31+
T = float(Base.promote_typeof(α, β, λ, q))
32+
return convert(T, Rmath.qnbeta(q, α, β, λ, true, false))
33+
end
34+
function nbetainvccdf::Real, β::Real, λ::Real, q::Real)
35+
T = float(Base.promote_typeof(α, β, λ, q))
36+
return convert(T, Rmath.qnbeta(q, α, β, λ, false, false))
37+
end
38+
function nbetainvlogcdf::Real, β::Real, λ::Real, lq::Real)
39+
T = float(Base.promote_typeof(α, β, λ, lq))
40+
return convert(T, Rmath.qnbeta(lq, α, β, λ, true, true))
41+
end
42+
function nbetainvlogccdf::Real, β::Real, λ::Real, lq::Real)
43+
T = float(Base.promote_typeof(α, β, λ, lq))
44+
return convert(T, Rmath.qnbeta(lq, α, β, λ, false, true))
45+
end

src/distrs/nbinom.jl

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,45 @@
11
# functions related to negative binomial distribution
22

3-
# R implementations
4-
using .RFunctions:
5-
nbinompdf,
6-
nbinomlogpdf,
7-
nbinomcdf,
8-
nbinomccdf,
9-
nbinomlogcdf,
10-
nbinomlogccdf,
11-
nbinominvcdf,
12-
nbinominvccdf,
13-
nbinominvlogcdf,
14-
nbinominvlogccdf
3+
# Rmath implementations
4+
function nbinompdf(r::Real, p::Real, x::Real)
5+
T = float(Base.promote_typeof(r, p, x))
6+
return convert(T, Rmath.dnbinom(x, r, p, false))
7+
end
8+
function nbinomlogpdf(r::Real, p::Real, x::Real)
9+
T = float(Base.promote_typeof(r, p, x))
10+
return convert(T, Rmath.dnbinom(x, r, p, true))
11+
end
12+
13+
function nbinomcdf(r::Real, p::Real, x::Real)
14+
T = float(Base.promote_typeof(r, p, x))
15+
return convert(T, Rmath.pnbinom(x, r, p, true, false))
16+
end
17+
function nbinomccdf(r::Real, p::Real, x::Real)
18+
T = float(Base.promote_typeof(r, p, x))
19+
return convert(T, Rmath.pnbinom(x, r, p, false, false))
20+
end
21+
function nbinomlogcdf(r::Real, p::Real, x::Real)
22+
T = float(Base.promote_typeof(r, p, x))
23+
return convert(T, Rmath.pnbinom(x, r, p, true, true))
24+
end
25+
function nbinomlogccdf(r::Real, p::Real, x::Real)
26+
T = float(Base.promote_typeof(r, p, x))
27+
return convert(T, Rmath.pnbinom(x, r, p, false, true))
28+
end
29+
30+
function nbinominvcdf(r::Real, p::Real, q::Real)
31+
T = float(Base.promote_typeof(r, p, q))
32+
return convert(T, Rmath.qnbinom(q, r, p, true, false))
33+
end
34+
function nbinominvccdf(r::Real, p::Real, q::Real)
35+
T = float(Base.promote_typeof(r, p, q))
36+
return convert(T, Rmath.qnbinom(q, r, p, false, false))
37+
end
38+
function nbinominvlogcdf(r::Real, p::Real, lq::Real)
39+
T = float(Base.promote_typeof(r, p, lq))
40+
return convert(T, Rmath.qnbinom(lq, r, p, true, true))
41+
end
42+
function nbinominvlogccdf(r::Real, p::Real, lq::Real)
43+
T = float(Base.promote_typeof(r, p, lq))
44+
return convert(T, Rmath.qnbinom(lq, r, p, false, true))
45+
end

src/distrs/nchisq.jl

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,45 @@
11
# functions related to noncentral chi-square distribution
22

3-
# R implementations
4-
using .RFunctions:
5-
nchisqpdf,
6-
nchisqlogpdf,
7-
nchisqcdf,
8-
nchisqccdf,
9-
nchisqlogcdf,
10-
nchisqlogccdf,
11-
nchisqinvcdf,
12-
nchisqinvccdf,
13-
nchisqinvlogcdf,
14-
nchisqinvlogccdf
3+
# Rmath implementations
4+
function nchisqpdf(k::Real, λ::Real, x::Real)
5+
T = float(Base.promote_typeof(k, λ, x))
6+
return convert(T, Rmath.dnchisq(x, k, λ, false))
7+
end
8+
function nchisqlogpdf(k::Real, λ::Real, x::Real)
9+
T = float(Base.promote_typeof(k, λ, x))
10+
return convert(T, Rmath.dnchisq(x, k, λ, true))
11+
end
12+
13+
function nchisqcdf(k::Real, λ::Real, x::Real)
14+
T = float(Base.promote_typeof(k, λ, x))
15+
return convert(T, Rmath.pnchisq(x, k, λ, true, false))
16+
end
17+
function nchisqccdf(k::Real, λ::Real, x::Real)
18+
T = float(Base.promote_typeof(k, λ, x))
19+
return convert(T, Rmath.pnchisq(x, k, λ, false, false))
20+
end
21+
function nchisqlogcdf(k::Real, λ::Real, x::Real)
22+
T = float(Base.promote_typeof(k, λ, x))
23+
return convert(T, Rmath.pnchisq(x, k, λ, true, true))
24+
end
25+
function nchisqlogccdf(k::Real, λ::Real, x::Real)
26+
T = float(Base.promote_typeof(k, λ, x))
27+
return convert(T, Rmath.pnchisq(x, k, λ, false, true))
28+
end
29+
30+
function nchisqinvcdf(k::Real, λ::Real, q::Real)
31+
T = float(Base.promote_typeof(k, λ, q))
32+
return convert(T, Rmath.qnchisq(q, k, λ, true, false))
33+
end
34+
function nchisqinvccdf(k::Real, λ::Real, q::Real)
35+
T = float(Base.promote_typeof(k, λ, q))
36+
return convert(T, Rmath.qnchisq(q, k, λ, false, false))
37+
end
38+
function nchisqinvlogcdf(k::Real, λ::Real, lq::Real)
39+
T = float(Base.promote_typeof(k, λ, lq))
40+
return convert(T, Rmath.qnchisq(lq, k, λ, true, true))
41+
end
42+
function nchisqinvlogccdf(k::Real, λ::Real, lq::Real)
43+
T = float(Base.promote_typeof(k, λ, lq))
44+
return convert(T, Rmath.qnchisq(lq, k, λ, false, true))
45+
end

0 commit comments

Comments
 (0)