<jupyter_start><jupyter_text>Observations and Insights1. Per the below box plot, there are minimal statistical differences between Ramicane & Capomulin (Group A) and Ceftamin & Infubinol (Group B). Effectiveness of the regimens is more easily differentiated when comparing regimens in separate groups, such as Ramicane & Ceftamin2. The effectiveness of the Capomulin regimen is also evident in the 'Tumor Volume Over Time' chart. This chart depicts a negative relation ship between time and tumor volume.3. For the Capomulin regimen, there's a positive correlation between weight and tumor volume  Dependencies and starter code<jupyter_code># Dependencies and Setup
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import scipy.stats as st
from scipy.stats import linregress
%matplotlib inline

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

# Read the mouse data and the study results
mouseData = pd.read_csv(mouse_metadata)
studyResults = pd.read_csv(study_results)
mouseData.head()
studyResults.head()
# Combine the data into a single dataset
mouseResults = pd.merge(mouseData, studyResults, how = 'inner', on = 'Mouse ID')
mouseResults.head(20)
#Check for null values
mouseResults.isnull().sum()
#Determine data types
mouseResults.dtypes<jupyter_output><empty_output><jupyter_text>Summary statistics<jupyter_code># Generate a summary statistics of mean, median, variance, standard deviation, and SEM of the tumor volume for each regimen
meanVol_Reg = mouseResults.groupby(['Drug Regimen']).mean()['Tumor Volume (mm3)']
medVol_Reg = mouseResults.groupby(['Drug Regimen']).median()['Tumor Volume (mm3)']
varVol_Reg = mouseResults.groupby(['Drug Regimen']).var()['Tumor Volume (mm3)']
stdVol_Reg = mouseResults.groupby(['Drug Regimen']).std()['Tumor Volume (mm3)']
semVol_Reg = mouseResults.groupby(['Drug Regimen']).sem()['Tumor Volume (mm3)']

statsSumm_Reg = pd.DataFrame({'Mean': meanVol_Reg,
                              'Median': medVol_Reg,
                              'Variance': varVol_Reg,
                              'Std Dev': stdVol_Reg,
                              'SEM': semVol_Reg}).round(2)
statsSumm_Reg<jupyter_output><empty_output><jupyter_text>Bar plots<jupyter_code>dataPtCount_Reg = mouseResults['Drug Regimen'].value_counts()
dataPtCount_Reg
drugRegimensIndx = dataPtCount_Reg.index.values
drugRegimensIndx
# Generate a bar plot showing number of data points for each treatment regimen using pandas
dataPtBar_Reg = dataPtCount_Reg.plot(kind='bar', title='Data Points per Regimen')

dataPtBar_Reg.set_xlabel('Drug Regimen')
dataPtBar_Reg.set_ylabel('No. of Data Points')
plt.show()
# Generate a bar plot showing number of data points for each treatment regimen using pyplot
xaxis = np.arange(len(drugRegimensIndx))
plt.xticks(xaxis, drugRegimensIndx, rotation=90)

plt.bar(xaxis, dataPtCount_Reg, width = 0.5)

plt.title('Data Points per Regimen')
plt.xlabel('Drug Regimen')
plt.ylabel('No. of Data Points')
plt.show()<jupyter_output><empty_output><jupyter_text>Pie plots<jupyter_code># Generate a pie plot showing the distribution of female versus male mice using pandas
genderCount = mouseResults['Sex'].value_counts() 
genderCount.plot(kind='pie', legend=False, autopct='%1.1f%%', pctdistance=.5, title='Gender Distribution')
plt.show()
# Generate a pie plot showing the distribution of female versus male mice using pyplot
labels = genderCount.index
plt.pie(genderCount, labels=labels,autopct="%1.1f%%", pctdistance=.5)

