開始使用免費開始

顯示 lmer 模型的結果

資料科學家必須能夠清楚表達自己的工作,而 DataCamp 也提供了相關的[課程](https://www.datacamp.com/courses/communicating-with-data-in-the-tidyverse)。 說明你的工作有助於讓受眾理解結果。 要做到這點,請根據受眾的知識程度與期待來調整你的呈現方式。

對非技術受眾,請描述輸出中最重要的發現。例如,你可以說,母親年齡較高的郡,出生率往往較低。 對技術受眾,請包含係數估計值、信賴區間與檢定統計量等細節。 像是 The Chicago Guide to Writing about Multivariate Analysis 這類書籍提供了描述迴歸輸出的建議。

在本練習中,你會擷取並繪製固定效果。除了繪製係數(使用 geom_point())以及其 95% 信賴區間(使用 geom_linerange())之外,你還會在圖上加入紅色水平線來幫助辨識 0 的位置(使用 geom_hline())。如果 95% 信賴區間不包含 0,則該係數的估計與 0 有顯著差異。

因為 ggplot 不支援 xminxmax,只支援 yminymax,所以需要使用 coord_flip()。另外,theme_minimal() 會把主題改成非預設樣式。

技術說明:lmer 萃取迴歸係數並不容易(可參考 lmerbroom 作者之間的[討論](https://github.com/tidyverse/broom/issues/96))。

本練習屬於課程

R 的階層式與混合效果模型

檢視課程

練習說明

  • 使用 broom.mixed 套件的 tidy() 從模型 out 擷取係數,並包含信賴區間。
  • 使用既有的程式碼來篩掉隨機效果的估計值。
  • 將係數表格列印到螢幕上。
  • 使用 ggplot2 繪製輸出。x 軸使用 term,y 軸使用 estimateymin 使用 conf.lowymax 使用 conf.high

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Extract out the parameter estimates and confidence intervals
coef_estimates <-
	___(___, ___) %>%
	filter(effect == "fixed")

# Print the new dataframe
print(___)

# Plot the results using ggplot2
ggplot(coef_estimates, aes(x = ___, y = ___,
                     ymin = ___, ymax = ___)) +
    geom_hline( yintercept = 0, color = 'red' ) +
    geom_linerange() + geom_point() + coord_flip() + theme_minimal()
編輯並執行程式碼