Skip to content

Commit

Permalink
Remove reference sets in economic efficiency models.
Browse files Browse the repository at this point in the history
Remove the parameters for seting a different reference set in economic efficiency models.
  • Loading branch information
javierbarbero committed Oct 1, 2019
1 parent 9a86b52 commit 8f227f2
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 287 deletions.
50 changes: 14 additions & 36 deletions src/deacost.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,45 +46,29 @@ Orientation = Input; Returns to Scale = VRS
──────────────────────────────────
```
"""
function deacost(X::Matrix, Y::Matrix, W::Matrix; rts::Symbol = :VRS, Xref::Matrix = X, Yref::Matrix = Y, Wref::Matrix = W)::CostDEAModel
function deacost(X::Matrix, Y::Matrix, W::Matrix; rts::Symbol = :VRS)::CostDEAModel
# Check parameters
nx, m = size(X)
ny, s = size(Y)

nw, mw = size(W)

nrefx, mref = size(Xref)
nrefy, sref = size(Yref)

if nx != ny
error("number of observations is different in inputs and outputs")
end
if nw != nx
error("number of observations is different in input prices and inputs")
end
if mw != m
error("number of input prices and intputs is different")
end
if nrefx != nrefy
error("number of observations is different in inputs reference set and ouputs reference set")
end
if m != mref
error("number of inputs in evaluation set and reference set is different")
end
if s != sref
error("number of outputs in evaluation set and reference set is different")
end
if size(Wref) != size(Xref)
error("size of reference prices for inputs should be equal to size of reference inputs")
error("number of input prices and intputs is different")
end

# Compute efficiency for each DMU
n = nx
nref = nrefx


Xefficient = zeros(n,m)
cefficiency = zeros(n)
clambdaeff = spzeros(n, nref)
clambdaeff = spzeros(n, n)

for i=1:n
# Value of inputs and outputs to evaluate
Expand All @@ -94,12 +78,12 @@ function deacost(X::Matrix, Y::Matrix, W::Matrix; rts::Symbol = :VRS, Xref::Matr
# Create the optimization model
deamodel = Model(with_optimizer(GLPK.Optimizer))
@variable(deamodel, Xeff[1:m])
@variable(deamodel, lambda[1:nref] >= 0)
@variable(deamodel, lambda[1:n] >= 0)

@objective(deamodel, Min, sum(w0[j] .* Xeff[j] for j in 1:m))

@constraint(deamodel, [j in 1:m], sum(Xref[t,j] * lambda[t] for t in 1:nref) <= Xeff[j])
@constraint(deamodel, [j in 1:s], sum(Yref[t,j] * lambda[t] for t in 1:nref) >= y0[j])
@constraint(deamodel, [j in 1:m], sum(X[t,j] * lambda[t] for t in 1:n) <= Xeff[j])
@constraint(deamodel, [j in 1:s], sum(Y[t,j] * lambda[t] for t in 1:n) >= y0[j])

# Add return to scale constraints
if rts == :CRS
Expand All @@ -120,34 +104,28 @@ function deacost(X::Matrix, Y::Matrix, W::Matrix; rts::Symbol = :VRS, Xref::Matr

# Cost, technical and allocative efficiency
cefficiency = vec( sum(W .* Xefficient, dims = 2) ./ sum(W .* X, dims = 2) )
techefficiency = efficiency(dea(X, Y, orient = :Input, rts = rts, Xref = Xref, Yref = Yref, slack = false))
techefficiency = efficiency(dea(X, Y, orient = :Input, rts = rts, slack = false))
allocefficiency = cefficiency ./ techefficiency
return CostDEAModel(n, m, s, rts, cefficiency, clambdaeff, techefficiency, allocefficiency)

end

function deacost(X::Vector, Y::Matrix, W::Vector, rts::Symbol = :VRS, Xref::Vector = X, Yref::Matrix = Y, Wref::Vector = W)::CostDEAModel
function deacost(X::Vector, Y::Matrix, W::Vector, rts::Symbol = :VRS)::CostDEAModel
X = X[:,:]
Xref = Xref[:,:]
W = W[:,:]
Wref = Wref[:,:]
return deacost(X, Y, W, rts = rts, Xref = Xref, Yref = Yref, Wref = Wref)
return deacost(X, Y, W, rts = rts)
end

function deacost(X::Matrix, Y::Vector, W::Matrix; rts::Symbol = :VRS, Xref::Matrix = X, Yref::Vector = Y, Wref::Matrix = W)::CostDEAModel
function deacost(X::Matrix, Y::Vector, W::Matrix; rts::Symbol = :VRS)::CostDEAModel
Y = Y[:,:]
Yref = Yref[:,:]
return deacost(X, Y, W, rts = rts, Xref = Xref, Yref = Yref, Wref = Wref)
return deacost(X, Y, W, rts = rts)
end

function deacost(X::Vector, Y::Vector, W::Vector; rts::Symbol = :VRS, Xref::Vector = X, Yref::Vector = Y, Wref::Vector = W)::CostDEAModel
function deacost(X::Vector, Y::Vector, W::Vector; rts::Symbol = :VRS)::CostDEAModel
X = X[:,:]
Xref = Xref[:,:]
W = W[:,:]
Wref = Wref[:,:]
Y = Y[:,:]
Yref = Yref[:,:]
return deacost(X, Y, W, rts = rts, Xref = Xref, Yref = Yref, Wref = Wref)
return deacost(X, Y, W, rts = rts)
end

function Base.show(io::IO, x::CostDEAModel)
Expand Down
60 changes: 20 additions & 40 deletions src/deaprofit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,55 +53,43 @@ Returns to Scale = VRS
─────────────────────────────────────
```
"""
function deaprofit(X::Matrix, Y::Matrix, W::Matrix, P::Matrix, Gx::Matrix, Gy::Matrix; Xref::Matrix = X, Yref::Matrix = Y, Wref::Matrix = W, Pref::Matrix = P)::ProfitDEAModel
function deaprofit(X::Matrix, Y::Matrix, W::Matrix, P::Matrix, Gx::Matrix, Gy::Matrix)::ProfitDEAModel
# Check parameters
nx, m = size(X)
ny, s = size(Y)

nw, mw = size(W)
np, sp = size(P)

nrefx, mref = size(Xref)
nrefy, sref = size(Yref)

if nx != ny
error("number of observations is different in inputs and outputs")
end
if nw != nx
error("number of observations is different in input prices and inputs")
end
if np != ny
error("number of observations is different in output prices and outputs")
end
if sp != s
error("number of output prices and outputs is different")
end
if nrefx != nrefy
error("number of observations is different in inputs reference set and ouputs reference set")
if mw != m
error("number of input prices and intputs is different")
end
if m != mref
error("number of inputs in evaluation set and reference set is different")
end
if s != sref
error("number of outputs in evaluation set and reference set is different")
if sp != s
error("number of output prices and outputs is different")
end
if size(Gx) != size(X)
error("size of inputs should be equal to size of inputs direction")
end
if size(Gy) != size(Y)
error("size of outputs should be equal to size of outputs direction")
end
if size(Wref) != size(Xref)
error("size of reference prices for inputs should be equal to size of reference inputs")
end
if size(Pref) != size(Yref)
error("size of reference prices for outputs should be equal to size of reference outputs")
end

# Compute efficiency for each DMU
n = nx
nref = nrefx

Xefficient = zeros(n,m)
Yefficient = zeros(n,m)
pefficiency = zeros(n)
plambdaeff = spzeros(n, nref)
plambdaeff = spzeros(n, n)

for i=1:n
# Value of inputs and outputs to evaluate
Expand All @@ -112,12 +100,12 @@ function deaprofit(X::Matrix, Y::Matrix, W::Matrix, P::Matrix, Gx::Matrix, Gy::M
deamodel = Model(with_optimizer(GLPK.Optimizer))
@variable(deamodel, Xeff[1:m])
@variable(deamodel, Yeff[1:m])
@variable(deamodel, lambda[1:nref] >= 0)
@variable(deamodel, lambda[1:n] >= 0)

@objective(deamodel, Max, (sum(p0[j] .* Yeff[j] for j in 1:s)) - (sum(w0[j] .* Xeff[j] for j in 1:m)))

@constraint(deamodel, [j in 1:m], sum(Xref[t,j] * lambda[t] for t in 1:nref) <= Xeff[j])
@constraint(deamodel, [j in 1:s], sum(Yref[t,j] * lambda[t] for t in 1:nref) >= Yeff[j])
@constraint(deamodel, [j in 1:m], sum(X[t,j] * lambda[t] for t in 1:n) <= Xeff[j])
@constraint(deamodel, [j in 1:s], sum(Y[t,j] * lambda[t] for t in 1:n) >= Yeff[j])

@constraint(deamodel, sum(lambda) == 1)

Expand All @@ -137,43 +125,35 @@ function deaprofit(X::Matrix, Y::Matrix, W::Matrix, P::Matrix, Gx::Matrix, Gy::M
pefficiency_den = sum(P .* Gy, dims = 2) .+ sum(W .* Gx, dims = 2)
pefficiency = vec( pefficiency_num ./ pefficiency_den )

techefficiency = efficiency(deaddf(X, Y, Gx, Gy, rts = :VRS, Xref = Xref, Yref = Yref, slack = false))
techefficiency = efficiency(deaddf(X, Y, Gx, Gy, rts = :VRS, slack = false))
allocefficiency = pefficiency - techefficiency

return ProfitDEAModel(n, m, s, pefficiency, plambdaeff, techefficiency, allocefficiency)

end

function deaprofit(X::Vector, Y::Matrix, W::Vector, P::Matrix, Gx::Vector, Gy::Matrix; Xref::Vector = X, Yref::Matrix = Y, Wref::Vector = W, Pref::Matrix = P)::ProfitDEAModel
function deaprofit(X::Vector, Y::Matrix, W::Vector, P::Matrix, Gx::Vector, Gy::Matrix)::ProfitDEAModel
X = X[:,:]
Xref = Xref[:,:]
W = W[:,:]
Wref = Wref[:,:]
Gx = Gx[:,:]
return deaprofit(X, Y, W, P, Gx, Gy, Xref = Xref, Yref = Yref, Wref = Wref, Pref = Pref)
return deaprofit(X, Y, W, P, Gx, Gy)
end

function deaprofit(X::Matrix, Y::Vector, W::Matrix, P::Vector, Gx::Matrix, Gy::Vector; Xref::Matrix = X, Yref::Vector = Y, Wref::Matrix = W, Pref::Vector = P)::ProfitDEAModel
function deaprofit(X::Matrix, Y::Vector, W::Matrix, P::Vector, Gx::Matrix, Gy::Vector)::ProfitDEAModel
Y = Y[:,:]
Yref = Yref[:,:]
P = P[:,:]
Pref = Pref[:,:]
Gy = Gy[:,:]
return deaprofit(X, Y, W, P, Gx, Gy, Xref = Xref, Yref = Yref, Wref = Wref, Pref = Pref)
return deaprofit(X, Y, W, P, Gx, Gy)
end

function deaprofit(X::Vector, Y::Vector, W::Vector, P::Vector, Gx::Vector, Gy::Vector; Xref::Vector = X, Yref::Vector = Y, Wref::Vector = W, Pref::Vector = W)::ProfitDEAModel
function deaprofit(X::Vector, Y::Vector, W::Vector, P::Vector, Gx::Vector, Gy::Vector)::ProfitDEAModel
X = X[:,:]
Xref = Xref[:,:]
Y = Y[:,:]
Yref = Yref[:,:]
W = W[:,:]
Wref = Wref[:,:]
P = P[:,:]
Pref = Pref[:,:]
Gx = Gx[:,:]
Gy = Gy[:,:]
return deaprofit(X, Y, W, P, Gx, Gy, Xref = Xref, Yref = Yref, Wref = Wref, Pref = Pref)
return deaprofit(X, Y, W, P, Gx, Gy)
end

function Base.show(io::IO, x::ProfitDEAModel)
Expand Down
53 changes: 13 additions & 40 deletions src/deaprofitability.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,14 @@ alpha = 0.5; Returns to Scale = VRS
─────────────────────────────────────────────────────────
```
"""
function deaprofitability(X::Matrix, Y::Matrix, W::Matrix, P::Matrix; alpha::Float64 = 0.5, Xref::Matrix = X, Yref::Matrix = Y, Wref::Matrix = W, Pref::Matrix = P)::ProfitabilityDEAModel
function deaprofitability(X::Matrix, Y::Matrix, W::Matrix, P::Matrix; alpha::Float64 = 0.5)::ProfitabilityDEAModel
# Check parameters
nx, m = size(X)
ny, s = size(Y)

