!!!GAM 一般化加法モデル(Generalized Additive Model) *分布が非線形な場合、非線形な分布を表す一つの曲線を求めようというのでなく、 *分割して、より単純な分布を足したものとしてとらえる。 !!mgcvパッケージ:Mixed GAM Computation Vehicle with Automatic Smoothness Estimation https://cran.r-project.org/web/packages/mgcv/index.html {{pre gam.model <- gam(目的変数 ~ s(変数)+s(変数)+s(変数)+s(変数),data=dat) summary(gam.model) plot(model) }} !説明変数を s() に入れる(sはsmooth 平滑化) * オプションで kの値を明示的に設定 ** knot(全体を区分に分割する数) *** 数が多くて細かすぎると、線がぐにゃぐにゃになる ** デフォルトは自動で変数の数に応じて設定される * オプションで bs で曲線の描き方を設定 ** tp (thin plate regression spline) ** cr (cubic regression spline) * オプション sp で平滑化パラメタの数を設定 ** 少ないほうが好ましいが、少ないと線がぐにゃぐにゃになる !plot.gam {mgcv} * オプション ** residuals=F で残差表示 ** se=F で標準誤差を非表示 ** pages=1 ですべてを1ページに ** jit=T でジッター表示 ** shade=T で信頼区間を影表示 *** shade.col="色" * y軸は実測値ではなく、予測値のベースラインが0となる * 実測値を確認するには、 ** できたモデルに、データを入れて、「予測値」をプロットする {{pre predictions <- predict(モデル, newdata = データ) plot(データ$x軸の変数, predictions, type = "b") }} * plot.xy() ** typeでプロットのタイプを指定 *** p: points *** l: lines *** b: both *** o: overplotted points and lines *** s: stair steps *** h: histogram !!gamパッケージ https://cran.r-project.org/web/packages/gam/index.html !!References https://qiita.com/tabintone/items/96afd222d92e876c51d1 https://qiita.com/purple_jp/items/5d138f5652f469dbfe9f https://www.jstage.jst.go.jp/article/jbhmk/34/1/34_1_111/_pdf