2016-04-13 23 views
0

接続の長さよりも強度の増加をプロットしようとしています。以下の例では、予想通りのランダムなデータが作成され、そのデータに対してフィットが行われます。 問題は、データセット全体の予測レベルではなく、すべての長さ(すべてのx値)の予測レベルを特定することです。図からわかるように、低いx値の場合、高い値よりも散在する結果が非常に少なくなります。MATLAB:プロットデータが予測と一致する

このタイプのグラフを作成する方法のヒントを誰でも得ることができます(予測線が近づくにつれて成長するところ)。

%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 prediction interval 
FitVec = fit(xVec',yVec','poly4'); 
pRvecConf = predint(FitVec,xVec,0.95,'observation','off'); 

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

次の例のプロット参照:YVECはSQRTのランダム分布(xVec)を重み付けすることにより生成されたので、あなたが実際xVecによって各x値に対して確率変数の分散を変更 See example plot here

答えて

2

を(sqrt(xVec)の2乗)である。あなたができることは、元のものに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') 

結果は次のようになります。 Figure of Modified Confidence Interval

関連する問題