R R.package !!!easystats https://github.com/easystats https://qiita.com/ocean_f/items/f1074f8cc05241dc28eb {{outline}} ---- !!インストール install.packages("easystats", repos = "https://easystats.r-universe.dev") !!GLMMなどの妥当性評価 !モデルパフォーマンス {{pre model_performance(modelER3f) ## # Indices of model performance ## ## AIC | BIC | R2 (cond.) | R2 (marg.) | ICC | RMSE | Sigma | Score_log | Score_spherical ## --------------------------------------------------------------------------------------------------- ## 1357.583 | 1378.366 | 0.819 | 0.532 | 0.612 | 4.957 | 1.000 | -2.501 | 0.055 }} !R2: r2() {{pre r2(modelER3f) # R2 for Mixed Models Conditional R2: 0.912 Marginal R2: 0.233 }} *Conditionalは 固定要因と変動要因を合わせた寄与率 *Marginal は固定要因のみの寄与率 !多重共線性: check_collinearity() *結果を plot() !正規性: check_normality() {{pre check_normality(modelER3f) OK: residuals appear as normally distributed (p = 0.730). }} *結果を plot() **パッケージ「see」が必要。 ***依存パッケージも必要 {{pre package ‘effectsize’ successfully unpacked and MD5 sums checked package ‘insight’ successfully unpacked and MD5 sums checked package ‘parameters’ successfully unpacked and MD5 sums checked package ‘see’ successfully unpacked and MD5 sums checked }} {{pre library(see) nom <- check_normality(modelER3f) plot(nom) }} {{ref_image nom.png}} !過分散: check_overdispersion() *ポアソン分布のみ !ゼロ過剰: check_zeloinflation() *ポアソン分布の場合のみ !!結果の報告 report() *モデルをreport()に入れるだけで、どう報告すればよいか全部書いてくれる。 {{pre report(both.model.glm) We fitted a linear model (estimated using ML) to predict IPSyn13 with year and mode (formula: IPSyn13 ~ year + mode). The model's explanatory power is substantial (R2 = 0.29). The model's intercept, corresponding to year = 1 and mode = spoken , is at 52.42 (95% CI [50.83, 54.01], t(390) = 64.56, p < .001). Within this model: - The effect of year [2] is statistically significant and positive (beta = 6.35, 95% CI [4.32, 8.38], t(390) = 6.14, p < .001; Std. beta = 0.64, 95% CI [0.44, 0.85]) - The effect of year [3] is statistically significant and positive (beta = 9.57, 95% CI [7.56, 11.58], t(390) = 9.34, p < .001; Std. beta = 0.97, 95% CI [0.76, 1.17]) - The effect of mode [written] is statistically significant and negative (beta = -6.80, 95% CI [-8.47, -5.13], t(390) = -7.98, p < .001; Std. beta = -0.69, 95% CI [-0.85, -0.52]) Standardized parameters were obtained by fitting the model on a standardized version of the dataset. 95% Confidence Intervals (CIs) and p-values were computed using a Wald t-distribution approximation. }} !簡潔にしたい場合は、summary()する {{pre report(t.best.model2) %>% summary() We fitted a poisson mixed model to predict score with timing and learning. The model included ID as random effects. The model's total explanatory power is weak (conditional R2 = 0.10) and the part related to the fixed effects alone (marginal R2) is of 0.02. The model's intercept is at 1.45 (95% CI [1.39, 1.52]). Within this model: - The effect of timing [2] is statistically significant and positive (beta = 0.16, 95% CI [0.11, 0.22], p < .001, Std. beta = 0.16) - The effect of timing [3] is statistically significant and positive (beta = 0.07, 95% CI [0.01, 0.13], p = 0.016, Std. beta = 0.07) - The effect of learning [notlearn] is statistically non-significant and negative (beta = -0.04, 95% CI [-0.09, 0.01], p = 0.126, Std. beta = -0.04) }} !report_table() {{pre report_table(both.model.glm) Parameter | Coefficient | 95% CI | t(390) | p | Std. Coef. | Std. Coef. 95% CI | Fit ---------------------------------------------------------------------------------------------------------- (Intercept) | 52.42 | [50.83, 54.01] | 64.56 | < .001 | -0.20 | [-0.36, -0.04] | year [2] | 6.35 | [ 4.32, 8.38] | 6.14 | < .001 | 0.64 | [ 0.44, 0.85] | year [3] | 9.57 | [ 7.56, 11.58] | 9.34 | < .001 | 0.97 | [ 0.76, 1.17] | mode [written] | -6.80 | [-8.47, -5.13] | -7.98 | < .001 | -0.69 | [-0.85, -0.52] | | | | | | | | AIC | | | | | | | 2801.84 BIC | | | | | | | 2821.72 R2 | | | | | | | 0.29 Sigma | | | | | | | 8.41 }} !エクセルファイルへ保存: そのまま出力をwrite.xlsxに渡せばよい。 report_table(t.best.model2) %>% write.xlsx("t.best.model2.xlsx") !!インストール {{pre install.packages("performance") library(performance) }} !!References https://qiita.com/ocean_f/items/325c5d0ef11df4b06a2d