R {{category GLMM}} {{outline}} ---- !!!GLMM {{ref_image glmmまとめ.png}} !目的変数の分布とリンク関数 ,分布,リンク関数例 ,正規(gaussian),identity ,ガンマ(Gamma),log ,二項(binomial),logit ,ポアソン(poisson),log *目的変数の分布を見て、どれを選ぶかを決める ** 正誤などの二値だったら binomial ** 正の整数だったら poisson ** 正の連続値だったら Gamma ** 正規分布だったら gaussian * !!概要 !ANOVA *yが数値データ(テストスコア等) *xがカテゴリーデータ(Low, Mid, High) model.1 <- lm(y ~ x, データ) model.0 <- lm(y ~ 1, データ) anova(model.1, model0) Anova(model.1) library(MuMIn) options(na.action = "na.fail") dredge(model.1, rank="AIC") summary(model.1) confint(model.1) library(multcomp) summary(glht(model.1, linfct = mcp(group = "Tukey"))) !Multiple Regression Analysis 重回帰分析 !LME !GLM : Generalized <> 一般化線形モデル *一人の被験者からは一回だけ(<<ランダム効果なし>>) glm(応答変数 ~ 説明変数, family=分布モデル, data) *分布モデルは、正規分布以外にも対応 *ランダム効果を入れない点が、glmerとは違う *交互作用も * で対応 *飽和モデルを作っておいて、step()でモデル選択 *Reference https://www1.doshisha.ac.jp/~mjin/R/Chap_16/16.html !GLMM: Generalized Linear <> Model 一般化線形<<混合>>モデル *一人の被験者について複数回(<<ランダム効果>>を考慮) *一つの項目について複数回(<<ランダム効果>>を考慮) *モデル式 {{pre 左辺:目的変数 右辺:説明変数    +記号で、複数の変数を並べる    :記号で、前後の交互作用を想定する    *記号で、変数の効果と組み合わせた交互作用の効果(自動で組み合わせてくれる)    ( )に入れるのがランダム効果(被験者のばらつきとか、項目のばらつきとか) }} * Reference https://youtu.be/lY_dzLMF4Jo !!注意点 !採用するモデルがきまったらsummary()でその結果を報告すること !!グラフはいろいろ描けるが、有意なグラフを見せること *有意ではない結果のグラフを見せても意味がないので、意味がない。 !plot(allEffects(モデル)) plot(allEffects(モデル), grid = TRUE) *格子付き !ggeffects を使うとrawdataも合わせてグラフにできる !!ランダム効果の注意点 *(1|変数)とすると、その変数の<<「切片」がランダム>>に異なっていると想定 **   (そもそも最初の実力にバラつきがあるとか) **   (そもそも最初から項目にバラつきがあるとか) *(0+固定効果|変数)とすると、 **   変数の「切片」は固定で、 **   固定効果の<<「傾き」がランダム>>に異なっていると想定(最初の0は書かずに省略可) *(1+固定効果|変数)とすると、 **  変数の<<「切片」と固定効果の「傾き」がランダム>>に異なっていると想定 **  (ただし、切片と傾きに相関が想定される場合) *(1|変数)+(0+固定効果|変数)とすると、 **  変数の<<「切片」と固定効果の「傾き」がランダム>>に異なっていると想定 **  (ただし、切片と傾きに相関が想定されない場合、つまり、独立にバラバラ) **  ★これは、 固定効果 + (固定効果||変数) と書いてもよい ***   (1+固定効果A+固定効果B|変数)のように複数の想定も可能 !!ランダム効果が有意かどうか調べる https://bbolker.github.io/mixedmodels-misc/glmmFAQ.html#testing-significance-of-random-effects *ランダム効果を入れたモデルと、入れないモデルを作って、 *anova()で調べる。(入れたモデルを先に) !!ランダム効果で ?isSingular と警告が出る https://rstudy.info/lmer-boundary-singular-fit-see-is-singular%E3%81%A8%E3%82%A8%E3%83%A9%E3%83%BC%E3%81%8C%E3%81%A7%E3%82%8B%E7%90%86%E7%94%B1/ https://stackoverflow.com/questions/60028673/lme4-error-boundary-singular-fit-see-issingular https://stats.stackexchange.com/questions/378939/dealing-with-singular-fit-in-mixed-models https://rdrr.io/cran/lme4/man/isSingular.html *singularかどうか、確認して、そうだとなったら、複雑なもの(ランダムスロープ)から外していく。 {{pre the random effects structure is too complex to be supported by the data, which naturally leads to the advice to remove the most complex part of the random effects structure (usually random slopes). }} {{pre Test Fitted Model for (Near) Singularity Description Evaluates whether a fitted mixed model is (almost / near) singular, i.e., the parameters are on the boundary of the feasible parameter space: variances of one or more linear combinations of effects are (close to) zero. Usage isSingular(x, tol = 1e-4) }} !!妥当性評価 easystats !LMEのモデルが妥当か検証 https://bookdown.org/animestina/phd_july_19/testing-the-assumptions.html !!References *https://strengejacke.github.io/sjPlot/ *https://cran.r-project.org/web/packages/sjPlot/vignettes/plot_interactions.html *https://ademos.people.uic.edu/ *https://bbolker.github.io/mixedmodels-misc/glmmFAQ.html *https://mspeekenbrink.github.io/sdam-r-companion/linear-mixed-effects-models.html *https://kuboweb.github.io/-kubo/ce/FaqGlm.html#toc5 *https://bookdown.org/animestina/phd_july_19/testing-the-assumptions.html *https://stats.stackexchange.com/questions/77891/checking-assumptions-lmer-lme-mixed-models-in-r *https://ademos.people.uic.edu/Chapter18.html#61_assumption_1_-_linearity *https://vasishth.github.io/Freq_CogSci/ *http://joshuawiley.com/MonashHonoursStatistics/LMM_Intro.html *http://data-science.tokyo/ed/edj1-2-1-4.html *Log-linked Gamma GLM vs log-linked Gaussian GLM vs log-transformed LM https://stats.stackexchange.com/questions/77579/log-linked-gamma-glm-vs-log-linked-gaussian-glm-vs-log-transformed-lm *Bates et al. (2015) Fitting Linear Mixed-Effects Models Using lme4, J of Statistical Software. 67(1). doi: 10.18637/jss.v067.i01 *https://stats.stackexchange.com/questions/13166/rs-lmer-cheat-sheet/13173#13173 *Barr, Dale J, R. Levy, C. Scheepers und H. J. Tily (2013). Random effects structure for confirmatory hypothesis testing: Keep it maximal. Journal of Memory and Language, 68:255– 278. *村山 航, 刺激の効果を侮るなかれ―ランダム刺激効果を含んだ線形混合モデルの重要性と落とし穴―, 基礎心理学研究, 2017, 36 巻, 2 号, p. 236-242, 公開日 2018/06/16, Online ISSN 2188-7977, Print ISSN 0287-7651, https://doi.org/10.14947/psychono.36.40, https://www.jstage.jst.go.jp/article/psychono/36/2/36_36.40/_article/-char/ja *Murakami 2015 Modeling systematicity and individuality in nonlinear second language development: The case of English grammatical morphemes. https://osf.io/dbuh4/ *[GLMM FAQ|https://bbolker.github.io/mixedmodels-misc/glmmFAQ.html] *https://kuboweb.github.io/-kubo/ce/FaqGlm.html *一般化線形モデルを実行したいならRがおすすめ https://www.kyougokumakoto.com/2019/07/r-glm.html *R言語 一般化線形モデル・glmの使いかた【初心者向け】https://multivariate-statistics.com/2021/03/06/r-programming-generalized-linear-model/ *生態学のデータ解析 - FAQ 一般化線形モデル https://kuboweb.github.io/-kubo/ce/FaqGlm.html *生態学のデータ解析 - FAQ モデル選択 https://kuboweb.github.io/-kubo/ce/FaqModelSelection.html *https://socinuit.hatenablog.com/entry/2019/12/21/042023 !!入門用参考図書 *嶋田・阿部(2017)『Rで学ぶ統計学入門』東京化学同人 *馬場(2015)   『平均・分散から始める一般化線形モデル入門』プレアデス出版 *堀(2017)    『ゼロからはじめる統計モデリング』ナカニシヤ出版 *粕谷(2012)   『一般化線形モデル』共立出版 *藤井(2010)   『カテゴリカルデータ解析』共立出版