xmeanxavg ymeanysxxsumx0avg x2sxysumx0avg x3y0avg yb1isxysxxb0iavg y0b1i3avg xendDrawhistogramsofthecoe14cientsb0andb1histb0histb1 Figure1 ID: 846798
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.
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((xavg x):2);sxy=sum((xavg x):(yavg y));b1(i)=sxy=sxx;b0(i)=avg yb1(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)holdoxlabel('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)holdoxlabel('b1')ylabel('40*Frequency')4 Figure4:Histogramandpdfcurveofb1onthesameplotAswecanseefromFigure3andFigure4,theshapeofthehistogramofthecoecientsobtainedfromthe200timessimulationsissimilartothatofthecurveoftheestimateddistubtioinofthecoecients.2.(20points)Usethesamedatasetinthelastproblem,wewillestimate0and1usingNewton-Raphsonmethod.a.Drawa3dplotusingMATLAB(check"surf"commandforexample)toillustratehowth
3 eSSEvariesaccordingtodierentcombina
eSSEvariesaccordingtodierentcombinationsofestimatesof0and1.Sotospeak,drawa3dplotwherexandyaxesrepresentdierentvaluesofslopeandinterceptoftheregressionlinerespectively,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((Yx(j)
ori=1:61forj=1:615 z(i;j)=sum((Yx(j)y(i)X):2);endendmeshgrid(x,y,z)surf(x,y,z) Figure5:3DplotofSSEversustheslopeandtheinterceptoftheregressionlineb.UseNewton-RaphsonmethodtominimizethefunctionF()=SSEandgettheesti-matesoftheparameters.HereweusetheiterationsHF(n)(n+1n)=rF(n)whereHF(n)istheHessianmatrix(second-orderpartialderivativesofthefunctionSSE)andrF(n)isgradient.rF="2Pi(Yi01Xi)2Pi((Yi01
5 Xi)Xi)#HF="2n2PiXi2PiXi2Pi(X2i)#="&
Xi)Xi)#HF="2n2PiXi2PiXi2Pi(X2i)#="01#TheMatlabcodeis:function[beta,SSE]=NR linear(data,beta start)x=data(:;1);y=data(:;2);n=length(x);di=1;beta=beta start;whiledi0: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((ybeta(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(0and1).Answer:TheerrorfunctionE=Pni=1(Yi0
7 ;1Xi)2Toprovetheerrorfunctionis
;1Xi)2Toprovetheerrorfunctionisconvexwithrespectto0and1,weneedtoshowthattheHessianmatrixoftheerrorfunctionispostive-semidenite.SupposewehaveanonzerovectorZ="z1z2#ZTHZ=hz1z2i"2n2PiXi2PiXi2Pi(X2i)#"z1z2#=h2nz1+2z2PiXi2z1PiXi+2z2PiX2ii"z1z2#=2nz21+4z1z2PiXi+2z22PiX2i=2[nz21+2z1z2PiXi+z22PiX2i]=2[(z1+Xiz2)2]0foranynonzerovectorZ2RnTheHessianMatrixoftheerrorfunctionwithrespectto0and1ispostive-semideniteandthereforetheerrorfunctionisaconvexfunct