宇宙論における線形モデル
100年も経たない昔、宇宙は静止した1つの銀河(おそらく数百万個の恒星を含む)だけで構成されていると考えられていました。現在では、数千億もの銀河が観測されており、それぞれが数千億の恒星を持ち、すべてが運動しています。
現代宇宙論のはじまりは、線形モデルの利用を含んだ1929年のEdwin Hubbleによる発表にあります。
この演習では、銀河の速度を地球からの距離の線形関数として表す定数であるハッブル定数(Hubble's Constant)を、傾きとして与えるモデルを構築します。

この演習はコースの一部です
Pythonで学ぶ線形モデリング入門
演習の手順
- 事前に読み込まれた
names、distances、velocitiesの列を持つDataFrameを使います。 formula="velocities ~ distances"、data=dfを指定して、ols().fit()でモデルを構築して当てはめます。model_fit.paramsを使って切片と傾きの推定値を取り出し、それぞれa0とa1に代入します。- 同様に、対応する不確かさについても
model_fit.bseを使って値を取り出し、同じ手順で取得します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Fit the model, based on the form of the formula
model_fit = ols(formula="velocities ~ ____", data=df).fit()
# Extract the model parameters and associated "errors" or uncertainties
a0 = model_fit.params['Intercept']
a1 = model_fit.params['____']
e0 = model_fit.bse['____']
e1 = model_fit.bse['distances']
# Print the results
print('For slope a1={:.02f}, the uncertainty in a1 is {:.02f}'.format(a1, e1))
print('For intercept a0={:.02f}, the uncertainty in a0 is {:.02f}'.format(a0, e0))