BaşlayınÜcretsiz Başlayın

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.

Bu egzersiz

Experimental Design in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Shuffle the blocks to create a new DataFrame called prod_df.
  • Reset the index so that block is not both an index and a column.
  • Randomly assign the three treatment values in the 'Treatment' column.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# 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(____)
)
Kodu Düzenle ve Çalıştır