Get startedGet started for free

ANOVA within blocks of employees

Building on your previous analyses with the manufacturing firm, where worker productivity was examined across different blocks and an incentive program was introduced, you're now delving deeper into the data. The firm, equipped with a more comprehensive dataset in the productivity DataFrame, including 1200 additional employees and their productivity_score, has structured the workforce into three blocks based on productivity levels. Each employee has been randomly assigned one of three incentive options: 'Bonus', 'Profit Sharing', or 'Work from Home'.

Before assessing the full impact of these incentive treatments on productivity, it's crucial to verify that the initial treatment assignment was indeed random and equitable across the different productivity blocks. This step ensures that any observed differences in productivity post-treatment can be confidently attributed to the incentive programs themselves, rather than pre-existing disparities in the blocks.

The f_oneway() function from scipy.stats has been loaded for you.

This exercise is part of the course

Experimental Design in Python

View Course

Exercise instructions

  • Group prod_df by the appropriate column that represents different blocks in your data.
  • Use a lambda function to apply the ANOVA test within each block, specifying the lambda function's argument.
  • For each treatment group within the blocks, filter prod_df based on the 'Treatment' column values and select the 'productivity_score' column.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Perform the within blocks ANOVA, first grouping by block
within_block_anova = prod_df.groupby('____').apply(
  # Set function
  lambda x: ____(
    # Filter Treatment values based on outcome
    x[x['____'] == '____']['____'], 
    x[x['____'] == '____']['____'],
    x[x['____'] == '____']['____'])
)
print(within_block_anova)
Edit and Run Code