Get startedGet started for free

Calculating the sample size

You're now going to utilize the sample size function to determine how many users you need for the test and control groups under various circumstances.

Included is the get_sample_size() function you viewed previously, which takes four primary arguments, power, p1, p2 and cl as described before:

def get_sample_size(power, p1, p2, cl, max_n=1000000):
    n = 1 
    while n <= max_n:
        tmp_power = get_power(n, p1, p2, cl)

        if tmp_power >= power: 
            return n 
        else: 
            n = n + 100

    return "Increase Max N Value"

You will continue working with the paywall conversion rate data for this exercise, which has been pre-loaded as purchase_data.

This exercise is part of the course

Customer Analytics and A/B Testing in Python

View Course

Hands-on interactive exercise

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

# Merge the demographics and purchase data to only include paywall views
purchase_data = demographics_data.merge(paywall_views, how='inner', on=['uid'])
                            
# Find the conversion rate
conversion_rate = (sum(purchase_data.____) / purchase_data.____.count())
            
print(conversion_rate)
Edit and Run Code