function [H_p]=pred_int(t,X,tau,a,b,out)

% t   ...vektor casu
% X   ...pozorovani rady
% tau ...casovy okamzik pro predpoved
% a   ...dolni mez intervalu pro hodnotu velicinu
% b   ...horni mez intervalu pro hodnotu velicinu
% out ...vyradit/nevyradit odlehle hodnoty, out=1 - vyradit
% H_p ...vysledky testu dobre shody (analyza chyby), 1-normalni rozdeleni nezamitnuto, a pravdepodobnosti, ze
%        velicina padne do (a,b)

[t1,X1,l]=vyhazet_radky(t,X);

if out==0;
    [Q,I]=outliers([t1 X1],1.5);
    t=Q(:,1);
    X=Q(:,2);
else
    t=t1;
    X=X1;
end;

b_lin=robustfit(t,X);
X_rob_lin=b_lin(1)+b_lin(2).*t;
a1(1)=a-(b_lin(1)+b_lin(2)*tau);
b1(1)=b-(b_lin(1)+b_lin(2)*tau);

b_moc=robustfit(log(t),log(X));
X_rob_moc=exp(b_moc(1)).*(t.^b_moc(2));
a1(2)=a-(exp(b_moc(1))*(tau^b_moc(2)));
b1(2)=b-(exp(b_moc(1))*(tau^b_moc(2)));

f1=fit(t,X,'poly1');
b5=coeffvalues(f1);
X_lin=b5(2)+b5(1).*t;
a1(3)=a-(b5(2)+b5(1)*tau);
b1(3)=b-(b5(2)+b5(1)*tau);

f2=fit(t,X,'exp1');
b2=coeffvalues(f2);
X_exp=b2(1)*exp(b2(2).*t);
a1(4)=a-(b2(1)*exp(b2(2)*tau));
b1(4)=b-(b2(1)*exp(b2(2)*tau));

r=ksr(t,X);
f3=fit(t,r.f','poly2');
b3=coeffvalues(f3);
X_ksr=b3(1).*t.^2+b3(2).*t+b3(3);
a1(5)=a-(b3(1)*tau^2+b3(2)*tau+b3(3));
b1(5)=b-(b3(1)*tau^2+b3(2)*tau+b3(3));


klp=smooth(X,3);
f4=fit(t,klp,'poly2');
b4=coeffvalues(f4);
X_klp=b4(1).*t.^2+b4(2).*t+b4(3);
a1(6)=a-(b4(1)*tau^2+b4(2)*tau+b4(3));
b1(6)=b-(b4(1)*tau^2+b4(2)*tau+b4(3));

e_rob_lin=X-X_rob_lin;
e_rob_moc=X-X_rob_moc;
e_lin=X-X_lin;
e_exp=X-X_exp;
e_ksr=X-X_ksr;
e_klp=X-X_klp;

E=[e_rob_lin e_rob_moc e_lin e_exp e_ksr e_klp];

for i=1:size(E,2)
    H(i,1)=chi2gof(E(:,i),'cdf',{@normcdf,mean(E(:,i)),std(E(:,i))});
    %H(i,2)=chi2gof(E(:,i),'cdf',{@unifcdf,min(E1(:,i)),max(E1(:,i))});
    p_a1(i)=cdf('Normal',a1(i),mean(E(:,i)),std(E(:,i)));
    p_b1(i)=cdf('Normal',b1(i),mean(E(:,i)),std(E(:,i)));
    p(i)=p_b1(i)-p_a1(i);
end;

H=not(H);

H_p=[H p'];

meabn




