/
yYindxavg yYindxavg

yYindxavg - PDF document

mary
mary . @mary
Follow
343 views
Uploaded On 2021-06-21

yYindxavg - PPT Presentation

xmeanxavg ymeanysxxsumx0avg x2sxysumx0avg x3y0avg yb1isxysxxb0iavg y0b1i3avg xendDrawhistogramsofthecoe14cientsb0andb1histb0histb1 Figure1 ID: 846798

sum beta 0and avg beta sum avg 0and xout pdfnormal surf z1z2 hist data sse usenewton start 2n2pixi2pixi2pi sigma

Share:

Link:

Embed:

Download Presentation from below link

Download Pdf The PPT/PDF document "yYindxavg" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

1 y=Y(indx);avg x=mean(x);avg y=mean(y);sx
y=Y(indx);avg x=mean(x);avg y=mean(y);sxx=sum((x�avg x):2);sxy=sum((x�avg x):(y�avg y));b1(i)=sxy=sxx;b0(i)=avg y�b1(i)avg x;end;Drawhistogramsofthecoecientsb0andb1hist(b0)hist(b1) Figure1:Histogramofb0 Figure2:Histogramofb12 [n;xout]=hist(b0);n=6n=200;bar(xout,n)holdon;plot(a,pdfNormal)holdo xlabel('b0')ylabel('6*Frequency') Figure3:Histogramandthepdfcurveofb0onthesameplotb=1:0:1:2mu=1:5;sigma=sd B1;pdfNormal=normpdf(b,mu,sigma);[n;xout]=hist(b1);n=

2 40n=200;bar(xout,n)holdon;plot(b,pdf
40n=200;bar(xout,n)holdon;plot(b,pdfNormal)holdo xlabel('b1')ylabel('40*Frequency')4 Figure4:Histogramandpdfcurveofb1onthesameplotAswecanseefromFigure3andFigure4,theshapeofthehistogramofthecoecientsobtainedfromthe200timessimulationsissimilartothatofthecurveoftheestimateddistubtioinofthecoecients.2.(20points)Usethesamedatasetinthelastproblem,wewillestimate 0and 1usingNewton-Raphsonmethod.a.Drawa3dplotusingMATLAB(check"surf"commandforexample)toillustratehowth

3 eSSEvariesaccordingtodi erentcombina
eSSEvariesaccordingtodi erentcombinationsofestimatesof 0and 1.Sotospeak,drawa3dplotwherexandyaxesrepresentdi erentvaluesofslopeandinterceptoftheregressionlinerespectively,whilezaxisistheSSE.b.UseNewton-RaphsonmethodtominimizetheSSEandgiveestimatesoftheparam-eters(slopeandintercept)oftheregressionline.Giveageometricalinterpretationofthemethodandexplainhowitworks.Answer:a.Usethe"surf"commandinMatlabtodrawthe3Dplotz=zeros(61;61);x=[0:0:1:6];y=[�1:5:0:1:4:5];i=0;j=0;f

4 ori=1:61forj=1:615 z(i;j)=sum((Y�x(j)
ori=1:61forj=1:615 z(i;j)=sum((Y�x(j)�y(i)X):2);endendmeshgrid(x,y,z)surf(x,y,z) Figure5:3DplotofSSEversustheslopeandtheinterceptoftheregressionlineb.UseNewton-RaphsonmethodtominimizethefunctionF( )=SSEandgettheesti-matesoftheparameters.HereweusetheiterationsHF( n)( n+1� n)=rF( n)whereHF( n)istheHessianmatrix(second-orderpartialderivativesofthefunctionSSE)andrF( n)isgradient.rF="�2Pi(Yi� 0� 1Xi)�2Pi((Yi� 0� 1

5 Xi)Xi)#HF="2n2PiXi2PiXi2Pi(X2i)# ="&
Xi)Xi)#HF="2n2PiXi2PiXi2Pi(X2i)# =" 0 1#TheMatlabcodeis:function[beta,SSE]=NR linear(data,beta start)x=data(:;1);y=data(:;2);n=length(x);di =1;beta=beta start;whiledi �0:0001beta old=beta;J=[-2*sum(y-beta(1)-beta(2)*x);-2*sum((y-beta(1)-beta(2)*x).*x)]6 H=[2n;2sum(x);2sum(x);2sum(x:2)]H 1=inv(H);SSE=sum((y�beta(1)�beta(2)x:2)beta=beta old-H 1*Jdi =sum(abs(beta-beta old));endhw1=[X,Y]beta0=[0;0][betaml;sse]=NR linear(hw1;beta0)

6 UsingNewtonRalphsonmethod,wegotthesamere
UsingNewtonRalphsonmethod,wegotthesameresultwiththeleastsquaremethod,b0=2:7725b1=1:5297:ThegeometricinterpretationofNewton'smethodisthatateachiterationoneapproximatesbyaquadraticfunctionaroundF(x),andthentakesasteptowardsthemaximum/minimumofthatquadraticfunction.3.(10points)a.Insimplelinearregressionsettingy= 0+ 1x+,writeouttheexplicitformtheerrorfunction.b.Provethisfunctionisconvexwithrespecttoitsvariables( 0and 1).Answer:TheerrorfunctionE=Pni=1(Yi� 0�

7 ; 1Xi)2Toprovetheerrorfunctionis
; 1Xi)2Toprovetheerrorfunctionisconvexwithrespectto 0and 1,weneedtoshowthattheHessianmatrixoftheerrorfunctionispostive-semide nite.SupposewehaveanonzerovectorZ="z1z2#ZTHZ=hz1z2i"2n2PiXi2PiXi2Pi(X2i)#"z1z2#=h2nz1+2z2PiXi2z1PiXi+2z2PiX2ii"z1z2#=2nz21+4z1z2PiXi+2z22PiX2i=2[nz21+2z1z2PiXi+z22PiX2i]=2[(z1+Xiz2)2]0foranynonzerovectorZ2RnTheHessianMatrixoftheerrorfunctionwithrespectto 0and 1ispostive-semide niteandthereforetheerrorfunctionisaconvexfunct

Related Contents


Next Show more