MATLAB:绘图数据与预测拟合

MATLAB:绘图数据与预测拟合,matlab,confidence-interval,Matlab,Confidence Interval,我试图绘制连接长度上的强度增加。在下面的示例中,创建了与我期望的相似的随机数据,并对其进行了拟合。 问题是我想确定每个长度(每个x值)的预测级别,而不是整个数据集的预测级别。如图所示,低x值的结果比高x值的结果分散得多 有谁能给我一个关于如何创建这种类型的图的提示(预测线正在远离拟合) 请参见以下示例图: 由于yVec是通过使用sqrt(xVec)对随机分布进行加权而生成的,因此您实际上通过xVec(sqrt(xVec)改变了每个x值的随机变量的方差。您可以做的是通过使用xVec加权原始置信区间

我试图绘制连接长度上的强度增加。在下面的示例中,创建了与我期望的相似的随机数据,并对其进行了拟合。 问题是我想确定每个长度(每个x值)的预测级别,而不是整个数据集的预测级别。如图所示,低x值的结果比高x值的结果分散得多

有谁能给我一个关于如何创建这种类型的图的提示(预测线正在远离拟合)

请参见以下示例图:

由于yVec是通过使用sqrt(xVec)对随机分布进行加权而生成的,因此您实际上通过xVec(sqrt(xVec)改变了每个x值的随机变量的方差。您可以做的是通过使用xVec加权原始置信区间来重新计算置信区间。这里有一些基于你的代码

   %Generate random data
 xVec = 0:0.001:1;
 Distr = makedist('Normal','mu',10,'sigma',1);
 for i=1:length(xVec)
    yVec(i) = sqrt(xVec(i))*random(Distr);
 end

%Create fit and confidence interval
 FitVec = fit(xVec',yVec','poly4')
 pRvecConf = predint(FitVec,xVec,0.95,'observation','off');

 %get the fitting values
 fitY=feval(FitVec,xVec);
 %multiply the confidence interval with sqrt(xVec(i)).^2 
 ci=(fitY-pRvecConf(:,1)).*xVec';
 %get the weighted confidence interval
 Conf_new=[fitY-ci,fitY+ci];

 %Plot
 plot(FitVec,xVec,yVec) 
 hold on
 plot(xVec,Conf_new,'m--')
 legend('Data','Fitted curve','Confidence','Location','se')
 xlabel('Length')
 ylabel('Strength')
结果应该如下所示:

   %Generate random data
 xVec = 0:0.001:1;
 Distr = makedist('Normal','mu',10,'sigma',1);
 for i=1:length(xVec)
    yVec(i) = sqrt(xVec(i))*random(Distr);
 end

%Create fit and confidence interval
 FitVec = fit(xVec',yVec','poly4')
 pRvecConf = predint(FitVec,xVec,0.95,'observation','off');

 %get the fitting values
 fitY=feval(FitVec,xVec);
 %multiply the confidence interval with sqrt(xVec(i)).^2 
 ci=(fitY-pRvecConf(:,1)).*xVec';
 %get the weighted confidence interval
 Conf_new=[fitY-ci,fitY+ci];

 %Plot
 plot(FitVec,xVec,yVec) 
 hold on
 plot(xVec,Conf_new,'m--')
 legend('Data','Fitted curve','Confidence','Location','se')
 xlabel('Length')
 ylabel('Strength')