nw, mw = size(W)
np, sp = size(P)

nrefx, mref = size(Xref)
nrefy, sref = size(Yref)

if nx != ny
error("number of observations is different in inputs and outputs")
end
Expand All @@ -71,33 +68,17 @@ function deaprofitability(X::Matrix, Y::Matrix, W::Matrix, P::Matrix; alpha::Flo
error("number of observations is different in output prices and outputs")
end
if mw != m
error("number of input prices and intputs is different")
error("number of input prices and intputs is different")
end
if sp != s
error("number of output prices and otuputs is different")
end
if nrefx != nrefy
error("number of observations is different in inputs reference set and ouputs reference set")
end
if m != mref
error("number of inputs in evaluation set and reference set is different")
end
if s != sref
error("number of outputs in evaluation set and reference set is different")
end
if size(Wref) != size(Xref)
error("size of reference prices for inputs should be equal to size of reference inputs")
end
if size(Pref) != size(Yref)
error("size of reference prices for outputs should be equal to size of reference outputs")
end

# Compute efficiency for each DMU
n = nx
nref = nrefx

pefficiency = zeros(n)
plambdaeff = spzeros(n, nref)
plambdaeff = spzeros(n, n)

for i=1:n
# Value of inputs and outputs to evaluate
Expand All @@ -109,11 +90,11 @@ function deaprofitability(X::Matrix, Y::Matrix, W::Matrix, P::Matrix; alpha::Flo
# Create the optimization model
deamodel = Model(with_optimizer(Ipopt.Optimizer, print_level= 0 ))
@variable(deamodel, eff, start = 1.0)
@variable(deamodel, lambda[1:nref] >= 0)
@variable(deamodel, lambda[1:n] >= 0)

@NLobjective(deamodel, Min, eff)

@NLconstraint(deamodel, sum(sum(Wref[t,mi] * Xref[t,mi] for mi in 1:m) / sum(Pref[t,si] * Yref[t,si] for si in 1:s) * lambda[t] for t in 1:nref) == eff * sum(w0[j] * x0[j] for j in 1:m ) / sum(p0[j] * y0[j] for j in 1:s))
@NLconstraint(deamodel, sum(sum(W[t,mi] * X[t,mi] for mi in 1:m) / sum(P[t,si] * Y[t,si] for si in 1:s) * lambda[t] for t in 1:n) == eff * sum(w0[j] * x0[j] for j in 1:m ) / sum(p0[j] * y0[j] for j in 1:s))

@constraint(deamodel, sum(lambda) == 1)

Expand All @@ -126,41 +107,33 @@ function deaprofitability(X::Matrix, Y::Matrix, W::Matrix, P::Matrix; alpha::Flo
end

# Technical, scale and allocative efficiency
crsefficiency = efficiency(deagdf(X, Y, alpha, rts = :CRS, Xref = Xref, Yref = Yref, slack = false))
vrsefficiency = efficiency(deagdf(X, Y, alpha, rts = :VRS, Xref = Xref, Yref = Yref, slack = false))
crsefficiency = efficiency(deagdf(X, Y, alpha, rts = :CRS, slack = false))
vrsefficiency = efficiency(deagdf(X, Y, alpha, rts = :VRS, slack = false))
scalefficiency = crsefficiency ./ vrsefficiency
allocefficiency = pefficiency ./ crsefficiency

return ProfitabilityDEAModel(n, m, s, alpha, pefficiency, plambdaeff, crsefficiency, vrsefficiency, scalefficiency, allocefficiency)

end

function deaprofitability(X::Vector, Y::Matrix, W::Vector, P::Matrix; alpha::Float64 = 0.5, Xref::Vector = X, Yref::Matrix = Y, Wref::Vector = W, Pref::Matrix = P)::ProfitabilityDEAModel
function deaprofitability(X::Vector, Y::Matrix, W::Vector, P::Matrix; alpha::Float64 = 0.5)::ProfitabilityDEAModel
X = X[:,:]
Xref = Xref[:,:]
W = W[:,:]
Wref = Wref[:,:]
return deaprofitability(X, Y, W, P, alpha = alpha, Xref = Xref, Yref = Yref, Wref = Wref, Pref = Pref)
return deaprofitability(X, Y, W, P, alpha = alpha)
end

function deaprofitability(X::Matrix, Y::Vector, W::Matrix, P::Vector; alpha::Float64 = 0.5, Xref::Matrix = X, Yref::Vector = Y, Wref::Matrix = W, Pref::Vector = P)::ProfitabilityDEAModel
function deaprofitability(X::Matrix, Y::Vector, W::Matrix, P::Vector; alpha::Float64 = 0.5)::ProfitabilityDEAModel
Y = Y[:,:]
Yref = Yref[:,:]
P = P[:,:]
Pref = Pref[:,:]
return deaprofitability(X, Y, W, P, alpha = alpha, Xref = Xref, Yref = Yref, Wref = Wref, Pref = Pref)
return deaprofitability(X, Y, W, P, alpha = alpha)
end

function deaprofitability(X::Vector, Y::Vector, W::Vector, P::Vector; alpha::Float64 = 0.5, Xref::Vector = X, Yref::Vector = Y, Wref::Vector = W, Pref::Vector = P)::ProfitabilityDEAModel
function deaprofitability(X::Vector, Y::Vector, W::Vector, P::Vector; alpha::Float64 = 0.5)::ProfitabilityDEAModel
X = X[:,:]
Xref = Xref[:,:]
W = W[:,:]
Wref = Wref[:,:]
Y = Y[:,:]
Yref = Y[:,:]
P = P[:,:]
Pref = Pref[:,:]
return deaprofitability(X, Y, W, P, alpha = alpha, Xref = Xref, Yref = Yref, Wref = Wref, Pref = Pref)
return deaprofitability(X, Y, W, P, alpha = alpha)
end

function Base.show(io::IO, x::ProfitabilityDEAModel)
Expand Down
Loading

0 comments on commit 8f227f2

Please sign in to comment.