เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Plotting results

In the previous exercises, you have examined the raw data, used the data to build a model, and applied the model for statistical inferences. You found drug 2 increased the amount of extra sleep compared to drug 1. During this exercise, you will plot the results to see how much drug 2 increased extra sleep.

First, wrangle the data by using pivot_wider() function from the tidyr package. Then, calculate the difference in extra sleep for each individual. Last, plot this difference as a histogram.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Hierarchical and Mixed Effects Models in R

ดูคอร์ส

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Load the tidyr package
library(___)

# Make the data wider
___ <- 
	pivot_wider(sleep, 
                names_from = group, values_from = extra)

# Calculate the difference 
sleep_wide$___ <- sleep_wide$`2` - sleep_wide$`1` 
แก้ไขและรันโค้ด