You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MATLAB创建剂量反应曲线遇doseResponse秩亏警告求助

解决MATLAB剂量反应曲线拟合问题

问题描述

我正在寻找MATLAB中基于数据创建剂量反应曲线的方法,目前使用的MATLAB社区贡献的doseResponse函数,但无法拟合出符合数据的Sigmoidal曲线。运行代码后出现秩亏缺等警告,生成的曲线不符合预期。

运行代码

doseResponse(drug_conc,resp_vals)
xlabel('5HT Dose (nm)','FontSize',20) 
ylabel('Normalized Response to Stimuli (\DeltaF / F)','FontSize',20)

警告信息

Warning: Rank deficient, rank = 3, tol =  1.196971e-11. 
> In nlinfit>LMfit (line 587)
In nlinfit (line 284)
In doseResponse (line 47)
Warning: Rank deficient, rank = 1, tol =  3.802134e-12. 
> In nlinfit>LMfit (line 587)
In nlinfit (line 284)
In doseResponse (line 47)
Warning: Some columns of the Jacobian are effectively zero at the solution, indicating that the model is insensitive to some of its parameters.
That may be because those parameters are not present in the model, or otherwise do not affect the predicted values.  It may also be due to
numerical underflow in the model function, which can sometimes be avoided by choosing better initial parameter values, or by rescaling or
recentering.  Parameter estimates may be unreliable. 
> In nlinfit (line 381)
In doseResponse (line 47) 
ans =
-5.2168e+07

当前拟合结果

剂量反应曲线绘制结果图

问题原因

出现的秩亏缺警告,本质是nlinfit在拟合Sigmoid模型时,默认初始参数与数据分布不匹配,或数据尺度差异过大,导致模型对部分参数不敏感,拟合过程无法收敛到合理结果。

解决方案

1. 手动指定拟合初始参数

doseResponse默认的初始参数可能不适配你的数据,查看函数源码找到Sigmoid模型的参数(通常包含响应下限、响应上限、EC50、斜率),根据数据手动设置初始值:

% 根据自身数据调整初始参数:[响应下限, 响应上限, EC50, 斜率]
init_params = [min(resp_vals), max(resp_vals), median(drug_conc), 1];
doseResponse(drug_conc, resp_vals, init_params);

2. 数据预处理优化

对浓度做对数转换(剂量反应分析常用操作),或对响应值做归一化,缩小数值尺度差异:

% 浓度取对数
log_drug_conc = log10(drug_conc);
% 响应值归一化到0-1区间
norm_resp = (resp_vals - min(resp_vals)) / (max(resp_vals) - min(resp_vals));

doseResponse(log_drug_conc, norm_resp);

3. 使用MATLAB原生工具自定义拟合

放弃第三方函数,用fitnlm实现Sigmoid拟合,灵活性更高:

% 定义Sigmoid模型:params(1)=下限, params(2)=上限, params(3)=斜率, params(4)=EC50
sigmoid_model = @(params, x) params(1) + (params(2)-params(1)) ./ (1 + exp(-params(3)*(x - params(4))));

% 设置初始参数
init_params = [min(resp_vals), max(resp_vals), 1, median(drug_conc)];

% 执行拟合
fit_result = fitnlm(drug_conc, resp_vals, sigmoid_model, init_params);

% 生成拟合曲线的采样点
x_fit = linspace(min(drug_conc), max(drug_conc), 100);
y_fit = predict(fit_result, x_fit);

% 绘图展示
figure;
scatter(drug_conc, resp_vals, 'filled', 'DisplayName', '原始数据'); hold on;
plot(x_fit, y_fit, 'r-', 'LineWidth', 2, 'DisplayName', '拟合曲线');
xlabel('5HT Dose (nm)','FontSize',20);
ylabel('Normalized Response to Stimuli (\DeltaF / F)','FontSize',20);
legend('Location', 'best');

4. 检查数据质量

确认数据是否存在异常值、重复值,或浓度梯度是否覆盖了从无响应到饱和响应的完整区间——缺失关键区间的数据会直接导致拟合失败。

内容的提问来源于stack exchange,提问作者user16211698

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 21:06:28