<jupyter_start><jupyter_text>Observations and Insights The sex and age of a mouse don't appear to have any direct impact on the effectiveness of a given drug regimen. The data was a fairly even split with just a slight difference of .6% among sex, but that small difference and the range of mice age didn't seem to impact effectiveness.The two most promising drug regimens, Capomulin and Ramicane, also happen to have the 2 largest counts of data points. These large sets could have skewed their perceived effectiveness.There's a relatively strong correlation between mouse weight and average tumor volume at a score of .53, showing that as a mouse's tumor grows, as does the total weight of the mouse. However, there are other variables worth considering when examining this correlation, such as how the mouse's age may be impacting the weight as well.  Dependencies and starter code<jupyter_code>%matplotlib notebook
# Dependencies and Setup
import matplotlib.pyplot as plt
import pandas as pd
import scipy.stats as st
import numpy as np

# Study data files
mouse_metadata = "data/Mouse_metadata.csv"
study_results = "data/Study_results.csv"

# Read the mouse data and the study results
mouse_metadata = pd.read_csv(mouse_metadata)
study_results = pd.read_csv(study_results)

# Combine the data into a single dataset
merge_df = pd.merge(study_results, mouse_metadata, how='left', on=['Mouse ID'])
merge_df.head()
merge_df = merge_df.dropna()
merge_df.head()<jupyter_output><empty_output><jupyter_text>Summary statistics<jupyter_code># Generate a summary statistics table of mean, median, variance, standard deviation, and SEM of the tumor volume for each regimen
drug_group = merge_df.groupby(['Drug Regimen'])
drugs_mean = drug_group.mean()['Tumor Volume (mm3)']

stats_sum = pd.DataFrame(data=drugs_mean)
stats_sum.columns=['Tumor Volume Mean']
stats_sum
for index, row in stats_sum.iterrows():
    stats_sum['Tumor Volume Median'] = drug_group.median()['Tumor Volume (mm3)']
    stats_sum['Tumor Volume Variance'] = drug_group['Tumor Volume (mm3)'].var()
    stats_sum['Standard Deviation'] = drug_group['Tumor Volume (mm3)'].std()
    stats_sum['SEM'] = drug_group['Tumor Volume (mm3)'].sem()

stats_sum<jupyter_output><empty_output><jupyter_text>Bar plots<jupyter_code># Generate a bar plot showing number of data points for each treatment regimen using pandas
datapts = merge_df['Drug Regimen'].value_counts()
datapts_df = pd.DataFrame(datapts)
datapts_df.columns=['Count of Points']
datapts_df.index.names = ['Drug Regimen']
datapts_df.plot(kind='bar', figsize=(6,10), legend=False)
plt.title('Data Points by Regimen')
plt.ylabel('Count of Points')
# Generate a bar plot showing number of data points for each treatment regimen using pyplot
x_axis = np.arange(len(datapts_df))
tick_locations = [value for value in x_axis]
plt.figure(figsize=(6, 10))
plt.bar(x_axis, datapts_df['Count of Points'], color='b', alpha=0.6)
plt.xticks(tick_locations, datapts_df.index.values, rotation='vertical')
plt.title('Data Points by Regimen')
plt.xlabel('Drug Regimen')
plt.ylabel('Count of Points')
plt.tight_layout()<jupyter_output><empty_output><jupyter_text>Pie plots<jupyter_code># Generate a pie plot showing the distribution of female versus male mice using pandas
mice_count = merge_df['Sex'].value_counts()
mice_count_df = pd.DataFrame(mice_count)
mice_count_df.columns=['Count']
mice_count_df.index.names = ['Sex']

