<<"LinearRegression`"

<<"MultivariateStatistics`"

data={{-20,323},{0,327},{20,340},{50,367},{100,386}}

(*meranie rychlost zvukui pri roznych teplotach*)
g1=ListPlot[data,PlotStyle->PointSize[Large]]

teplota=Table[data[[j,1]],{j,1,Length[data]}]

rychlost=Table[data[[j,2]],{j,1,Length[data]}]

r=Correlation[teplota,rychlost]//N

(*datya koreluju-ma zmysle popisat to nmiakov funkciou*)

(* robi sa cez prikaz Regress[data,zoznam bazovych funkcii,zoznam premennych]*)

Regress[data,{x},x]

(*{x} preto lebo default value je ...??? *)

(*P value pri 1ke znamena - ak ej ≤0.05 alebo niaka moja α zamietram H0, a je rozne od nuly parameter treba uvazovat cize a musime zobrat

RSquared - koeficient determinacie cize na kolko % sme vystihli spravanie sa dat
  
AdjustedSq... korigovany koef determinacie

Estimated variance odhad disperzie 

anovaTable - analysis of variance . 

*)

Regress[data,{x},x,IncludeConstant->False]

Regress[data,{x,x^2,x^3},x]

Regress[data,{x},x,BasisNames->{"konstanta","smernica"}]

Regress[data,{x},x,BasisNames->{"konstanta","smernica"},ConfidenceLevel->.99,RegressionReport->ParameterCITable]

Regress[data,{x},x,BasisNames->{"konstanta","smernica"},ConfidenceLevel->.99,IncludeConstant->False]

krivka=Regress[data,{x},x,RegressionReport->{BestFit}]

param=Regress[data,{x},x,RegressionReport->{BestFitParameters}]

tabulka=Regress[data,{x},x,RegressionReport->{ANOVATable}]

Regress[data,{x},x,RegressionReport->{FitResiduals}]

Regress[data,{x},x,RegressionReport->{PredictedResponse}]

Regress[data,x,x,RegressionReport->{SinglePredictionCITable}]

(*ak chcem vycucnut len funkciu*)

f1=Fit[data,{1,x},x]

f2=Fit[data,{1,x,x^2},x]

f3=Fit[data,{1,x,x^2,x^3},x]

g1=Plot[{f1,f2,f3},{x,-100,100}];

g2=ListPlot[data,PlotStyle->PointSize[Large]];

Show[g1,g2]

(*predpoved novych hodnot

aka je predpokld rychlost pri 70 stupnoch?*)

f1/.x->70

f1/.x->110

(*nakreslime rezidua*)

rezy=Regress[data,x,x,RegressionReport->{FitResiduals}]

(*ListPlot[FitResiduals]*)
(*Novy priklad
prehyb dosky , ide sa po 10 cm cize netreba zapisovat xn staci yn*)

data2={2.1299,2.1532,2.1611,2.151,2.1282,2.0807,2.0266,1.9594,1.8759,1.7723}

g1=ListPlot[data2,PlotStyle->PointSize[Large]]

Regress[data2,{x,x^2},x]

f=Regress[data2,{x,x^2},x,RegressionReport->{BestFit}]

g2=Plot[BestFit/.f,{x,0,10}];

Show[g1,g2]

Regress[data2,{x,x^2},x,IncludeConstant->False]

f4=Regress[data2,{x,x^2},x,RegressionReport->{BestFit},IncludeConstant->False];
g2=Plot[BestFit/.f4,{x,0,10}];

Show[g1,g2]

(*novy proklad

zavislost tlaku od nadm vysky*)
data3={{0,100000},{270,96974},{840,90263},{1452,83553},{2116,76842},{3203,66842}}

g1=ListPlot[data3,PlotStyle->PointSize[Large]]

(*mala by to byt exponencialna zavislost len mame blbu mierku

vytvorime novy vstup{x,Ln[y]}

popisane v zosite*)

upravene=Table[{data3[[i,1]],Log[data3[[i,2]]]//N},{i,1,6}]

Regress[upravene,x,x]

(*cize A=11.5154 a B=-0.000126087=b

E^A=a 
*)

koef=Regress[upravene,x,x,RegressionReport->{BestFitParameters}]

parametre=BestFitParameters/.koef

b=parametre[[2]]

a=E^parametre[[1]]

g2=Plot[a*Exp[b*t],{t,1,3250}]