# Problem Statement:

\begin{equation} H_{0} : p_{gate30} - p_{gate40} >= 0 \end{equation}

\begin{equation} H_{1} : p_{gate30} - p_{gate40} < 0 \end{equation}


```python
import pandas as pd
import numpy as np
import random
import matplotlib.pyplot as plt
%matplotlib inline
```

## Read & Understand the data


```python
### Your Code Here ###
df = pd.read_csv('cookie_cats.csv')
df.head()
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>userid</th>
      <th>version</th>
      <th>sum_gamerounds</th>
      <th>retention_1</th>
      <th>retention_7</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>116</td>
      <td>gate_30</td>
      <td>3</td>
      <td>False</td>
      <td>False</td>
    </tr>
    <tr>
      <th>1</th>
      <td>337</td>
      <td>gate_30</td>
      <td>38</td>
      <td>True</td>
      <td>False</td>
    </tr>
    <tr>
      <th>2</th>
      <td>377</td>
      <td>gate_40</td>
      <td>165</td>
      <td>True</td>
      <td>False</td>
    </tr>
    <tr>
      <th>3</th>
      <td>483</td>
      <td>gate_40</td>
      <td>1</td>
      <td>False</td>
      <td>False</td>
    </tr>
    <tr>
      <th>4</th>
      <td>488</td>
      <td>gate_40</td>
      <td>179</td>
      <td>True</td>
      <td>True</td>
    </tr>
  </tbody>
</table>
</div>




```python
df.shape
```




    (90189, 5)




```python
df.isnull().any().sum()
```




    0




```python
df.userid.duplicated().sum()
```




    0



### How many player in each group?

##### Hint: Use groupby with count


```python
### Your Code Here ###
df.groupby('version').count()
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>userid</th>
      <th>sum_gamerounds</th>
      <th>retention_1</th>
      <th>retention_7</th>
    </tr>
    <tr>
      <th>version</th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>gate_30</th>
      <td>44700</td>
      <td>44700</td>
      <td>44700</td>
      <td>44700</td>
    </tr>
    <tr>
      <th>gate_40</th>
      <td>45489</td>
      <td>45489</td>
      <td>45489</td>
      <td>45489</td>
    </tr>
  </tbody>
</table>
</div>



### What is the percentage of users that came back the day after they installed?


```python
### Your Code Here ###
df.retention_1.mean()
```




    0.4452095044850259



### What is the percentage of users of each group [gate_30, gate_40] that came back the day after they installed?



```python
### Your Code Here ###
gate_30 = df.query("version == 'gate_30'").retention_1.mean()
gate_40 = df.query("version == 'gate_40'").retention_1.mean()
gate_30, gate_40

obs_sample = gate_30 - gate_40
obs_sample
```




    0.005905169787341458



### Bootstrap the data by resampling the dataset with replacement for retention_1

##### Hint:  use .sample method with frac = 1 and replace = True
##### Hint:  groupby the result of sampling by version column then select retention_1 column and apply mean as an agg function
##### Hint: take difference in mean between the 2 groups in each iteration and append it to a list


```python
df_30 = df.query("version == 'gate_30'")
df_40 = df.query("version == 'gate_40'")
```


```python
### Your Code Here ###
diffs = []
for _ in range(10000):
    sample_30 = np.random.choice([0,1],df_30.shape[0], p = [1-gate_30, gate_30])
    sample_40 = np.random.choice([0,1],df_40.shape[0], p = [1-gate_40, gate_40])
    diff = sample_30.mean() - sample_40.mean()
    diffs.append(diff)
    
```

### Plot the difference distribution 


```python
### Your Code Here ###
plt.hist(diffs);
```

### At alpha level 0.05, should we reject the null ?
##### Hint: Calculate the STDerr, Simulate under the null, Calculate the p-value


```python
diffs = np.array(diffs)
```


```python
### Your Code Here ###
under_null = np.random.normal(0, diffs.std(), 10000)
```


```python
### Your Code Here ###
plt.hist(under_null)
plt.axvline(x= obs_sample, color = 'r');
```


```python
P_value = (under_null < obs_sample).mean()
P_value
```




    0.9653



**Since P_Value is (0.9648) > alpha (0.05), So we Fail to Reject the Null Hypothesis.**


```python

```

c49877941fe9dd8eab3fb6dd69571e1695920bf4
ipynb
Jupyter Notebook
Cookie Cats AB testing.ipynb
asmaamahrous91/AB-Test-for-Cookie-Cats
a6ba41806cc2b509f8e2f38dcc05c49b27e404a4
Unlicense
Cookie Cats AB testing.ipynb
asmaamahrous91/AB-Test-for-Cookie-Cats
a6ba41806cc2b509f8e2f38dcc05c49b27e404a4
Unlicense
Cookie Cats AB testing.ipynb
asmaamahrous91/AB-Test-for-Cookie-Cats
a6ba41806cc2b509f8e2f38dcc05c49b27e404a4
Unlicense
Qwen/Qwen-72B
1. YES
2. YES