Implementing a randomized block design
The manufacturing firm you worked with earlier is still interested in conducting some experiments on worker productivity. Previously, the two blocks were set randomly. While this can work, it can be better to group subjects based on similar characteristics.
The same employees are again loaded but this time in a DataFrame called productivity including 1200 other colleagues. It also includes a worker 'productivity_score' column based on units produced per hour. This column was binned into three groups to generate blocks based on similar productivity values. The firm would like to apply a new incentive program with three options ('Bonus', 'Profit Sharing' and 'Work from Home') throughout the firm with treatment applied randomly.
numpy and pandas as np and pd respectively are loaded.
Questo esercizio fa parte del corso
Experimental Design in Python
Istruzioni dell'esercizio
- Shuffle the
blocks to create a new DataFrame calledprod_df. - Reset the index so that
blockis not both an index and a column. - Randomly assign the three treatment values in the
'Treatment'column.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# Randomly assign workers to blocks
prod_df = productivity.____('____').apply(
lambda x: x.____(____)
)
# Reset the index
prod_df = prod_df.____(____)
# Assign treatment randomly
prod_df['Treatment'] = np.random.choice(
['____', '____', '____'],
size=len(____)
)