我一直在运行从here下载的DoseResponse函数的变体,以生成剂量-ReactSigmoid曲线。然而,我的一个数据集在生成线性曲线时遇到了问题。通过运行以下代码,我得到以下错误并生成以下图形。我还将名为dose2.csv和res2.csv的数据上传到了Google Drive here。有人知道我怎么解决这个问题吗?谢谢。
用于生成图形的代码
% Plotting Dose-Response Curve
response = resp2;
dose = dose2;
% Deal with 0 dosage by using it to normalise the results.
normalised=0;
if (sum(dose(:)==0)>0)
%compute mean control response
controlResponse=mean(response(dose==0));
%remove controls from dose/response curve
response=response(dose~=0)/controlResponse;
dose=dose(dose~=0);
normalised=1;
end
%hill equation sigmoid
sigmoid=@(beta,x)beta(1)+(beta(2)-beta(1))./(1+(x/beta(3)).^beta(4));
%calculate some rough guesses for initial parameters
minResponse=min(response);
maxResponse=max(response);
midResponse=mean([minResponse maxResponse]);
minDose=min(dose);
maxDose=max(dose);
%fit the curve and compute the values
%[coeffs,r,J]=nlinfit(dose,response,sigmoid,[minResponse maxResponse midResponse 1]); % nlinfit doesn't work as well
beta_new = lsqcurvefit(sigmoid,[minResponse maxResponse midResponse 1],dose,response);
[coeffs,r,J]=nlinfit(dose,response,sigmoid, beta_new);
ec50=coeffs(3);
hillCoeff=coeffs(4);
%plot the fitted sigmoid
xpoints=logspace(log10(minDose),log10(maxDose),1000);
semilogx(xpoints,sigmoid(coeffs,xpoints),'Color',[1 0 0],'LineWidth',2)
hold on
%notate the EC50
text(ec50,mean([coeffs(1) coeffs(2)]),[' \leftarrow ' sprintf('EC_{50}=%0.2g',ec50)],'FontSize',20,'Color',[1 0 0]);
%plot mean response for each dose with standard error
doses=unique(dose);
meanResponse=zeros(1,length(doses));
stdErrResponse=zeros(1,length(doses));
for i=1:length(doses)
responses=response(dose==doses(i));
meanResponse(i)=mean(responses);
stdErrResponse(i)=std(responses)/sqrt(length(responses));
%stdErrResponse(i)=std(responses);
end
errorbar(doses,meanResponse,stdErrResponse,'o','Color',[1 0 0],'LineWidth',2,'MarkerSize',12)
警告消息
Solver stopped prematurely.
lsqcurvefit stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 4.000000e+02.
Warning: Iteration limit exceeded. Returning results from final iteration.
图表(希望生成不是线性的Sigmoid曲线)
1条答案
按热度按时间oo7oh9g91#
您还需要为
lsqcurvefit
优化初始值[minResponse maxResponse midResponse 1]
。不要简单地从给定值的最小值或最大值开始。取而代之的是,你可能首先从你的方程式开始估计你的系数。给出了
sigmoid=@(beta,x)beta(1)+(beta(2)-beta(1))./(1+(x/beta(3)).^beta(4))
的S型模型。当x
任意接近inf
时,公式将返回beta(2)
。当x
任意接近0
时,方程将返回beta(1)
。因此,minResponse
、maxResponse
和midResponse
的初步估计似乎足够合理。实际上,您的问题在于对1
的初始估计。根据您的对数图的倾斜度,可以粗略估计beta(4)
。根据我的粗略估计,它大约是1/4,因此您可能会得出结论,您最初估计的1太大了,不能收敛。