Stats

Popular Posts

Followers

Mathematica 教學 簡單直線迴歸

戴忠淵 於 2010年11月15日星期一 下午1:27 發表



(* 產生100對隨機樣本 *)
data=(t=Random[];{t,3+t*5+RandomReal[NormalDistribution[0,1.2]]})&/@Range[100]
(*畫出散佈圖*)
ListPlot[data,PlotStyle->PointSize[0.02]]




(*分別抽出10個樣本做簡單迴歸計算beta1,實驗重覆1,100,500,1000,10000次並畫出beta1的直方圖*)
GraphicsGrid@Partition[Histogram[Normal[LinearModelFit[RandomSample[data,10],x,x]][[2,1]]&/@Range[#]]&/@{1,10,100,500,1000,10000},3]



Tags: ,

讀者回應 ( 0 意見 )

發佈留言

Please leave your name and tell me what you thought about this site. Comments, suggestions and views are welcomed.

如果這篇文章對你有幫助,那請留個訊息給我~