plt.title('Gender Distribution')
plt.show()<jupyter_output><empty_output><jupyter_text>Quartiles, outliers and boxplots<jupyter_code># Confirm four most promising treatment regimens
bestRegimens = statsSumm_Reg.sort_values(['SEM']).head(4).index.tolist()
bestRegimens
# Calculate the final tumor volumes for the most promising treatment regimens by finding the max 'Timepoint' for each 'Mouse ID' and removing all other duplicates
finalVols = mouseResults.sort_values('Timepoint', ascending=False).drop_duplicates(['Mouse ID'])
finalVols.head()
# Calculate the IQR and quantitatively determine if there are any potential outliers. 
ramiVols = finalVols[finalVols['Drug Regimen'] == 'Ramicane']['Tumor Volume (mm3)']
capoVols = finalVols[finalVols['Drug Regimen'] == 'Capomulin']['Tumor Volume (mm3)']
ceftVols = finalVols[finalVols['Drug Regimen'] == 'Ceftamin']['Tumor Volume (mm3)']
infuVols = finalVols[finalVols['Drug Regimen'] == 'Infubinol']['Tumor Volume (mm3)']

bestRegVols = [ramiVols, capoVols, ceftVols, infuVols]

iqrList = []

for regimens in bestRegVols:
    quartiles = regimens.quantile([.25,.5,.75])
    lowerq = quartiles[0.25]
    upperq = quartiles[0.75]
    iqr = upperq-lowerq
    iqrList.append(iqr)
    
print(iqrList)
# Generate a box plot of the final tumor volume of each mouse across four regimens of interest
# Highlight any potential outliers in the plot by changing their color and style
fig = plt.figure(1, figsize=(9,6))
ax = fig.add_subplot(111)
green_diamond = dict(markerfacecolor='g', marker='D')
ax.boxplot(bestRegVols, labels = bestRegimens, flierprops = green_diamond )
ax.set_title('Top 4 Most Promising Regimens')
ax.set_ylabel('Final Tumor Volume (mm3)')
ax.set_xlabel('Regimens')
plt.show()<jupyter_output><empty_output><jupyter_text>Line and scatter plots<jupyter_code># Generate a line plot of time point versus tumor volume for a single (random) mouse treated with Capomulin
capoResults = mouseResults[mouseResults['Drug Regimen'] == 'Capomulin']
randomMouseID = np.random.choice(capoResults['Mouse ID'].unique())
randomMouseResults = capoResults[capoResults['Mouse ID'] == randomMouseID]

x_axis = randomMouseResults['Timepoint']
y_axis = randomMouseResults['Tumor Volume (mm3)']

plt.plot(x_axis, y_axis)
plt.title(f'Tumor Volume Over Time - Mouse ID: {randomMouseID}')
plt.xlabel("Timepoint")
plt.ylabel("Tumor Volume (mm3)")
plt.show()
# Generate a scatter plot of mouse weight versus average tumor volume for the Capomulin regimen
x_axis2 = capoResults['Timepoint']
y_axis2 = capoResults['Tumor Volume (mm3)']

plt.scatter(x_axis2, y_axis2)
plt.title(f'Tumor Volume Over Time - Capomulin Regimen')
plt.xlabel("Timepoint")
plt.ylabel("Tumor Volume (mm3)")
plt.show()
# Calculate the correlation coefficient for mouse weight and average tumor volume for the Capomulin regimen
weight = capoResults.iloc[:,4]
tumorVol = capoResults.iloc[:,6]
correlation = st.pearsonr(weight,tumorVol)
correlation[0]
# Calculate the linear regression model for mouse weight and average tumor volume for the Capomulin regimen
(slope, intercept, _, _, _) = linregress(weight, tumorVol)  ##Returns: slope, intercept, rvalue, pvalue, stderr
fit = slope * weight + intercept

plt.plot(weight, tumorVol, 'o', label='Data Points')
plt.plot(weight, intercept + slope*weight, 'r', label='Linear Regression')
plt.title(f'Weight v. Tumor Volume - Capomulin Regimen')
plt.xlabel("Weight (g)")
plt.ylabel("Tumor Volume (mm3)")
plt.legend()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11160079613306796, 'fraction_numerical': 0.008103497298834235, 'mean_word_length': 6.020958083832335, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '21391', 'license': 'ADSL', 'n_tokens_mistral': 2370, 'n_tokens_neox': 2206, 'n_words': 645, 'path': 'Pymaceuticals/pymaceuticals_starter.ipynb', 'repo_name': 'octaviaisom/Matplotlib-Challenge', 'size': '7034'}