mice_count_df.plot.pie(y='Count', legend=False, autopct="%1.1f%%",startangle=60,shadow=True)
plt.title('Mouse Distribution')
plt.ylabel('')
# Generate a pie plot showing the distribution of female versus male mice using pyplot
colors = ['Teal','Orange']
plt.title('Mouse Distribution')
plt.pie(mice_count_df, labels=mice_count_df.index.values, colors=colors, autopct="%1.1f%%",shadow=True,startangle=60)
plt.axis('equal')<jupyter_output><empty_output><jupyter_text>Quartiles, outliers and boxplots<jupyter_code># Calculate the final tumor volume of each mouse across four of the most promising treatment regimens. 
# Calculate the IQR and quantitatively determine if there are any potential outliers. 
stats_sum.nsmallest(4, 'SEM')
most_promising = merge_df.loc[merge_df['Drug Regimen'].isin(['Ramicane', 'Capomulin', 'Infubinol', 'Ceftamin'])]
mp_grp = most_promising.groupby(['Mouse ID'])
final_vol = mp_grp.last()
final_vol
quartiles = final_vol['Tumor Volume (mm3)'].quantile([.25,.5,.75])
lowerq = quartiles[0.25]
upperq = quartiles[0.75]
iqr = upperq-lowerq

lower_bound = lowerq - (1.5*iqr)
upper_bound = upperq + (1.5*iqr)

print(f'The IQR is {iqr}, and values below {lower_bound} or above {upper_bound} could be outliers.')
final_volram = final_vol.loc[final_vol['Drug Regimen'].isin(['Ramicane'])]
final_volcap = final_vol.loc[final_vol['Drug Regimen'].isin(['Capomulin'])]
final_volinf = final_vol.loc[final_vol['Drug Regimen'].isin(['Infubinol'])]
final_volcef = final_vol.loc[final_vol['Drug Regimen'].isin(['Ceftamin'])]
# Generate a box plot of the final tumor volume of each mouse across four regimens of interest
vol_data = [final_volram, final_volcap, final_volinf, final_volcef]

fig, ax = plt.subplots()
pos = np.array(range(len(vol_data))) + 1
bp = ax.boxplot(vol_data, sym='k+', positions=pos,
                notch=1, bootstrap=5000)

# fig2, ax2 = plt.subplots()
# ax2.set_title('Capomulin: Final Volume')
# ax2.boxplot(final_volcap['Tumor Volume (mm3)'])<jupyter_output><empty_output><jupyter_text>Line and scatter plots<jupyter_code># Generate a line plot of time point versus tumor volume for a mouse treated with Capomulin
cap_mouse = merge_df.loc[merge_df['Mouse ID'].isin(['y793'])]
x_axis = cap_mouse['Timepoint']
y_axis = cap_mouse['Tumor Volume (mm3)']
plt.plot(x_axis, y_axis)
plt.xlabel('Timepoint')
plt.ylabel('Tumor Volume')
plt.title('Mouse(y793) treated with Capomulin')
# Generate a scatter plot of mouse weight versus average tumor volume for the Capomulin regimen
cap_mice = merge_df.loc[merge_df['Drug Regimen'].isin(['Capomulin'])]
mouse_weight = cap_mice['Weight (g)']
mouse_vol = cap_mice['Tumor Volume (mm3)']
plt.scatter(mouse_weight, mouse_vol)
plt.xlabel('Mouse Weight (g)')
plt.ylabel('Tumor Volume (mm3)')
plt.title('Mouse Weight vs. Average Tumor Volume')
# Calculate the correlation coefficient and linear regression model for mouse weight and average 
# tumor volume for the Capomulin regimen
vc_slope, vc_int, vc_r, vc_p, vc_std_err = st.linregress(mouse_weight, mouse_vol)
vc_fit = vc_slope * mouse_weight + vc_int
plt.plot(mouse_weight, vc_fit, '-', label='y={:.2f}x+{:.2f}'.format(vc_slope,vc_int))
plt.legend(fontsize=12)

print(f'The correlation coefficient is {round(st.pearsonr(mouse_weight, mouse_vol)[0],2)}')<jupyter_output>The correlation coefficient is 0.53
{'fraction_non_alphanumeric': 0.11860637509266123, 'fraction_numerical': 0.010526315789473684, 'mean_word_length': 6.709714285714286, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '142090', 'license': 'ADSL', 'n_tokens_mistral': 2364, 'n_tokens_neox': 2207, 'n_words': 642, 'path': 'Pymaceuticals/pymaceuticals_starter.ipynb', 'repo_name': 'caschkerke/matplotlib-homework', 'size': '6745'}