function [H,p,y]=pred_int2(t,X,tau,a,b,out,k)

% 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
% k   ...volime metodu pro odhad trendu
% H   ...vysledek testu dobre shody (analyza chyby), 1-normalni rozdeleni
%        nezamitnuto
% p   ...pravdepodobnost, ze velicina padne do (a,b)
% y   ...nejpravdepodobnejsi hodnota veliciny v case tau

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

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


if k==1;
     f0=fit(log(t),log(X),'poly1');
   b_moc=coeffvalues(f0);
    X_rob_moc=exp(b_moc(1)).*(t.^b_moc(2));
    y=exp(b_moc(1))*(tau^b_moc(2));
    a1=a-(exp(b_moc(1))*(tau^b_moc(2)));
    b1=b-(exp(b_moc(1))*(tau^b_moc(2)));
    e=X-X_rob_moc;
    p_a1=cdf('Normal',a1,mean(e),std(e));
    p_b1=cdf('Normal',b1,mean(e),std(e));
    p=p_b1-p_a1;
    H=chi2gof(e,'cdf',{@normcdf,mean(e),std(e)});
end;

if k==3;
    f1=fit(t,X,'poly1');
    b5=coeffvalues(f1);
    X_lin=b5(2)+b5(1).*t;
    y=b5(2)+b5(1)*tau;
    a1=a-(b5(2)+b5(1)*tau);
    b1=b-(b5(2)+b5(1)*tau);
    e=X-X_lin;
    p_a1=cdf('Normal',a1,mean(e),std(e));
    p_b1=cdf('Normal',b1,mean(e),std(e));
    p=p_b1-p_a1;
    H=chi2gof(e,'cdf',{@normcdf,mean(e),std(e)});
end;

if k==4;
    f2=fit(t,X,'exp1');
    b2=coeffvalues(f2);
    X_exp=b2(1)*exp(b2(2).*t);
    y=b2(1)*exp(b2(2)*tau);
    a1=a-(b2(1)*exp(b2(2)*tau));
    b1=b-(b2(1)*exp(b2(2)*tau));
    e=X-X_exp;
    p_a1=cdf('Normal',a1,mean(e),std(e));
    p_b1=cdf('Normal',b1,mean(e),std(e));
    p=p_b1-p_a1;
    H=chi2gof(e,'cdf',{@normcdf,mean(e),std(e)});
end;

if k==5;
    r=ksr(t,X);
    f3=fit(t,r.f','poly2');
    b3=coeffvalues(f3);
    X_ksr=b3(1).*t.^2+b3(2).*t+b3(3);
    y=b3(1)*tau^2+b3(2)*tau+b3(3);
    a1=a-(b3(1)*tau^2+b3(2)*tau+b3(3));
    b1=b-(b3(1)*tau^2+b3(2)*tau+b3(3));
    e=X-X_ksr;
    p_a1=cdf('Normal',a1,mean(e),std(e));
    p_b1=cdf('Normal',b1,mean(e),std(e));
    p=p_b1-p_a1;
    H=chi2gof(e,'cdf',{@normcdf,mean(e),std(e)});
end;

if k==6;
    klp=smooth(X,3);
    f4=fit(t,klp,'poly2');
    b4=coeffvalues(f4);
    X_klp=b4(1).*t.^2+b4(2).*t+b4(3);
    y=b4(1)*tau^2+b4(2)*tau+b4(3);
    a1=a-(b4(1)*tau^2+b4(2)*tau+b4(3));
    b1=b-(b4(1)*tau^2+b4(2)*tau+b4(3));
    e=X-X_klp;
    p_a1=cdf('Normal',a1,mean(e),std(e));
    p_b1=cdf('Normal',b1,mean(e),std(e));
    p=p_b1-p_a1;
    H=chi2gof(e,'cdf',{@normcdf,mean(e),std(e)});
end;
    
H=not(H);





