本章末尾の Exercise 18.2 を行った。
以下は「お金で成績を買えるか?」で取り上げた図 18.1 。
predictors x1 , x2 に相関がないこのデータを、スクリプト Jags-Ymet-XmetMulti-Mrobust.R を次のように変更しながら分析する。
myData = read.csv( file="MultLinRegrPlotUnif.csv" )
yName = "y" ; xName = c("x1","x2")
> ggpairs(myData)
プロット図から y と x2 に強い相関があり(0.85)、x1 と x2 には相関がない(0.00714)。y と x1 の相関 0.443 は弱いと判断する。
以下が推定結果。
係数の mode 値が、図 18.1 の回帰式 y ~ N(m, sd=2), m = 10 + 1x1 + 2x2 の係数と一致する。
次に、predictor を x1 のみにする
yName = "y" ; xName = c("x1")
Intercept が 10 から 20 へ、標準偏差(scale or σ)が 2 から 6 と大きく変化した。また Prop Var Accntd (the proportion of variance accounted for) の変化も大きい。この結果は、以下の「本課題のポイント」の通り。
Here’s the point of the exercise: Notice that even when the predictors are uncorrelated, when you include the second predictor, you get a more precise estimate of the slope on the first predictor.
相関のない predictors の場合でさえ、第 2 predictor を含めることで、第 1 predictor の係数の精度を高くできる。
データが少ない場合
以降では、同様の推定をデータを減らして行う。
myData = read.csv( file="MultLinRegrPlotUnif.csv" )
myData = myData[101:150,]
yName = "y" ; xName = c("x1","x2")
データ量は減ったが、相関は以下のようにほぼ同じ。
以下が推定結果。
全データ使用の結果と比較して、95%HDI が広く
少ないデータの場合は推定は不確実
さらに predictor を x1 のみにする。
myData = read.csv( file="MultLinRegrPlotUnif.csv" )
myData = myData[101:150,]
yName = "y" ; xName = c("x1")
x1 の係数の 95%HDI が 0 を含むという、かなり不確実な結果となった。これも、先の「本課題のポイント」の通り。
「多変量解析は簡単じゃない」に続く。







0 件のコメント:
コメントを投稿