Course 1.2Lesson 1 of 3
A simple random sample gives every group of people in the population the same chance of being the sample. This lesson shows how to choose one with names in a hat, with random digits and with Python's random.sample, and what a sampling frame is.
This lesson is free to read. Enroll free to keep your place and take the tests.
Try the code and the simulations beside the lesson.
random.sample in Python;A class of 30 students must send 6 to a meeting. The teacher writes every name on a slip of paper, folds the slips, shakes them in a hat and draws 6 without looking. Nobody can complain. Every student had the same chance.
In First Steps you met this idea as "choosing by chance". Now we give it its proper name and look at it more closely.
A simple random sample (SRS) of size is chosen so that every possible group of members of the population has the same chance of being the sample. Then each member has the same chance too: , where is the size of the population.
The second fact does not give the first. Suppose a teacher picks 3 boys and 3 girls from a class of 15 boys and 15 girls. Each student has the chance , the same as in a simple random sample of 6 from 30. But a group of 6 boys can never be chosen. So this is not a simple random sample. (It is a stratified sample, which the next lesson meets.)
random.sample(class_list, 6) picks 6 different members, and every group of 6 is equally likely.Be careful with random.choices(class_list, k=6). It picks with replacement, so the same student can come up twice. That is not a simple random sample.
You can only choose from a list. The list you choose from is the sampling frame. If the frame leaves people out, so does the sample, however random the choice. A sample of a town drawn from a list of house owners can never include people who rent. This is the undercoverage of the first course, now seen from the inside.
A school has 1000 students, and 450 of them are girls. A simple random sample of 40 is chosen.
The program takes one simple random sample of 6 from a class of 30. Then it takes samples and counts how often roll number 1 is chosen.
Your turn.
random.choices can repeat a name. Use random.sample.random.sample, never "by eye".random.seed(...) makes a program pick the same "random" sample every time, which helps when you check work.Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
random.sample(names, 4) and random.choices(names, k=4)?Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…