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

Calculating statistic of interest

Using the NHANES dataset, let's investigate the relationship between gender and home ownership. Remember, more information about the dataset can be found here: NHANES.

As seen in the video, natural variability can be modeled from shuffling observations around to remove any relationships that might exist in the population. However, before you permute the data, you need to calculate the original observed statistic. In this exercise, you will calculate the difference in proportion of home owners who are men versus women.

Recall that:

  • %in% returns a logical vector that is TRUE when values on the left hand side are listed on the right hand side.
  • The mean of a logical vector is the proportion of cases where that vector is TRUE.
fruits <- c("apple", "banana", "cherry")
fruits %in% c("banana", "cherry")
mean(fruits %in% c("banana", "cherry"))

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

Foundations of Inference in R

ดูคอร์ส

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

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

homes <- NHANES %>%
  # Select Gender and HomeOwn
  ___(___, ___) %>%
  # Filter for HomeOwn equal to "Own" or "Rent"
  ___(___ %in% c("___", "___"))
แก้ไขและรันโค้ด