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

Step-by-step through the permutation

To help you understand the code used to create the randomization distribution, this exercise will walk you through the steps of the infer framework. In particular, you'll see how differences in the generated replicates affect the calculated statistics.

After running the infer steps, be sure to notice that the numbers are slightly different for each replicate.

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

Foundations of Inference in R

ดูคอร์ส

คำแนะนำการฝึกหัด

The dplyr and infer packages have been loaded for you, along with the disc data frame from the last exercise.

  • Call the functions for the first three steps. The work has been done for you, your job is to investigate the results of calling the first three infer steps.
  • In order to see the effect of permuting,
    • group the permuted data frame, disc_perm, by the new replicate variable, then
    • count the variables of interest (promote within each sex) using count().
  • Using disc_perm, calculate() the statistic of interest. Set stat to "diff in props" and order to c("male", "female").

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

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

# Replicate the entire data frame, permuting the promote variable
disc_perm <- disc %>%
  specify(promote ~ sex, success = "promoted") %>%
  hypothesize(null = "independence") %>%
  generate(reps = 5, type = "permute")

disc_perm %>%
  # Group by replicate
  ___ %>%
  # Count per group
  ___

disc_perm %>%
  # Calculate difference in proportion, male then female
  ___
แก้ไขและรันโค้ด