<<"LinearRegression`"

(*prietoky vody v dvoch satniciach na jednej rieke*)
dataX={23.1 , 12.8,17.8,21.3,18.5,93.5}

dataY={25.9,15.1,20.4,23.5,21,105.9}

Covariance[dataX,dataY]

kor=((Covariance[dataX,dataY])/(StandardDeviation[dataX]*StandardDeviation[dataY]))

korelacnykoeficient=Correlation[dataX,dataY]

ListPlot[Table[{dataX[[i]],dataY[[i]]},{i,1,Length[dataX]}],PlotRange->All,  PlotMarkers->Automatic]

ListPlot[Table[{dataX[[i]],dataY[[i]]},{i,1,Length[dataX]}],PlotRange->All, Joined->True, PlotMarkers->Automatic]

(*nekorelovane*)

data1={62,60,65,55,57,59,65,61,61,63,53,63,69,61,56,61,63,58,74,55,55,50,63,55,68,61,63,50,58,56,60,62,65,56,57,58,50,56,62,59,67,63,54,68,53,64,65,61,57,53,63,66,60,63,61,65,67,66,52,61,59,57,62,57,58,61,68,51,66,67,62,57,62,67,64,64,66,51,54,61,59,61,57,57,63,53,59,64,58,60,58,57,54,60,56,60,54,58,64,62};

data2={52,58,51,67,65,65,61,55,65,55,57,61,63,55,65,56,56,54,56,61,60,65,55,55,57,63,60,55,66,65,59,67,65,65,49,61,67,75,60,55,64,59,64,60,52,62,61,52,57,54,66,68,62,52,65,60,57,67,59,58,61,51,60,59,61,49,55,61,53,57,62,63,57,67,64,57,53,55,66,52,65,65,62,59,62,55,63,59,63,53,53,63,57,57,44,58,63,55,64,58};

Correlation[data1,data2]//N

ListPlot[Table[{data1[[i]],data2[[i]]},{i,1,Length[data1]}],PlotRange->All,PlotStyle->PointSize[Large]]

data1={1,2,3,0,5,10,12,4,3,2,4,7,9,11,4,2,3,4,75,82,-12,1.1,2,35,2.3,6,-5,0,3};

data2={11,2,-3,10,5,1,2,-4,33,1.1,3.5,4,2,1,-9,3.3,4,77,-8,2,5.5,9,11,-2,2.2,7,-3,9,10};

Correlation[data1,data2]//N

ListPlot[Table[{data1[[i]],data2[[i]]},{i,1,Length[data1]}],PlotRange->All,PlotStyle->PointSize[Large]]

data2={104.95`,116.49`,102.22`,134.1`,130.84`,130.92`,122,110.7,130.7`,110.05`,114.39`,122.78`,126.26`,110.84`,130.64`,112.41`,112.34`,108.29`,112.17`,122.92`,120.78`,130.14`,110.23`,110.72`,114.16`,126.83`,120.88`,110.48`,132.54`,130.94`,118.05`,134.342`,130.14`,130.87`,98.68`,122.48`,134.57`,150.836`,120.9`,110.73`,128.4`,118.93`,128.835`,120.8`,104.45`,124.`,122.516`,104.34`,114.1472`,108.69`,132.097`,136.22`,124.904`,104.37`,130.688`,120.36`,114.59`,134.27`,118.095`,116.53`,122.15`,102.09`,120.29`,118.88`,122.27`,98.944`,110.79`,122.05`,106.32`,114.63`,124.05`,126.7`,114.98`,134.12`,128.97`,114.22`,106.26`,110.42`,132.79`,104.35`,130.803`,130.5`,124.65`,118.3`,124.14`,110.61`,126,118.98`,126.99`,106.2`,106.6`,126.4`,114.8`,114.64`,88.06`,116.6`,126.9`,110.85`,128.922`,116.2`};

data1={52,58,51,67,65,65,61,55,65,55,57,61,63,55,65,56,56,54,56,61,60,65,55,55,57,63,60,55,66,65,59,67,65,65,49,61,67,75,60,55,64,59,64,60,52,62,61,52,57,54,66,68,62,52,65,60,57,67,59,58,61,51,60,59,61,49,55,61,53,57,62,63,57,67,64,57,53,55,66,52,65,65,62,59,62,55,63,59,63,53,53,63,57,57,44,58,63,55,64,58};

Correlation[data1,data2]//N

ListPlot[Table[{data1[[i]],data2[[i]]},{i,1,Length[data1]}],PlotRange->All,PlotStyle->PointSize[Large]]

data1={74,37,44,28,44,2,45,10,56,69,90,27,23,56,41,42,94,51,44,96,27,89,49,47,94,64,67,41,75,47,23,14,58,17,97,45,6,37,83,35,26,9,62,44,71,26,37,61,37,58,1,47,60,98,7,6,2,88,99,35,16,71,74,20,79,74,42,7,84,77,36,25,80,63,71,98,61,14,68,11,71,44,62,64,55,39,9,98,94,85,7,14,70,53,50,56,3,40,18,16};

data2={1710,579,760,373,760,4,788,72,1109,1534,2317,352,273,1109,681,707,2478,958,760,2560,352,2277,900,843,2478,1365,1466,681,1746,843,273,124,1171,169,2601,788,31,579,2044,531,332,60,1299,760,1604,332,579,1267,579,1171,1,843,1234,2643,40,31,4,2237,2685,531,153,1604,1710,219,1893,1710,707,40,2082,1819,555,312,1930,1332,1604,2643,1267,124,1500,84,1604,760,1299,1365,1078,629,60,2643,2478,2120,40,124,1569,1017,929,1109,9,655,185,153};

Correlation[data1,data2]//N

ListPlot[Table[{data1[[i]],data2[[i]]},{i,1,Length[data1]}],PlotRange->All,PlotStyle->PointSize[Large]]

T=(korelacnykoeficient/(Sqrt[1-(korelacnykoeficient^2)]))*(Sqrt[6-2])

uuu=Quantile[StudentTDistribution[4],0.975]

(*procedura na testovanie*)

Testkorelacie[data1_,data2_,alpha_]:=
Module[{α},α=alpha;Print[Style["Test nulaovsti korelacneho koeficienta.",16,Bold]];
r=Correlation[data1,data2];n=Length[data1];
Print[Style["------------------------------",16,Bold]];
Print["korelacny koeficient na hodnotu: ",r];uu=((Abs[r]*(Sqrt[n-2]))/(1-(r^2)));
Print["testovacia statistika na hodnotu: ",uu];
uuu=Quantile[StudentTDistribution[n-2],1-(α/2)];
Print["kvantil Studentovho T rozdelenia je : ",uuu];
Print[Style["-------------------------------",16,Bold]];
Print[Style["Zaver",16,Bold]];Print[Style["----------------------------------",16,Bold]];
If[((Abs[r]*(Sqrt[n-2]))/(1-(r^2)))>uuu,Print["zamietam H0, korelacny koeficient nie je nulovy"],Print["nezamietam H0"]]]

Testkorelacie[data1,data2,0.05]