SetDirectory["F:\\anlyzaCR"]

SetOptions[ListPlot,PlotRange->All,AxesLabel->{"time [Year]","pocet * 1000"},BaseStyle->{11,FontFamily->"Arial"},Joined->True];

data=ReadList["auta_mes.dat",Number];

n=Length[data]

Zakladna analyza casoveho radu

vypocet vyberovej strednej hodnoty, smerodajnej odchylky a rozptylu CR

μ=Mean[data]//N
σ=StandardDeviation[data]//N
σ2=Variance[data]//N

popis casovej osi pri zobrazeni CR mesacnych prirastkov  novych aut

popis=Table[{13+i*12,1983+i},{i,0,5}];

gd=ListPlot[data,Ticks->{popis,Automatic},AxesOrigin->{0,0},Joined->True]

dat=Partition[data,12];
rp=Table[(∑_(j=1)^12)dat[[i,j]],{i,7}]

popisr=Table[{1+i*2,1983+i*2},{i,0,5}];
gdr=ListPlot[rp,Joined->True,PlotStyle->Hue[0.05],Ticks->{popisr,Automatic},AxesOrigin->{0,0}]

Vycislime a zobrazime priemerne prirastky aut v jednotlivych mesiacoch roka

pocetr=Length[dat]

mesiac=Table[i,{i,12}];

pmp=N[Table[(1/pocetr) (∑_(i=1)^pocetr)dat[[i,j]],{j,12}]]
matica=Transpose[{mesiac,pmp}];
TableForm[matica,TableHeadings->{None,{"mesiac","priemer"}}]

ListPlot[pmp,AxesLabel->{"manoth","pocet*1000"}, AxesOrigin->{0,700}]

Urcenie Systematickych zloziek CR

<<"LinearRegression`"
<<"NonlinearRegression`"

x=data;

1. typ Trendu
  Urobime testy pre vsetky typy trendov a potom vyberieme trend s najmensim rozptylom testovacich premennych
  
  a) Vycislime a zobrqazime prve diferencie CR
  
  V pripade ze prve diferencie su priblizne nulove, pouzijeme konstantny trend, ak su priblizne konstantne (nenulove) pouzijeme linearny trend

tv1=Drop[x,1]-Drop[x,-1];
Variance[tv1]//N
ListPlot[tv1,Joined->False]

hodnoty prvych diferenci daneho CR nemozno povazovat za konstantne

b) Vycislime a zobrqazime druhe diferencie CR

tv2=Drop[x,2]-2*Drop[Drop[x,-1],1]+Drop[x,-2];
Variance[tv2]//N
ListPlot[tv2,Joined->False]

hodnoty prvych diferenci daneho CR nemozno povazovat za konstantne

c) Vycislime a zobrazime podiely susednych clenov radu

tv3=Table[If[(x[[t]]≠0)∧(x[[t+1]]≠0),(1/x[[t+1]])/(1/x[[t]]),0],{t,n-1}];
Variance[tv3]//N
tv3g=ListPlot[tv3,Joined->False]

tv4=Table[If[(x[[t]]≠0)∧(x[[t+1]]≠0)∧(x[[t+2]]≠0)∧(1/x[[t+1]]-1/x[[t]])≠0,(1/x[[t+2]]-1/x[[t+1]])/(1/x[[t+1]]-1/x[[t]]),0],{t,n-2}];
Variance[tv4]//N
ListPlot[tv4,Joined->False]

EXPONENCIALNY trend

odhadneme parametre exponencialneho trendu nelinearnou regresiou

rege=NonlinearRegress[x,a*b^t,{a,b},t,RegressionReport->{BestFit,ParameterCITable,EstimatedVariance,ANOVATable}]

etrend=BestFit/.rege

gte=Plot[etrend,{t,0,n},PlotStyle->{Hue[0.6],Thickness[0.005]}];
Show[gd,gte]

rege=NonlinearRegress[x,a*b^t,{a,b},t,RegressionReport->{FitResiduals}];

rezte=FitResiduals/.rege;

μ=Mean[rezte]//Chop
σ=StandardDeviation[rezte]
σ2=Variance[rezte]

LOGISTICKY trend

odhadneme parametre lofistickeho trendu melinearnou regresiou

rege1=NonlinearRegress[x,γ/(1+a*b^t),{{a,-1},{b,0.2},{γ,50}},t,RegressionReport->{BestFit,ParameterCITable,EstimatedVariance,ANOVATable}]

Itrend=BestFit/.rege1

gt1=Plot[Itrend,{t,0,n},PlotStyle->{Hue[0.6],Thickness[0.005]}];
Show[gd,gt1]

reg1=NonlinearRegress[x,γ/(1+a*b^t),{{a,-1},{b,0.2},{γ,50}},t,RegressionReport->{FitResiduals}];
rezt1=FitResiduals/.reg1;

μ=Mean[rezt1]//Chop
σ=StandardDeviation[rezt1]
σ2=Variance[rezt1]

Save["rezt1.dat",reat1]

reztl=ReadList["reztlauta.dat"];

<<"timeseri\\datasmoo.m"
<<"timeseri\\timeseri.m"
<<"timeseri\\userfunc.m"

odhad sezonnej zlozky pomocou korelogramu

kf=CorrelationFunction[reztl,60];
myplotcorr1[kf,2/Sqrt[n],AxesLabel->{k,ρk},Ticks->{{12,24,36,48,60},Automatic},PlotLabel->"Autocorrelation Function",PlotRange->All]