Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • b7953a0
  • /
  • deartstest.jl
Raw File Download
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:35529715524d6a11adee135c570631f87de2f20d
directory badge Iframe embedding
swh:1:dir:b7953a0181984616831ccdfbbba622e10eb82cca
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
deartstest.jl

# This file contains functions for the DEA Returns to Scale Test
struct DEAReturnsToScaleTest
    nreps::Int        
    S::Float64
    SB::Vector{Float64}    
    p::Float64 
    h::Float64
end

"""
    deartstest(X, Y)
Compute the DEA Returns to Scale (RTS) test using the bootstrap radial model for inputs X and outputs Y.

# Optional Arguments
- `nreps=200`: number of bootstrap replications.
- `rng=default_rng()`: random number generator.
- `orient=:Input`: chooses the radially oriented input mode. For the radially oriented output model choose `:Output`.
"""
function deartstest(X::Union{Matrix,Vector}, Y::Union{Matrix,Vector}; 
    orient::Symbol = :Input, nreps::Int = 200, rng::AbstractRNG = default_rng())::DEAReturnsToScaleTest

    # Observed S
    crs = efficiency(dea(X, Y, rts = :CRS, orient = orient))
    vrs = efficiency(dea(X, Y, rts = :VRS, orient = orient))

    S = 0
    if orient == :Input
        S = sum(crs) / sum(vrs)
    else
        S = sum(1 ./ crs) / sum(1 ./ vrs)
    end

    # Bootstrapped S
    rng2 = deepcopy(rng)

    crsboot = deaboot(X, Y, orient = orient, rts = :CRS, nreps = nreps, rng = rng)
    crsB = crsboot.effB

    vrsboot = deaboot(X, Y, orient = orient, rts = :VRS, nreps = nreps, rng = rng2, effref = crs)
    vrsB = vrsboot.effB

    if orient == :Input
        SB = sum(crsB, dims = 1) ./ sum(vrsB, dims = 1)
    else
        SB = sum(1 ./ crsB, dims = 1) ./ sum(1 ./ vrsB, dims = 1)
    end
    SB = vec(SB)

    lower = sum(SB .< S)
    p = (lower + 1) / nreps

    return DEAReturnsToScaleTest(nreps, S, SB, p, crsboot.h)
end

"""
    criticalvalue(model::BootstrapRadialDEAModel, alpha = 0.05)
Return the critical value of the DEA Returns to Scale Test, with level `alpha`.
"""
function criticalvalue(x::DEAReturnsToScaleTest, alpha ::Float64 = 0.05)
    SB = x.SB
    nreps = x.nreps

    SBsorted = sort(SB)
    critval = mean( SBsorted[Int.([floor(alpha * nreps), 
                                   ceil(alpha * nreps)])] )
    return critval
end

function Base.show(io::IO, x::DEAReturnsToScaleTest)
    compact = get(io, :compact, false)

    nreps = x.nreps    
    S = x.S
    p = x.p
    h = x.h
    alpha = 0.05
    critval = criticalvalue(x, alpha)

    if !compact
        print(io, "DEA Returns to Scale (RTS) Test \n")
        print(io, "--------------------------------\n")
        print(io, "\n")
        print(io, "  H0: Globally CRS \n")
        print(io, "  H1: VRS \n")
        print(io, "\n")
        print(io, "  Bootstrap replications: ", nreps, "\n")
        print(io, "  Bandwidth = ", round(h, digits = 5), "\n")
        print(io, "\n")
        print(io, "  Scale efficiency: ", round(S, digits = 4), "\n")
        print(io, "  Critical value (α = $alpha): ", round(critval, digits = 4), "\n")
        print(io, "  p-value: ", round(p, digits = 4), "\n")
    end

end

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API