1. 数据包络分析(DEA)基础概念与应用场景
数据包络分析(Data Envelopment Analysis, DEA)是一种用于评估决策单元(DMU)相对效率的非参数方法。它最早由Charnes、Cooper和Rhodes在1978年提出,通过线性规划技术构建生产前沿面,衡量各DMU与前沿面的距离来评估效率。
提示:DEA特别适合处理多输入多输出的效率评估问题,传统财务指标往往难以全面反映这类复杂情况。
在Matlab中实现DEA具有显著优势:
- 矩阵运算高效:Matlab内置的线性代数库能快速处理DEA涉及的矩阵运算
- 可视化能力强:可直观展示效率前沿面和各DMU的相对位置
- 算法扩展方便:便于实现CCR、BCC等不同DEA模型的变体
典型应用场景包括:
- 医院运营效率评估(输入:医护人员数、床位;输出:诊疗人次、手术量)
- 银行分支机构绩效(输入:员工数、营业面积;输出:存款额、贷款额)
- 学校教学效果评价(输入:师资力量、经费投入;输出:升学率、竞赛获奖)
需要模型API调用? 免费领10W Token,多模型网关一键接入 Claude、DeepSeek 等主流模型。
2. DEA核心模型:CCR与BCC的实现原理
2.1 CCR模型数学表达
CCR模型假设规模报酬不变(CRS),其原始形式为:
max θ = ∑(u_r * y_rj) / ∑(v_i * x_ij)
s.t.
∑(u_r * y_rk) / ∑(v_i * x_ik) ≤ 1, ∀k
u_r, v_i ≥ ε > 0
通过Charnes-Cooper变换可转化为线性规划问题。在Matlab中,我们使用linprog函数求解:
matlab复制function [theta, weights] = dea_ccr(input, output, dmu_index)
[s, m] = size(output, 2), size(input, 2);
f = [zeros(1,m+s), -1];
Aeq = [output(dmu_index,:), zeros(1,s), 0;
zeros(1,m), input(dmu_index,:), -1];
beq = [1; 0];
A = [output, -input, zeros(size(input,1),1)];
b = zeros(size(input,1),1);
lb = [zeros(1,m+s), -Inf];
options = optimoptions('linprog','Display','none');
sol = linprog(f,A,b,Aeq,beq,lb,[],[],options);
theta = sol(end);
weights = sol(1:m+s)';
end
2.2 BCC模型的改进与实现
Banker、Charnes和Cooper在1984年提出的BCC模型放宽了规模报酬不变的假设(VRS),增加凸性约束∑λ=1。面向输入的BCC模型数学形式:
min θ
s.t.
∑λ_j x_ij ≤ θx_i0, ∀i
∑λ_j y_rj ≥ y_r0, ∀r
∑λ_j = 1
λ_j ≥ 0, ∀j
Matlab实现关键差异点:
matlab复制Aeq = [Aeq; ones(1,size(input,1)), zeros(1,size(output,2)+1)]; % 增加凸性约束
beq = [beq; 1];
3. Matlab环境准备与数据预处理
3.1 必要工具包配置
建议安装以下Matlab工具包以获得最佳性能:
- Optimization Toolbox(必需):提供linprog等优化求解器
- Parallel Computing Toolbox(可选):加速大规模DEA计算
- Statistics and Machine Learning Toolbox(可选):辅助数据分析
验证安装:
matlab复制ver('optim') % 检查优化工具箱
license('test','optimization_toolbox') % 验证许可证
3.2 数据标准化处理
DEA对数据尺度敏感,建议预处理:
- 同向化:将成本型指标取倒数
- 归一化:避免数值差异过大
matlab复制function [norm_input, norm_output] = dea_normalize(input, output, input_directions)
% input_directions: 1表示效益型,-1表示成本型
norm_input = input;
for i = 1:size(input,2)
if input_directions(i) == -1
norm_input(:,i) = 1./input(:,i);
end
norm_input(:,i) = norm_input(:,i)/max(norm_input(:,i));
end
norm_output = output ./ max(output);
end
3.3 异常值检测
使用Malmquist指数初步筛查异常DMU:
matlab复制function outliers = dea_find_outliers(input, output, threshold)
mi = zeros(size(input,1),1);
for i = 1:size(input,1)
[~,~,~,mi(i)] = dea_malmquist(input,output,i);
end
outliers = find(mi > median(mi)+threshold*std(mi));
end
4. 完整DEA实现与结果分析
4.1 CCR模型完整实现
matlab复制function [eff, lambda, slack] = dea_ccr_full(input, output, dmu_index)
[n, m] = size(input); s = size(output,2);
% 目标函数:最小化θ
f = [zeros(1,n), 1];
% 约束条件
A = [-input', output', zeros(m,1);
zeros(s,n), -eye(s), zeros(s,1)];
b = [zeros(m,1); -output(dmu_index,:)'];
Aeq = [ones(1,n), zeros(1,s+1)];
beq = 1;
lb = [zeros(1,n+s), -Inf];
ub = [];
options = optimoptions('linprog','Algorithm','dual-simplex');
sol = linprog(f,A,b,Aeq,beq,lb,ub,[],options);
lambda = sol(1:n);
theta = sol(n+1);
slack = sol(n+2:end);
% 计算技术效率
eff = 1/theta;
end
4.2 结果可视化方法
- 效率值分布直方图:
matlab复制histogram(eff_scores,'BinWidth',0.1);
xlabel('效率得分'); ylabel('DMU数量');
title('CCR模型效率得分分布');
- 前沿面投影(二维示例):
matlab复制scatter(input(:,1)./output, input(:,2)./output,'filled');
hold on;
k = convhull(input(eff==1,1)./output(eff==1), input(eff==1,2)./output(eff==1));
plot(input(eff==1,1)./output(eff==1), input(eff==1,2)./output(eff==1),'r-');
4.3 敏感性分析
通过改变ε值观察效率稳定性:
matlab复制epsilon_range = logspace(-6,-2,20);
eff_variation = zeros(length(epsilon_range),n);
for i = 1:length(epsilon_range)
options = optimoptions('linprog','ConstraintTolerance',epsilon_range(i));
for j = 1:n
[eff_variation(i,j),~,~] = dea_ccr_full(input,output,j,options);
end
end
semilogx(epsilon_range,eff_variation);
xlabel('ε值'); ylabel('效率得分');
5. 实际案例:医院效率评估
5.1 数据集说明
使用某省25家医院数据:
- 输入指标:医师人数、护士人数、床位数(单位:人/张)
- 输出指标:年门诊量、年手术量(单位:万人次/千例)
matlab复制input = [120 240 800; 95 180 600; ... ]; % 25×3矩阵
output = [45.2 8.1; 32.7 5.9; ... ]; % 25×2矩阵
5.2 CCR与BCC结果对比
matlab复制ccr_eff = zeros(25,1);
bcc_eff = zeros(25,1);
for i = 1:25
[ccr_eff(i),~,~] = dea_ccr_full(input,output,i);
[bcc_eff(i),~,~] = dea_bcc_input(input,output,i);
end
% 计算规模效率
scale_eff = ccr_eff ./ bcc_eff;
% 结果展示
table([1:25]',ccr_eff,bcc_eff,scale_eff,...
'VariableNames',{'DMU','CCR效率','BCC效率','规模效率'})
5.3 改进建议生成
对低效DMU(如医院15):
matlab复制[~,lambda,slack] = dea_bcc_input(input,output,15);
peer_idx = find(lambda > 0.1); % 找到参考医院
% 计算输入冗余
input_redundancy = input(15,:) - lambda'*input(peer_idx,:);
% 计算产出不足
output_shortfall = lambda'*output(peer_idx,:) - output(15,:);
disp(['建议减少输入:医师',num2str(input_redundancy(1)),'人,护士',...
num2str(input_redundancy(2)),'人,床位',num2str(input_redundancy(3)),'张']);
disp(['建议增加产出:门诊量',num2str(output_shortfall(1)),'万人次,手术量',...
num2str(output_shortfall(2)),'千例']);
6. 高级话题与扩展应用
6.1 超效率模型实现
允许效率值>1,用于区分有效DMU:
matlab复制function [super_eff] = dea_super(input, output, dmu_index)
[eff,~,~] = dea_ccr_full(input,output,dmu_index);
if eff < 1
super_eff = eff;
else
% 排除自身构建前沿面
new_input = input([1:dmu_index-1,dmu_index+1:end],:);
new_output = output([1:dmu_index-1,dmu_index+1:end],:);
[~,~,~,super_eff] = dea_ccr_full(new_input,new_output,dmu_index);
end
end
6.2 Malmquist生产力指数
衡量效率随时间的变化:
matlab复制function [effch,techch,pech,sech,tfpch] = dea_malmquist(input1,output1,input2,output2,dmu_index)
% 计算各时期效率
[eff1,~,~] = dea_ccr_full(input1,output1,dmu_index);
[eff2,~,~] = dea_ccr_full(input2,output2,dmu_index);
% 计算混合效率
[eff12,~,~] = dea_ccr_full(input1,output2,dmu_index);
[eff21,~,~] = dea_ccr_full(input2,output1,dmu_index);
% 分解指数
tfpch = sqrt((eff12/eff1)*(eff2/eff21));
effch = eff2/eff1;
techch = sqrt((eff1/eff12)*(eff21/eff2));
pech = ...; % 纯技术效率变化
sech = ...; % 规模效率变化
end
6.3 网络DEA实现
考虑内部子过程:
matlab复制function [overall_eff, stage1_eff, stage2_eff] = network_dea(input, intermediate, output, dmu_index)
% 第一阶段:输入→中间产出
[stage1_eff,~,~] = dea_ccr_full(input,intermediate,dmu_index);
% 第二阶段:中间产出→最终产出
[stage2_eff,~,~] = dea_ccr_full(intermediate,output,dmu_index);
% 整体效率(几何平均)
overall_eff = sqrt(stage1_eff * stage2_eff);
end
注意:实际应用中应根据具体问题调整模型结构,如添加共享资源约束、考虑非期望产出等特殊情况。
