You will write three functions that choose a sample in the ways of this lesson: a systematic sample, the places of a stratified sample, and a cluster sample.
The idea. A systematic sample takes every th item after a start. Proportional allocation gives a stratum of size the share of the places. A cluster sample chooses whole groups at random and keeps every member of them.
Your tasks.
systematic(frame, k, start). Return the items at positions start, start + k, start + 2k and so on. Positions count from 0, as in a Python list.allocate(sizes, n). Return a list with the number of places for each stratum, rounded to whole numbers.cluster(clusters, how_many). Choose how_many clusters with random.sample and return one list of all their members.Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…