Latest commit

History

60 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Matplotlib - The Power of Plots

"Visual storytelling of one kind or another has been around since caveman were drawing on the walls." Frank Darabont

Laboratory

Background

This respository apply a Python Matplotlib to visualize a real-world pharmaceutical data. The data is sourced from Pymaceuticals Inc., a burgeoning pharmaceutical company based out of San Diego. Pymaceuticals specializes in anti-cancer pharmaceuticals. In its most recent efforts, it began screening for potential treatments for squamous cell carcinoma (SCC), a commonly occurring form of skin cancer.

These analysis used a complete data from their most recent animal study in two datasets in CSV format. Data set one is Mouse_metadata.csv wich includes 249 mice identified data with SCC tumor growth were treated through a variety of drug regimens, and their Sex, Age_months and Weight (g) identified. The other dataset is Study_results.csv file which includes the results of the study in each columns Mouse I,Timepoint,Tumor Volume (mm3), and Metastatic Sites.

The purpose of this study was to compare the performance of Pymaceuticals' drug of interest, Capomulin, versus the other treatment regimens. The analysis also generated all of the table and figures needed for the technical, and top-level summary report of the study. For this analysis both datasets imported, merged,cleaned and the aggregate data diplayed in to Python Pandas dataframes, visualized in Matplotlib, and other libraries used in order to make a stastical analysis. The project is conducted in Jupyter notebook to showcase, and communicate the analysis report the following link is created: Jupyter Notebook Viewer

Observable Trends

  • The bar graph showed the Drug Regimen Capomulin has the maximum mice number (230), and Zoniferol has the smaller mice number (182).By removing duplicates the total number of mice is 248. The total count of mice by gender also showed that 124 female mice and 125 male mice.
  • The correlation between mouse weight, and average tumor volume is 0.84. It is a strong positive correlation, when the mouse weight increases the average tumor volume also increases.
  • The regression analysis helped us to understand how much the average tumor volume (dependent variable) will change when weight of mice change(independent variables). The R-squared value is 0.70, which means 70% the model fit the data, wich is fairely good to predict the data from the model. Higher R-squared values represent smaller differences between the observed data, and the fitted value. 70% the model explains all of the variation in the response variable around its mean.
  • From the selected treatments Capomulin and Ramicane reduces the size of tumors better.

Table of Contents

Solutions

Data Cleaning

  • The data was loaded, read, combined, duplicate removed, and the head (5 rows on the top) of cleaned data out put looks as follows
Mouse IDDrug RegimenSexAge_monthsWeight (g)TimepointTumor Volume (mm3)Metastatic Sites
0k403RamicaneMale2116045.0000000
1k403RamicaneMale2116538.8258980
2k403RamicaneMale21161035.0142711
3k403RamicaneMale21161534.2239921
4k403RamicaneMale21162032.9977291

Summary statistics

  • A summary statistics table was generated by using two techniques one is by creating multiple series, and putting them all together at the end, and the other method produces everything in a single groupby function. The summery statistic table consis the mean, median, variance, standard deviation, and SEM of the tumor volume for each drug regimen. The summery stastics tables looks as follws:
MeanMedianVarianceStandard DeviationSEM
Drug Regimen
Capomulin40.67574141.55780924.9477644.9947740.329346
Ceftamin52.59117251.77615739.2901776.2681880.469821
Infubinol52.88479551.82058443.1286846.5672430.492236
Ketapril55.23563853.69874368.5535778.2797090.603860
Naftisol54.33156552.50928566.1734798.1347080.596466
Placebo54.03358152.28893461.1680837.8210030.581331
Propriva52.32093050.44626643.8520136.6220850.544332
Ramicane40.21674540.67323623.4867044.8463080.320955
Stelasyn54.23314952.43173759.4505627.7104190.573111
Zoniferol53.23650751.81847948.5333556.9665890.516398

Bar and Pie Charts

  • Two identical bar charts was generated by using both Pandas's DataFrame.plot() and Matplotlib's pyplot that shows the number of total mice for each treatment regimen throughout the course of the study.

    The Bar Cahrts looks as follows:

Bar Chart on the Number of Mice per Treatment (Pandas's DataFrame.plot())

Pandas's DataFrame.plot()

Bar Chart on the Number of Mice per Treatment (Matplotlib's pyplot)

Matplotlib's pyplot

  • Two identical pie plot was generated by using both Pandas's DataFrame.plot() and Matplotlib's pyplot that shows the distribution of female or male mice in the study.

Pi Chart on the distribution of female or male mice in the study (Pandas's DataFrame.plot())

Pandas's DataFrame.plot()

Pi Chart on the distribution of female or male mice in the study (Matplotlib's pyplot)

Matplotlib's pyplot

Quartiles, Outliers and Boxplots

  • The final tumor volume of each mouse across four of the most promising treatment regimens was created: Capomulin, Ramicane, Infubinol, and Ceftamin. Afterward the quartiles, IQR, and potential outliers across all the four treatment regimens was quantitatively determined.

Capomulin Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0b12845CapomulinFemale92238.9828782
1b74245CapomulinMale72138.9396330
2f96620CapomulinMale161730.4859850
3g28845CapomulinMale31937.0740241
4g31645CapomulinFemale222240.1592202

Capomulin Quartiles and IQR

Capomulin_tumors=Capomulin_merge["Tumor Volume (mm3)"]
quartiles=Capomulin_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of Capomulin tumors: {lowerq}")
print(f"The upper quartile of Capomulin tumors: {upperq}")
print(f"The interquartile range of Capomulin tumors: {iqr}")
print(f"The median of Capomulin tumors: {quartiles[0.5]} ")

The output looks as follws: Capomulinc

Capomulin Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Capomulin outliers_upper and lower_bounds

Ramicane Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a41145RamicaneMale32238.4076181
1a44445RamicaneFemale102543.0475430
2a52045RamicaneMale132138.8103661
3a64445RamicaneFemale71732.9785221
4c45830RamicaneFemale232038.3420082

Ramicane Quartiles and IQR

Ramicane_tumors=Ramicane_merge["Tumor Volume (mm3)"]
quartiles=Ramicane_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of Ramicane tumors is: {lowerq}")
print(f"The upper quartile of Ramicane tumors is: {upperq}")
print(f"The interquartile range of Ramicane tumors is: {iqr}")
print(f"The median of Ramicane tumors is: {quartiles[0.5]} ")

The output looks as follws: Ramicane quartiles and IQR

Ramicane Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Ramicane outliers_upper and lower_bounds

Infubinol Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a20345InfubinolFemale202367.9734192
1a25145InfubinolFemale212565.5257431
2a57730InfubinolFemale62557.0318622
3a68545InfubinolMale83066.0830663
4c13945InfubinolMale112872.2267312

Infubinol Quartiles and IQR

Infubinol_last=Infubinol_df.groupby('Mouse ID').max()['Timepoint']
Infubinol_vol=pd.DataFrame(Infubinol_last)
Infubinol_merge=pd.merge(Infubinol_vol, Combined_data, on=("Mouse ID","Timepoint"),how="left")
Infubinol_merge.head()

The output looks as follws: Infubinol quartiles and IQR

Infubinol Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Infubinol outliers_upper and lower_bounds

Ceftamin Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a27545CeftaminFemale202862.9993563
1b4470CeftaminMale23045.0000000
2b48725CeftaminFemale62856.0577491
3b75930CeftaminFemale122555.7428291
4f43615CeftaminFemale32548.7220782

Ceftamin Quartiles and IQR

Ceftamin_tumors=Ceftamin_merge["Tumor Volume (mm3)"]
quartiles=Ceftamin_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of treatment Cap: {lowerq}")
print(f"The upper quartile of temperatures is: {upperq}")
print(f"The interquartile range of temperatures is: {iqr}")
print(f"The the median of temperatures is: {quartiles[0.5]} ")

The output looks as follws: Ceftamin quartiles and IQR

Ceftamin Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Ceftamin outliers_upper and lower_bounds

Box and Whisker Plot

  • A box and whisker plot of the final tumor volume for all four treatment regimens was generated, and a potential outliers highlighted by using color, and style.

A box and whisker plot looks as follws: Ceftamin outliers_upper and lower_bounds

Line and Scatter Plots

Line Plot

  • A line plot created on selected mouse (b742) that was treated with Capomulin, and generate a line plot of time point versus tumor volume for that mouse.

    A line plot looks as follws: Line Plot

Scatter Plot

  • A scatter plot of mouse weight versus average tumor volume for the Capomulin treatment regimen was created.

    A scatter plot looks as follws: Scatter Plot

Correlation and Regression

  • A correlation coefficient, and linear regression analysis was conducted between mouse weight and average tumor volume for the Capomulin treatment. A Plot of the linear regression model created on top of the previous scatter plot.

Correlation

corr=round(st.pearsonr(avg_capm_vol['Weight (g)'],avg_capm_vol['Tumor Volume (mm3)'])[0],2)
print(f"The correlation between mouse weight and average tumor volume is {corr}")

A line plot looks as follws: ![Correlation Coefficient Out put](Images/correlation coefficient.png)

Regression

x_values=avg_capm_vol['Weight (g)']
y_values=avg_capm_vol['Tumor Volume (mm3)']
(slope, intercept, rvalue, pvalue, stderr) =linregress(x_values, y_values)
regress_values=x_values*slope+interceptprint(f"slope:{slope}")
print(f"intercept:{intercept}")
print(f"rvalue (Correlation coefficient):{rvalue}")
print(f"pandas (Correlation coefficient):{corr}")
print(f"stderr:{stderr}")
line_eq="y = "+str(round(slope,2)) +"x + "+str(round(intercept,2))
print(line_eq)

A linear regression output looks as follws: linear regression outpu

Adding a linear regression line to the scatter plot

fig1, ax1=plt.subplots(figsize=(15, 10))
plt.scatter(x_values,y_values,s=175, color="blue")
plt.plot(x_values,regress_values,"r-")
plt.xlabel('Weight(g)',fontsize=14)
plt.ylabel('Average Tumore Volume (mm3)',fontsize=14)
ax1.annotate(line_eq, xy=(20, 40), xycoords='data',xytext=(0.8, 0.95), textcoords='axes fraction',horizontalalignment='right', verticalalignment='top',fontsize=30,color="red")
plt.savefig("../Images/linear_regression.png", bbox_inches="tight")
plt.show()

A linear regression plot looks as follws: linear_regression plot

Copyright

Trilogy Education Services © 2020. All Rights Reserved.

About

This respository apply a Python Matplotlib to visualize real-world pharmaceutical data. The data is sourced from Pymaceuticals Inc., a burgeoning pharmaceutical company based out of San Diego.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Latest commit

History

60 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Matplotlib - The Power of Plots

"Visual storytelling of one kind or another has been around since caveman were drawing on the walls." Frank Darabont

Laboratory

Background

This respository apply a Python Matplotlib to visualize a real-world pharmaceutical data. The data is sourced from Pymaceuticals Inc., a burgeoning pharmaceutical company based out of San Diego. Pymaceuticals specializes in anti-cancer pharmaceuticals. In its most recent efforts, it began screening for potential treatments for squamous cell carcinoma (SCC), a commonly occurring form of skin cancer.

These analysis used a complete data from their most recent animal study in two datasets in CSV format. Data set one is Mouse_metadata.csv wich includes 249 mice identified data with SCC tumor growth were treated through a variety of drug regimens, and their Sex, Age_months and Weight (g) identified. The other dataset is Study_results.csv file which includes the results of the study in each columns Mouse I,Timepoint,Tumor Volume (mm3), and Metastatic Sites.

The purpose of this study was to compare the performance of Pymaceuticals' drug of interest, Capomulin, versus the other treatment regimens. The analysis also generated all of the table and figures needed for the technical, and top-level summary report of the study. For this analysis both datasets imported, merged,cleaned and the aggregate data diplayed in to Python Pandas dataframes, visualized in Matplotlib, and other libraries used in order to make a stastical analysis. The project is conducted in Jupyter notebook to showcase, and communicate the analysis report the following link is created: Jupyter Notebook Viewer

Observable Trends

  • The bar graph showed the Drug Regimen Capomulin has the maximum mice number (230), and Zoniferol has the smaller mice number (182).By removing duplicates the total number of mice is 248. The total count of mice by gender also showed that 124 female mice and 125 male mice.
  • The correlation between mouse weight, and average tumor volume is 0.84. It is a strong positive correlation, when the mouse weight increases the average tumor volume also increases.
  • The regression analysis helped us to understand how much the average tumor volume (dependent variable) will change when weight of mice change(independent variables). The R-squared value is 0.70, which means 70% the model fit the data, wich is fairely good to predict the data from the model. Higher R-squared values represent smaller differences between the observed data, and the fitted value. 70% the model explains all of the variation in the response variable around its mean.
  • From the selected treatments Capomulin and Ramicane reduces the size of tumors better.

Table of Contents

Solutions

Data Cleaning

  • The data was loaded, read, combined, duplicate removed, and the head (5 rows on the top) of cleaned data out put looks as follows
Mouse IDDrug RegimenSexAge_monthsWeight (g)TimepointTumor Volume (mm3)Metastatic Sites
0k403RamicaneMale2116045.0000000
1k403RamicaneMale2116538.8258980
2k403RamicaneMale21161035.0142711
3k403RamicaneMale21161534.2239921
4k403RamicaneMale21162032.9977291

Summary statistics

  • A summary statistics table was generated by using two techniques one is by creating multiple series, and putting them all together at the end, and the other method produces everything in a single groupby function. The summery statistic table consis the mean, median, variance, standard deviation, and SEM of the tumor volume for each drug regimen. The summery stastics tables looks as follws:
MeanMedianVarianceStandard DeviationSEM
Drug Regimen
Capomulin40.67574141.55780924.9477644.9947740.329346
Ceftamin52.59117251.77615739.2901776.2681880.469821
Infubinol52.88479551.82058443.1286846.5672430.492236
Ketapril55.23563853.69874368.5535778.2797090.603860
Naftisol54.33156552.50928566.1734798.1347080.596466
Placebo54.03358152.28893461.1680837.8210030.581331
Propriva52.32093050.44626643.8520136.6220850.544332
Ramicane40.21674540.67323623.4867044.8463080.320955
Stelasyn54.23314952.43173759.4505627.7104190.573111
Zoniferol53.23650751.81847948.5333556.9665890.516398

Bar and Pie Charts

  • Two identical bar charts was generated by using both Pandas's DataFrame.plot() and Matplotlib's pyplot that shows the number of total mice for each treatment regimen throughout the course of the study.

    The Bar Cahrts looks as follows:

Bar Chart on the Number of Mice per Treatment (Pandas's DataFrame.plot())

Pandas's DataFrame.plot()

Bar Chart on the Number of Mice per Treatment (Matplotlib's pyplot)

Matplotlib's pyplot

  • Two identical pie plot was generated by using both Pandas's DataFrame.plot() and Matplotlib's pyplot that shows the distribution of female or male mice in the study.

Pi Chart on the distribution of female or male mice in the study (Pandas's DataFrame.plot())

Pandas's DataFrame.plot()

Pi Chart on the distribution of female or male mice in the study (Matplotlib's pyplot)

Matplotlib's pyplot

Quartiles, Outliers and Boxplots

  • The final tumor volume of each mouse across four of the most promising treatment regimens was created: Capomulin, Ramicane, Infubinol, and Ceftamin. Afterward the quartiles, IQR, and potential outliers across all the four treatment regimens was quantitatively determined.

Capomulin Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0b12845CapomulinFemale92238.9828782
1b74245CapomulinMale72138.9396330
2f96620CapomulinMale161730.4859850
3g28845CapomulinMale31937.0740241
4g31645CapomulinFemale222240.1592202

Capomulin Quartiles and IQR

Capomulin_tumors=Capomulin_merge["Tumor Volume (mm3)"]
quartiles=Capomulin_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of Capomulin tumors: {lowerq}")
print(f"The upper quartile of Capomulin tumors: {upperq}")
print(f"The interquartile range of Capomulin tumors: {iqr}")
print(f"The median of Capomulin tumors: {quartiles[0.5]} ")

The output looks as follws: Capomulinc

Capomulin Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Capomulin outliers_upper and lower_bounds

Ramicane Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a41145RamicaneMale32238.4076181
1a44445RamicaneFemale102543.0475430
2a52045RamicaneMale132138.8103661
3a64445RamicaneFemale71732.9785221
4c45830RamicaneFemale232038.3420082

Ramicane Quartiles and IQR

Ramicane_tumors=Ramicane_merge["Tumor Volume (mm3)"]
quartiles=Ramicane_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of Ramicane tumors is: {lowerq}")
print(f"The upper quartile of Ramicane tumors is: {upperq}")
print(f"The interquartile range of Ramicane tumors is: {iqr}")
print(f"The median of Ramicane tumors is: {quartiles[0.5]} ")

The output looks as follws: Ramicane quartiles and IQR

Ramicane Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Ramicane outliers_upper and lower_bounds

Infubinol Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a20345InfubinolFemale202367.9734192
1a25145InfubinolFemale212565.5257431
2a57730InfubinolFemale62557.0318622
3a68545InfubinolMale83066.0830663
4c13945InfubinolMale112872.2267312

Infubinol Quartiles and IQR

Infubinol_last=Infubinol_df.groupby('Mouse ID').max()['Timepoint']
Infubinol_vol=pd.DataFrame(Infubinol_last)
Infubinol_merge=pd.merge(Infubinol_vol, Combined_data, on=("Mouse ID","Timepoint"),how="left")
Infubinol_merge.head()

The output looks as follws: Infubinol quartiles and IQR

Infubinol Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Infubinol outliers_upper and lower_bounds

Ceftamin Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a27545CeftaminFemale202862.9993563
1b4470CeftaminMale23045.0000000
2b48725CeftaminFemale62856.0577491
3b75930CeftaminFemale122555.7428291
4f43615CeftaminFemale32548.7220782

Ceftamin Quartiles and IQR

Ceftamin_tumors=Ceftamin_merge["Tumor Volume (mm3)"]
quartiles=Ceftamin_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of treatment Cap: {lowerq}")
print(f"The upper quartile of temperatures is: {upperq}")
print(f"The interquartile range of temperatures is: {iqr}")
print(f"The the median of temperatures is: {quartiles[0.5]} ")

The output looks as follws: Ceftamin quartiles and IQR

Ceftamin Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Ceftamin outliers_upper and lower_bounds

Box and Whisker Plot

  • A box and whisker plot of the final tumor volume for all four treatment regimens was generated, and a potential outliers highlighted by using color, and style.

A box and whisker plot looks as follws: Ceftamin outliers_upper and lower_bounds

Line and Scatter Plots

Line Plot

  • A line plot created on selected mouse (b742) that was treated with Capomulin, and generate a line plot of time point versus tumor volume for that mouse.

    A line plot looks as follws: Line Plot

Scatter Plot

  • A scatter plot of mouse weight versus average tumor volume for the Capomulin treatment regimen was created.

    A scatter plot looks as follws: Scatter Plot

Correlation and Regression

  • A correlation coefficient, and linear regression analysis was conducted between mouse weight and average tumor volume for the Capomulin treatment. A Plot of the linear regression model created on top of the previous scatter plot.

Correlation

corr=round(st.pearsonr(avg_capm_vol['Weight (g)'],avg_capm_vol['Tumor Volume (mm3)'])[0],2)
print(f"The correlation between mouse weight and average tumor volume is {corr}")

A line plot looks as follws: ![Correlation Coefficient Out put](Images/correlation coefficient.png)

Regression

x_values=avg_capm_vol['Weight (g)']
y_values=avg_capm_vol['Tumor Volume (mm3)']
(slope, intercept, rvalue, pvalue, stderr) =linregress(x_values, y_values)
regress_values=x_values*slope+interceptprint(f"slope:{slope}")
print(f"intercept:{intercept}")
print(f"rvalue (Correlation coefficient):{rvalue}")
print(f"pandas (Correlation coefficient):{corr}")
print(f"stderr:{stderr}")
line_eq="y = "+str(round(slope,2)) +"x + "+str(round(intercept,2))
print(line_eq)

A linear regression output looks as follws: linear regression outpu

Adding a linear regression line to the scatter plot

fig1, ax1=plt.subplots(figsize=(15, 10))
plt.scatter(x_values,y_values,s=175, color="blue")
plt.plot(x_values,regress_values,"r-")
plt.xlabel('Weight(g)',fontsize=14)
plt.ylabel('Average Tumore Volume (mm3)',fontsize=14)
ax1.annotate(line_eq, xy=(20, 40), xycoords='data',xytext=(0.8, 0.95), textcoords='axes fraction',horizontalalignment='right', verticalalignment='top',fontsize=30,color="red")
plt.savefig("../Images/linear_regression.png", bbox_inches="tight")
plt.show()

A linear regression plot looks as follws: linear_regression plot

Copyright

Trilogy Education Services © 2020. All Rights Reserved.

About

This respository apply a Python Matplotlib to visualize real-world pharmaceutical data. The data is sourced from Pymaceuticals Inc., a burgeoning pharmaceutical company based out of San Diego.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

60 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Matplotlib - The Power of Plots

"Visual storytelling of one kind or another has been around since caveman were drawing on the walls." Frank Darabont

Laboratory

Background

This respository apply a Python Matplotlib to visualize a real-world pharmaceutical data. The data is sourced from Pymaceuticals Inc., a burgeoning pharmaceutical company based out of San Diego. Pymaceuticals specializes in anti-cancer pharmaceuticals. In its most recent efforts, it began screening for potential treatments for squamous cell carcinoma (SCC), a commonly occurring form of skin cancer.

These analysis used a complete data from their most recent animal study in two datasets in CSV format. Data set one is Mouse_metadata.csv wich includes 249 mice identified data with SCC tumor growth were treated through a variety of drug regimens, and their Sex, Age_months and Weight (g) identified. The other dataset is Study_results.csv file which includes the results of the study in each columns Mouse I,Timepoint,Tumor Volume (mm3), and Metastatic Sites.

The purpose of this study was to compare the performance of Pymaceuticals' drug of interest, Capomulin, versus the other treatment regimens. The analysis also generated all of the table and figures needed for the technical, and top-level summary report of the study. For this analysis both datasets imported, merged,cleaned and the aggregate data diplayed in to Python Pandas dataframes, visualized in Matplotlib, and other libraries used in order to make a stastical analysis. The project is conducted in Jupyter notebook to showcase, and communicate the analysis report the following link is created: Jupyter Notebook Viewer

Observable Trends

  • The bar graph showed the Drug Regimen Capomulin has the maximum mice number (230), and Zoniferol has the smaller mice number (182).By removing duplicates the total number of mice is 248. The total count of mice by gender also showed that 124 female mice and 125 male mice.
  • The correlation between mouse weight, and average tumor volume is 0.84. It is a strong positive correlation, when the mouse weight increases the average tumor volume also increases.
  • The regression analysis helped us to understand how much the average tumor volume (dependent variable) will change when weight of mice change(independent variables). The R-squared value is 0.70, which means 70% the model fit the data, wich is fairely good to predict the data from the model. Higher R-squared values represent smaller differences between the observed data, and the fitted value. 70% the model explains all of the variation in the response variable around its mean.
  • From the selected treatments Capomulin and Ramicane reduces the size of tumors better.

Table of Contents

Solutions

Data Cleaning

  • The data was loaded, read, combined, duplicate removed, and the head (5 rows on the top) of cleaned data out put looks as follows
Mouse IDDrug RegimenSexAge_monthsWeight (g)TimepointTumor Volume (mm3)Metastatic Sites
0k403RamicaneMale2116045.0000000
1k403RamicaneMale2116538.8258980
2k403RamicaneMale21161035.0142711
3k403RamicaneMale21161534.2239921
4k403RamicaneMale21162032.9977291

Summary statistics

  • A summary statistics table was generated by using two techniques one is by creating multiple series, and putting them all together at the end, and the other method produces everything in a single groupby function. The summery statistic table consis the mean, median, variance, standard deviation, and SEM of the tumor volume for each drug regimen. The summery stastics tables looks as follws:
MeanMedianVarianceStandard DeviationSEM
Drug Regimen
Capomulin40.67574141.55780924.9477644.9947740.329346
Ceftamin52.59117251.77615739.2901776.2681880.469821
Infubinol52.88479551.82058443.1286846.5672430.492236
Ketapril55.23563853.69874368.5535778.2797090.603860
Naftisol54.33156552.50928566.1734798.1347080.596466
Placebo54.03358152.28893461.1680837.8210030.581331
Propriva52.32093050.44626643.8520136.6220850.544332
Ramicane40.21674540.67323623.4867044.8463080.320955
Stelasyn54.23314952.43173759.4505627.7104190.573111
Zoniferol53.23650751.81847948.5333556.9665890.516398

Bar and Pie Charts

  • Two identical bar charts was generated by using both Pandas's DataFrame.plot() and Matplotlib's pyplot that shows the number of total mice for each treatment regimen throughout the course of the study.

    The Bar Cahrts looks as follows:

Bar Chart on the Number of Mice per Treatment (Pandas's DataFrame.plot())

Pandas's DataFrame.plot()

Bar Chart on the Number of Mice per Treatment (Matplotlib's pyplot)

Matplotlib's pyplot

  • Two identical pie plot was generated by using both Pandas's DataFrame.plot() and Matplotlib's pyplot that shows the distribution of female or male mice in the study.

Pi Chart on the distribution of female or male mice in the study (Pandas's DataFrame.plot())

Pandas's DataFrame.plot()

Pi Chart on the distribution of female or male mice in the study (Matplotlib's pyplot)

Matplotlib's pyplot

Quartiles, Outliers and Boxplots

  • The final tumor volume of each mouse across four of the most promising treatment regimens was created: Capomulin, Ramicane, Infubinol, and Ceftamin. Afterward the quartiles, IQR, and potential outliers across all the four treatment regimens was quantitatively determined.

Capomulin Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0b12845CapomulinFemale92238.9828782
1b74245CapomulinMale72138.9396330
2f96620CapomulinMale161730.4859850
3g28845CapomulinMale31937.0740241
4g31645CapomulinFemale222240.1592202

Capomulin Quartiles and IQR

Capomulin_tumors=Capomulin_merge["Tumor Volume (mm3)"]
quartiles=Capomulin_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of Capomulin tumors: {lowerq}")
print(f"The upper quartile of Capomulin tumors: {upperq}")
print(f"The interquartile range of Capomulin tumors: {iqr}")
print(f"The median of Capomulin tumors: {quartiles[0.5]} ")

The output looks as follws: Capomulinc

Capomulin Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Capomulin outliers_upper and lower_bounds

Ramicane Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a41145RamicaneMale32238.4076181
1a44445RamicaneFemale102543.0475430
2a52045RamicaneMale132138.8103661
3a64445RamicaneFemale71732.9785221
4c45830RamicaneFemale232038.3420082

Ramicane Quartiles and IQR

Ramicane_tumors=Ramicane_merge["Tumor Volume (mm3)"]
quartiles=Ramicane_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of Ramicane tumors is: {lowerq}")
print(f"The upper quartile of Ramicane tumors is: {upperq}")
print(f"The interquartile range of Ramicane tumors is: {iqr}")
print(f"The median of Ramicane tumors is: {quartiles[0.5]} ")

The output looks as follws: Ramicane quartiles and IQR

Ramicane Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Ramicane outliers_upper and lower_bounds

Infubinol Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a20345InfubinolFemale202367.9734192
1a25145InfubinolFemale212565.5257431
2a57730InfubinolFemale62557.0318622
3a68545InfubinolMale83066.0830663
4c13945InfubinolMale112872.2267312

Infubinol Quartiles and IQR

Infubinol_last=Infubinol_df.groupby('Mouse ID').max()['Timepoint']
Infubinol_vol=pd.DataFrame(Infubinol_last)
Infubinol_merge=pd.merge(Infubinol_vol, Combined_data, on=("Mouse ID","Timepoint"),how="left")
Infubinol_merge.head()

The output looks as follws: Infubinol quartiles and IQR

Infubinol Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Infubinol outliers_upper and lower_bounds

Ceftamin Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a27545CeftaminFemale202862.9993563
1b4470CeftaminMale23045.0000000
2b48725CeftaminFemale62856.0577491
3b75930CeftaminFemale122555.7428291
4f43615CeftaminFemale32548.7220782

Ceftamin Quartiles and IQR

Ceftamin_tumors=Ceftamin_merge["Tumor Volume (mm3)"]
quartiles=Ceftamin_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of treatment Cap: {lowerq}")
print(f"The upper quartile of temperatures is: {upperq}")
print(f"The interquartile range of temperatures is: {iqr}")
print(f"The the median of temperatures is: {quartiles[0.5]} ")

The output looks as follws: Ceftamin quartiles and IQR

Ceftamin Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Ceftamin outliers_upper and lower_bounds

Box and Whisker Plot

  • A box and whisker plot of the final tumor volume for all four treatment regimens was generated, and a potential outliers highlighted by using color, and style.

A box and whisker plot looks as follws: Ceftamin outliers_upper and lower_bounds

Line and Scatter Plots

Line Plot

  • A line plot created on selected mouse (b742) that was treated with Capomulin, and generate a line plot of time point versus tumor volume for that mouse.

    A line plot looks as follws: Line Plot

Scatter Plot

  • A scatter plot of mouse weight versus average tumor volume for the Capomulin treatment regimen was created.

    A scatter plot looks as follws: Scatter Plot

Correlation and Regression

  • A correlation coefficient, and linear regression analysis was conducted between mouse weight and average tumor volume for the Capomulin treatment. A Plot of the linear regression model created on top of the previous scatter plot.

Correlation

corr=round(st.pearsonr(avg_capm_vol['Weight (g)'],avg_capm_vol['Tumor Volume (mm3)'])[0],2)
print(f"The correlation between mouse weight and average tumor volume is {corr}")

A line plot looks as follws: ![Correlation Coefficient Out put](Images/correlation coefficient.png)

Regression

x_values=avg_capm_vol['Weight (g)']
y_values=avg_capm_vol['Tumor Volume (mm3)']
(slope, intercept, rvalue, pvalue, stderr) =linregress(x_values, y_values)
regress_values=x_values*slope+interceptprint(f"slope:{slope}")
print(f"intercept:{intercept}")
print(f"rvalue (Correlation coefficient):{rvalue}")
print(f"pandas (Correlation coefficient):{corr}")
print(f"stderr:{stderr}")
line_eq="y = "+str(round(slope,2)) +"x + "+str(round(intercept,2))
print(line_eq)

A linear regression output looks as follws: linear regression outpu

Adding a linear regression line to the scatter plot

fig1, ax1=plt.subplots(figsize=(15, 10))
plt.scatter(x_values,y_values,s=175, color="blue")
plt.plot(x_values,regress_values,"r-")
plt.xlabel('Weight(g)',fontsize=14)
plt.ylabel('Average Tumore Volume (mm3)',fontsize=14)
ax1.annotate(line_eq, xy=(20, 40), xycoords='data',xytext=(0.8, 0.95), textcoords='axes fraction',horizontalalignment='right', verticalalignment='top',fontsize=30,color="red")
plt.savefig("../Images/linear_regression.png", bbox_inches="tight")
plt.show()

A linear regression plot looks as follws: linear_regression plot

Copyright

Trilogy Education Services © 2020. All Rights Reserved.

About

This respository apply a Python Matplotlib to visualize real-world pharmaceutical data. The data is sourced from Pymaceuticals Inc., a burgeoning pharmaceutical company based out of San Diego.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

60 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Matplotlib - The Power of Plots

"Visual storytelling of one kind or another has been around since caveman were drawing on the walls." Frank Darabont

Laboratory

Background

This respository apply a Python Matplotlib to visualize a real-world pharmaceutical data. The data is sourced from Pymaceuticals Inc., a burgeoning pharmaceutical company based out of San Diego. Pymaceuticals specializes in anti-cancer pharmaceuticals. In its most recent efforts, it began screening for potential treatments for squamous cell carcinoma (SCC), a commonly occurring form of skin cancer.

These analysis used a complete data from their most recent animal study in two datasets in CSV format. Data set one is Mouse_metadata.csv wich includes 249 mice identified data with SCC tumor growth were treated through a variety of drug regimens, and their Sex, Age_months and Weight (g) identified. The other dataset is Study_results.csv file which includes the results of the study in each columns Mouse I,Timepoint,Tumor Volume (mm3), and Metastatic Sites.

The purpose of this study was to compare the performance of Pymaceuticals' drug of interest, Capomulin, versus the other treatment regimens. The analysis also generated all of the table and figures needed for the technical, and top-level summary report of the study. For this analysis both datasets imported, merged,cleaned and the aggregate data diplayed in to Python Pandas dataframes, visualized in Matplotlib, and other libraries used in order to make a stastical analysis. The project is conducted in Jupyter notebook to showcase, and communicate the analysis report the following link is created: Jupyter Notebook Viewer

Observable Trends

  • The bar graph showed the Drug Regimen Capomulin has the maximum mice number (230), and Zoniferol has the smaller mice number (182).By removing duplicates the total number of mice is 248. The total count of mice by gender also showed that 124 female mice and 125 male mice.
  • The correlation between mouse weight, and average tumor volume is 0.84. It is a strong positive correlation, when the mouse weight increases the average tumor volume also increases.
  • The regression analysis helped us to understand how much the average tumor volume (dependent variable) will change when weight of mice change(independent variables). The R-squared value is 0.70, which means 70% the model fit the data, wich is fairely good to predict the data from the model. Higher R-squared values represent smaller differences between the observed data, and the fitted value. 70% the model explains all of the variation in the response variable around its mean.
  • From the selected treatments Capomulin and Ramicane reduces the size of tumors better.

Table of Contents

Solutions

Data Cleaning

  • The data was loaded, read, combined, duplicate removed, and the head (5 rows on the top) of cleaned data out put looks as follows
Mouse IDDrug RegimenSexAge_monthsWeight (g)TimepointTumor Volume (mm3)Metastatic Sites
0k403RamicaneMale2116045.0000000
1k403RamicaneMale2116538.8258980
2k403RamicaneMale21161035.0142711
3k403RamicaneMale21161534.2239921
4k403RamicaneMale21162032.9977291

Summary statistics

  • A summary statistics table was generated by using two techniques one is by creating multiple series, and putting them all together at the end, and the other method produces everything in a single groupby function. The summery statistic table consis the mean, median, variance, standard deviation, and SEM of the tumor volume for each drug regimen. The summery stastics tables looks as follws:
MeanMedianVarianceStandard DeviationSEM
Drug Regimen
Capomulin40.67574141.55780924.9477644.9947740.329346
Ceftamin52.59117251.77615739.2901776.2681880.469821
Infubinol52.88479551.82058443.1286846.5672430.492236
Ketapril55.23563853.69874368.5535778.2797090.603860
Naftisol54.33156552.50928566.1734798.1347080.596466
Placebo54.03358152.28893461.1680837.8210030.581331
Propriva52.32093050.44626643.8520136.6220850.544332
Ramicane40.21674540.67323623.4867044.8463080.320955
Stelasyn54.23314952.43173759.4505627.7104190.573111
Zoniferol53.23650751.81847948.5333556.9665890.516398

Bar and Pie Charts

  • Two identical bar charts was generated by using both Pandas's DataFrame.plot() and Matplotlib's pyplot that shows the number of total mice for each treatment regimen throughout the course of the study.

    The Bar Cahrts looks as follows:

Bar Chart on the Number of Mice per Treatment (Pandas's DataFrame.plot())

Pandas's DataFrame.plot()

Bar Chart on the Number of Mice per Treatment (Matplotlib's pyplot)

Matplotlib's pyplot

  • Two identical pie plot was generated by using both Pandas's DataFrame.plot() and Matplotlib's pyplot that shows the distribution of female or male mice in the study.

Pi Chart on the distribution of female or male mice in the study (Pandas's DataFrame.plot())

Pandas's DataFrame.plot()

Pi Chart on the distribution of female or male mice in the study (Matplotlib's pyplot)

Matplotlib's pyplot

Quartiles, Outliers and Boxplots

  • The final tumor volume of each mouse across four of the most promising treatment regimens was created: Capomulin, Ramicane, Infubinol, and Ceftamin. Afterward the quartiles, IQR, and potential outliers across all the four treatment regimens was quantitatively determined.

Capomulin Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0b12845CapomulinFemale92238.9828782
1b74245CapomulinMale72138.9396330
2f96620CapomulinMale161730.4859850
3g28845CapomulinMale31937.0740241
4g31645CapomulinFemale222240.1592202

Capomulin Quartiles and IQR

Capomulin_tumors=Capomulin_merge["Tumor Volume (mm3)"]
quartiles=Capomulin_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of Capomulin tumors: {lowerq}")
print(f"The upper quartile of Capomulin tumors: {upperq}")
print(f"The interquartile range of Capomulin tumors: {iqr}")
print(f"The median of Capomulin tumors: {quartiles[0.5]} ")

The output looks as follws: Capomulinc

Capomulin Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Capomulin outliers_upper and lower_bounds

Ramicane Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a41145RamicaneMale32238.4076181
1a44445RamicaneFemale102543.0475430
2a52045RamicaneMale132138.8103661
3a64445RamicaneFemale71732.9785221
4c45830RamicaneFemale232038.3420082

Ramicane Quartiles and IQR

Ramicane_tumors=Ramicane_merge["Tumor Volume (mm3)"]
quartiles=Ramicane_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of Ramicane tumors is: {lowerq}")
print(f"The upper quartile of Ramicane tumors is: {upperq}")
print(f"The interquartile range of Ramicane tumors is: {iqr}")
print(f"The median of Ramicane tumors is: {quartiles[0.5]} ")

The output looks as follws: Ramicane quartiles and IQR

Ramicane Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Ramicane outliers_upper and lower_bounds

Infubinol Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a20345InfubinolFemale202367.9734192
1a25145InfubinolFemale212565.5257431
2a57730InfubinolFemale62557.0318622
3a68545InfubinolMale83066.0830663
4c13945InfubinolMale112872.2267312

Infubinol Quartiles and IQR

Infubinol_last=Infubinol_df.groupby('Mouse ID').max()['Timepoint']
Infubinol_vol=pd.DataFrame(Infubinol_last)
Infubinol_merge=pd.merge(Infubinol_vol, Combined_data, on=("Mouse ID","Timepoint"),how="left")
Infubinol_merge.head()

The output looks as follws: Infubinol quartiles and IQR

Infubinol Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Infubinol outliers_upper and lower_bounds

Ceftamin Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a27545CeftaminFemale202862.9993563
1b4470CeftaminMale23045.0000000
2b48725CeftaminFemale62856.0577491
3b75930CeftaminFemale122555.7428291
4f43615CeftaminFemale32548.7220782

Ceftamin Quartiles and IQR

Ceftamin_tumors=Ceftamin_merge["Tumor Volume (mm3)"]
quartiles=Ceftamin_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of treatment Cap: {lowerq}")
print(f"The upper quartile of temperatures is: {upperq}")
print(f"The interquartile range of temperatures is: {iqr}")
print(f"The the median of temperatures is: {quartiles[0.5]} ")

The output looks as follws: Ceftamin quartiles and IQR

Ceftamin Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Ceftamin outliers_upper and lower_bounds

Box and Whisker Plot

  • A box and whisker plot of the final tumor volume for all four treatment regimens was generated, and a potential outliers highlighted by using color, and style.

A box and whisker plot looks as follws: Ceftamin outliers_upper and lower_bounds

Line and Scatter Plots

Line Plot

  • A line plot created on selected mouse (b742) that was treated with Capomulin, and generate a line plot of time point versus tumor volume for that mouse.

    A line plot looks as follws: Line Plot

Scatter Plot

  • A scatter plot of mouse weight versus average tumor volume for the Capomulin treatment regimen was created.

    A scatter plot looks as follws: Scatter Plot

Correlation and Regression

  • A correlation coefficient, and linear regression analysis was conducted between mouse weight and average tumor volume for the Capomulin treatment. A Plot of the linear regression model created on top of the previous scatter plot.

Correlation

corr=round(st.pearsonr(avg_capm_vol['Weight (g)'],avg_capm_vol['Tumor Volume (mm3)'])[0],2)
print(f"The correlation between mouse weight and average tumor volume is {corr}")

A line plot looks as follws: ![Correlation Coefficient Out put](Images/correlation coefficient.png)

Regression

x_values=avg_capm_vol['Weight (g)']
y_values=avg_capm_vol['Tumor Volume (mm3)']
(slope, intercept, rvalue, pvalue, stderr) =linregress(x_values, y_values)
regress_values=x_values*slope+interceptprint(f"slope:{slope}")
print(f"intercept:{intercept}")
print(f"rvalue (Correlation coefficient):{rvalue}")
print(f"pandas (Correlation coefficient):{corr}")
print(f"stderr:{stderr}")
line_eq="y = "+str(round(slope,2)) +"x + "+str(round(intercept,2))
print(line_eq)

A linear regression output looks as follws: linear regression outpu

Adding a linear regression line to the scatter plot

fig1, ax1=plt.subplots(figsize=(15, 10))
plt.scatter(x_values,y_values,s=175, color="blue")
plt.plot(x_values,regress_values,"r-")
plt.xlabel('Weight(g)',fontsize=14)
plt.ylabel('Average Tumore Volume (mm3)',fontsize=14)
ax1.annotate(line_eq, xy=(20, 40), xycoords='data',xytext=(0.8, 0.95), textcoords='axes fraction',horizontalalignment='right', verticalalignment='top',fontsize=30,color="red")
plt.savefig("../Images/linear_regression.png", bbox_inches="tight")
plt.show()

A linear regression plot looks as follws: linear_regression plot

Copyright

Trilogy Education Services © 2020. All Rights Reserved.

About

This respository apply a Python Matplotlib to visualize real-world pharmaceutical data. The data is sourced from Pymaceuticals Inc., a burgeoning pharmaceutical company based out of San Diego.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Latest commit

History

60 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Matplotlib - The Power of Plots

"Visual storytelling of one kind or another has been around since caveman were drawing on the walls." Frank Darabont

Laboratory

Background

This respository apply a Python Matplotlib to visualize a real-world pharmaceutical data. The data is sourced from Pymaceuticals Inc., a burgeoning pharmaceutical company based out of San Diego. Pymaceuticals specializes in anti-cancer pharmaceuticals. In its most recent efforts, it began screening for potential treatments for squamous cell carcinoma (SCC), a commonly occurring form of skin cancer.

These analysis used a complete data from their most recent animal study in two datasets in CSV format. Data set one is Mouse_metadata.csv wich includes 249 mice identified data with SCC tumor growth were treated through a variety of drug regimens, and their Sex, Age_months and Weight (g) identified. The other dataset is Study_results.csv file which includes the results of the study in each columns Mouse I,Timepoint,Tumor Volume (mm3), and Metastatic Sites.

The purpose of this study was to compare the performance of Pymaceuticals' drug of interest, Capomulin, versus the other treatment regimens. The analysis also generated all of the table and figures needed for the technical, and top-level summary report of the study. For this analysis both datasets imported, merged,cleaned and the aggregate data diplayed in to Python Pandas dataframes, visualized in Matplotlib, and other libraries used in order to make a stastical analysis. The project is conducted in Jupyter notebook to showcase, and communicate the analysis report the following link is created: Jupyter Notebook Viewer

Observable Trends

  • The bar graph showed the Drug Regimen Capomulin has the maximum mice number (230), and Zoniferol has the smaller mice number (182).By removing duplicates the total number of mice is 248. The total count of mice by gender also showed that 124 female mice and 125 male mice.
  • The correlation between mouse weight, and average tumor volume is 0.84. It is a strong positive correlation, when the mouse weight increases the average tumor volume also increases.
  • The regression analysis helped us to understand how much the average tumor volume (dependent variable) will change when weight of mice change(independent variables). The R-squared value is 0.70, which means 70% the model fit the data, wich is fairely good to predict the data from the model. Higher R-squared values represent smaller differences between the observed data, and the fitted value. 70% the model explains all of the variation in the response variable around its mean.
  • From the selected treatments Capomulin and Ramicane reduces the size of tumors better.

Table of Contents

Solutions

Data Cleaning

  • The data was loaded, read, combined, duplicate removed, and the head (5 rows on the top) of cleaned data out put looks as follows
Mouse IDDrug RegimenSexAge_monthsWeight (g)TimepointTumor Volume (mm3)Metastatic Sites
0k403RamicaneMale2116045.0000000
1k403RamicaneMale2116538.8258980
2k403RamicaneMale21161035.0142711
3k403RamicaneMale21161534.2239921
4k403RamicaneMale21162032.9977291

Summary statistics

  • A summary statistics table was generated by using two techniques one is by creating multiple series, and putting them all together at the end, and the other method produces everything in a single groupby function. The summery statistic table consis the mean, median, variance, standard deviation, and SEM of the tumor volume for each drug regimen. The summery stastics tables looks as follws:
MeanMedianVarianceStandard DeviationSEM
Drug Regimen
Capomulin40.67574141.55780924.9477644.9947740.329346
Ceftamin52.59117251.77615739.2901776.2681880.469821
Infubinol52.88479551.82058443.1286846.5672430.492236
Ketapril55.23563853.69874368.5535778.2797090.603860
Naftisol54.33156552.50928566.1734798.1347080.596466
Placebo54.03358152.28893461.1680837.8210030.581331
Propriva52.32093050.44626643.8520136.6220850.544332
Ramicane40.21674540.67323623.4867044.8463080.320955
Stelasyn54.23314952.43173759.4505627.7104190.573111
Zoniferol53.23650751.81847948.5333556.9665890.516398

Bar and Pie Charts

  • Two identical bar charts was generated by using both Pandas's DataFrame.plot() and Matplotlib's pyplot that shows the number of total mice for each treatment regimen throughout the course of the study.

    The Bar Cahrts looks as follows:

Bar Chart on the Number of Mice per Treatment (Pandas's DataFrame.plot())

Pandas's DataFrame.plot()

Bar Chart on the Number of Mice per Treatment (Matplotlib's pyplot)

Matplotlib's pyplot

  • Two identical pie plot was generated by using both Pandas's DataFrame.plot() and Matplotlib's pyplot that shows the distribution of female or male mice in the study.

Pi Chart on the distribution of female or male mice in the study (Pandas's DataFrame.plot())

Pandas's DataFrame.plot()

Pi Chart on the distribution of female or male mice in the study (Matplotlib's pyplot)

Matplotlib's pyplot

Quartiles, Outliers and Boxplots

  • The final tumor volume of each mouse across four of the most promising treatment regimens was created: Capomulin, Ramicane, Infubinol, and Ceftamin. Afterward the quartiles, IQR, and potential outliers across all the four treatment regimens was quantitatively determined.

Capomulin Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0b12845CapomulinFemale92238.9828782
1b74245CapomulinMale72138.9396330
2f96620CapomulinMale161730.4859850
3g28845CapomulinMale31937.0740241
4g31645CapomulinFemale222240.1592202

Capomulin Quartiles and IQR

Capomulin_tumors=Capomulin_merge["Tumor Volume (mm3)"]
quartiles=Capomulin_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of Capomulin tumors: {lowerq}")
print(f"The upper quartile of Capomulin tumors: {upperq}")
print(f"The interquartile range of Capomulin tumors: {iqr}")
print(f"The median of Capomulin tumors: {quartiles[0.5]} ")

The output looks as follws: Capomulinc

Capomulin Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Capomulin outliers_upper and lower_bounds

Ramicane Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a41145RamicaneMale32238.4076181
1a44445RamicaneFemale102543.0475430
2a52045RamicaneMale132138.8103661
3a64445RamicaneFemale71732.9785221
4c45830RamicaneFemale232038.3420082

Ramicane Quartiles and IQR

Ramicane_tumors=Ramicane_merge["Tumor Volume (mm3)"]
quartiles=Ramicane_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of Ramicane tumors is: {lowerq}")
print(f"The upper quartile of Ramicane tumors is: {upperq}")
print(f"The interquartile range of Ramicane tumors is: {iqr}")
print(f"The median of Ramicane tumors is: {quartiles[0.5]} ")

The output looks as follws: Ramicane quartiles and IQR

Ramicane Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Ramicane outliers_upper and lower_bounds

Infubinol Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a20345InfubinolFemale202367.9734192
1a25145InfubinolFemale212565.5257431
2a57730InfubinolFemale62557.0318622
3a68545InfubinolMale83066.0830663
4c13945InfubinolMale112872.2267312

Infubinol Quartiles and IQR

Infubinol_last=Infubinol_df.groupby('Mouse ID').max()['Timepoint']
Infubinol_vol=pd.DataFrame(Infubinol_last)
Infubinol_merge=pd.merge(Infubinol_vol, Combined_data, on=("Mouse ID","Timepoint"),how="left")
Infubinol_merge.head()

The output looks as follws: Infubinol quartiles and IQR

Infubinol Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Infubinol outliers_upper and lower_bounds

Ceftamin Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a27545CeftaminFemale202862.9993563
1b4470CeftaminMale23045.0000000
2b48725CeftaminFemale62856.0577491
3b75930CeftaminFemale122555.7428291
4f43615CeftaminFemale32548.7220782

Ceftamin Quartiles and IQR

Ceftamin_tumors=Ceftamin_merge["Tumor Volume (mm3)"]
quartiles=Ceftamin_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of treatment Cap: {lowerq}")
print(f"The upper quartile of temperatures is: {upperq}")
print(f"The interquartile range of temperatures is: {iqr}")
print(f"The the median of temperatures is: {quartiles[0.5]} ")

The output looks as follws: Ceftamin quartiles and IQR

Ceftamin Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Ceftamin outliers_upper and lower_bounds

Box and Whisker Plot

  • A box and whisker plot of the final tumor volume for all four treatment regimens was generated, and a potential outliers highlighted by using color, and style.

A box and whisker plot looks as follws: Ceftamin outliers_upper and lower_bounds

Line and Scatter Plots

Line Plot

  • A line plot created on selected mouse (b742) that was treated with Capomulin, and generate a line plot of time point versus tumor volume for that mouse.

    A line plot looks as follws: Line Plot

Scatter Plot

  • A scatter plot of mouse weight versus average tumor volume for the Capomulin treatment regimen was created.

    A scatter plot looks as follws: Scatter Plot

Correlation and Regression

  • A correlation coefficient, and linear regression analysis was conducted between mouse weight and average tumor volume for the Capomulin treatment. A Plot of the linear regression model created on top of the previous scatter plot.

Correlation

corr=round(st.pearsonr(avg_capm_vol['Weight (g)'],avg_capm_vol['Tumor Volume (mm3)'])[0],2)
print(f"The correlation between mouse weight and average tumor volume is {corr}")

A line plot looks as follws: ![Correlation Coefficient Out put](Images/correlation coefficient.png)

Regression

x_values=avg_capm_vol['Weight (g)']
y_values=avg_capm_vol['Tumor Volume (mm3)']
(slope, intercept, rvalue, pvalue, stderr) =linregress(x_values, y_values)
regress_values=x_values*slope+interceptprint(f"slope:{slope}")
print(f"intercept:{intercept}")
print(f"rvalue (Correlation coefficient):{rvalue}")
print(f"pandas (Correlation coefficient):{corr}")
print(f"stderr:{stderr}")
line_eq="y = "+str(round(slope,2)) +"x + "+str(round(intercept,2))
print(line_eq)

A linear regression output looks as follws: linear regression outpu

Adding a linear regression line to the scatter plot

fig1, ax1=plt.subplots(figsize=(15, 10))
plt.scatter(x_values,y_values,s=175, color="blue")
plt.plot(x_values,regress_values,"r-")
plt.xlabel('Weight(g)',fontsize=14)
plt.ylabel('Average Tumore Volume (mm3)',fontsize=14)
ax1.annotate(line_eq, xy=(20, 40), xycoords='data',xytext=(0.8, 0.95), textcoords='axes fraction',horizontalalignment='right', verticalalignment='top',fontsize=30,color="red")
plt.savefig("../Images/linear_regression.png", bbox_inches="tight")
plt.show()

A linear regression plot looks as follws: linear_regression plot

Copyright

Trilogy Education Services © 2020. All Rights Reserved.

About

This respository apply a Python Matplotlib to visualize real-world pharmaceutical data. The data is sourced from Pymaceuticals Inc., a burgeoning pharmaceutical company based out of San Diego.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

60 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Matplotlib - The Power of Plots

"Visual storytelling of one kind or another has been around since caveman were drawing on the walls." Frank Darabont

Laboratory

Background

This respository apply a Python Matplotlib to visualize a real-world pharmaceutical data. The data is sourced from Pymaceuticals Inc., a burgeoning pharmaceutical company based out of San Diego. Pymaceuticals specializes in anti-cancer pharmaceuticals. In its most recent efforts, it began screening for potential treatments for squamous cell carcinoma (SCC), a commonly occurring form of skin cancer.

These analysis used a complete data from their most recent animal study in two datasets in CSV format. Data set one is Mouse_metadata.csv wich includes 249 mice identified data with SCC tumor growth were treated through a variety of drug regimens, and their Sex, Age_months and Weight (g) identified. The other dataset is Study_results.csv file which includes the results of the study in each columns Mouse I,Timepoint,Tumor Volume (mm3), and Metastatic Sites.

The purpose of this study was to compare the performance of Pymaceuticals' drug of interest, Capomulin, versus the other treatment regimens. The analysis also generated all of the table and figures needed for the technical, and top-level summary report of the study. For this analysis both datasets imported, merged,cleaned and the aggregate data diplayed in to Python Pandas dataframes, visualized in Matplotlib, and other libraries used in order to make a stastical analysis. The project is conducted in Jupyter notebook to showcase, and communicate the analysis report the following link is created: Jupyter Notebook Viewer

Observable Trends

  • The bar graph showed the Drug Regimen Capomulin has the maximum mice number (230), and Zoniferol has the smaller mice number (182).By removing duplicates the total number of mice is 248. The total count of mice by gender also showed that 124 female mice and 125 male mice.
  • The correlation between mouse weight, and average tumor volume is 0.84. It is a strong positive correlation, when the mouse weight increases the average tumor volume also increases.
  • The regression analysis helped us to understand how much the average tumor volume (dependent variable) will change when weight of mice change(independent variables). The R-squared value is 0.70, which means 70% the model fit the data, wich is fairely good to predict the data from the model. Higher R-squared values represent smaller differences between the observed data, and the fitted value. 70% the model explains all of the variation in the response variable around its mean.
  • From the selected treatments Capomulin and Ramicane reduces the size of tumors better.

Table of Contents

Solutions

Data Cleaning

  • The data was loaded, read, combined, duplicate removed, and the head (5 rows on the top) of cleaned data out put looks as follows
Mouse IDDrug RegimenSexAge_monthsWeight (g)TimepointTumor Volume (mm3)Metastatic Sites
0k403RamicaneMale2116045.0000000
1k403RamicaneMale2116538.8258980
2k403RamicaneMale21161035.0142711
3k403RamicaneMale21161534.2239921
4k403RamicaneMale21162032.9977291

Summary statistics

  • A summary statistics table was generated by using two techniques one is by creating multiple series, and putting them all together at the end, and the other method produces everything in a single groupby function. The summery statistic table consis the mean, median, variance, standard deviation, and SEM of the tumor volume for each drug regimen. The summery stastics tables looks as follws:
MeanMedianVarianceStandard DeviationSEM
Drug Regimen
Capomulin40.67574141.55780924.9477644.9947740.329346
Ceftamin52.59117251.77615739.2901776.2681880.469821
Infubinol52.88479551.82058443.1286846.5672430.492236
Ketapril55.23563853.69874368.5535778.2797090.603860
Naftisol54.33156552.50928566.1734798.1347080.596466
Placebo54.03358152.28893461.1680837.8210030.581331
Propriva52.32093050.44626643.8520136.6220850.544332
Ramicane40.21674540.67323623.4867044.8463080.320955
Stelasyn54.23314952.43173759.4505627.7104190.573111
Zoniferol53.23650751.81847948.5333556.9665890.516398

Bar and Pie Charts

  • Two identical bar charts was generated by using both Pandas's DataFrame.plot() and Matplotlib's pyplot that shows the number of total mice for each treatment regimen throughout the course of the study.

    The Bar Cahrts looks as follows:

Bar Chart on the Number of Mice per Treatment (Pandas's DataFrame.plot())

Pandas's DataFrame.plot()

Bar Chart on the Number of Mice per Treatment (Matplotlib's pyplot)

Matplotlib's pyplot

  • Two identical pie plot was generated by using both Pandas's DataFrame.plot() and Matplotlib's pyplot that shows the distribution of female or male mice in the study.

Pi Chart on the distribution of female or male mice in the study (Pandas's DataFrame.plot())

Pandas's DataFrame.plot()

Pi Chart on the distribution of female or male mice in the study (Matplotlib's pyplot)

Matplotlib's pyplot

Quartiles, Outliers and Boxplots

  • The final tumor volume of each mouse across four of the most promising treatment regimens was created: Capomulin, Ramicane, Infubinol, and Ceftamin. Afterward the quartiles, IQR, and potential outliers across all the four treatment regimens was quantitatively determined.

Capomulin Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0b12845CapomulinFemale92238.9828782
1b74245CapomulinMale72138.9396330
2f96620CapomulinMale161730.4859850
3g28845CapomulinMale31937.0740241
4g31645CapomulinFemale222240.1592202

Capomulin Quartiles and IQR

Capomulin_tumors=Capomulin_merge["Tumor Volume (mm3)"]
quartiles=Capomulin_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of Capomulin tumors: {lowerq}")
print(f"The upper quartile of Capomulin tumors: {upperq}")
print(f"The interquartile range of Capomulin tumors: {iqr}")
print(f"The median of Capomulin tumors: {quartiles[0.5]} ")

The output looks as follws: Capomulinc

Capomulin Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Capomulin outliers_upper and lower_bounds

Ramicane Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a41145RamicaneMale32238.4076181
1a44445RamicaneFemale102543.0475430
2a52045RamicaneMale132138.8103661
3a64445RamicaneFemale71732.9785221
4c45830RamicaneFemale232038.3420082

Ramicane Quartiles and IQR

Ramicane_tumors=Ramicane_merge["Tumor Volume (mm3)"]
quartiles=Ramicane_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of Ramicane tumors is: {lowerq}")
print(f"The upper quartile of Ramicane tumors is: {upperq}")
print(f"The interquartile range of Ramicane tumors is: {iqr}")
print(f"The median of Ramicane tumors is: {quartiles[0.5]} ")

The output looks as follws: Ramicane quartiles and IQR

Ramicane Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Ramicane outliers_upper and lower_bounds

Infubinol Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a20345InfubinolFemale202367.9734192
1a25145InfubinolFemale212565.5257431
2a57730InfubinolFemale62557.0318622
3a68545InfubinolMale83066.0830663
4c13945InfubinolMale112872.2267312

Infubinol Quartiles and IQR

Infubinol_last=Infubinol_df.groupby('Mouse ID').max()['Timepoint']
Infubinol_vol=pd.DataFrame(Infubinol_last)
Infubinol_merge=pd.merge(Infubinol_vol, Combined_data, on=("Mouse ID","Timepoint"),how="left")
Infubinol_merge.head()

The output looks as follws: Infubinol quartiles and IQR

Infubinol Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Infubinol outliers_upper and lower_bounds

Ceftamin Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a27545CeftaminFemale202862.9993563
1b4470CeftaminMale23045.0000000
2b48725CeftaminFemale62856.0577491
3b75930CeftaminFemale122555.7428291
4f43615CeftaminFemale32548.7220782

Ceftamin Quartiles and IQR

Ceftamin_tumors=Ceftamin_merge["Tumor Volume (mm3)"]
quartiles=Ceftamin_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of treatment Cap: {lowerq}")
print(f"The upper quartile of temperatures is: {upperq}")
print(f"The interquartile range of temperatures is: {iqr}")
print(f"The the median of temperatures is: {quartiles[0.5]} ")

The output looks as follws: Ceftamin quartiles and IQR

Ceftamin Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Ceftamin outliers_upper and lower_bounds

Box and Whisker Plot

  • A box and whisker plot of the final tumor volume for all four treatment regimens was generated, and a potential outliers highlighted by using color, and style.

A box and whisker plot looks as follws: Ceftamin outliers_upper and lower_bounds

Line and Scatter Plots

Line Plot

  • A line plot created on selected mouse (b742) that was treated with Capomulin, and generate a line plot of time point versus tumor volume for that mouse.

    A line plot looks as follws: Line Plot

Scatter Plot

  • A scatter plot of mouse weight versus average tumor volume for the Capomulin treatment regimen was created.

    A scatter plot looks as follws: Scatter Plot

Correlation and Regression

  • A correlation coefficient, and linear regression analysis was conducted between mouse weight and average tumor volume for the Capomulin treatment. A Plot of the linear regression model created on top of the previous scatter plot.

Correlation

corr=round(st.pearsonr(avg_capm_vol['Weight (g)'],avg_capm_vol['Tumor Volume (mm3)'])[0],2)
print(f"The correlation between mouse weight and average tumor volume is {corr}")

A line plot looks as follws: ![Correlation Coefficient Out put](Images/correlation coefficient.png)

Regression

x_values=avg_capm_vol['Weight (g)']
y_values=avg_capm_vol['Tumor Volume (mm3)']
(slope, intercept, rvalue, pvalue, stderr) =linregress(x_values, y_values)
regress_values=x_values*slope+interceptprint(f"slope:{slope}")
print(f"intercept:{intercept}")
print(f"rvalue (Correlation coefficient):{rvalue}")
print(f"pandas (Correlation coefficient):{corr}")
print(f"stderr:{stderr}")
line_eq="y = "+str(round(slope,2)) +"x + "+str(round(intercept,2))
print(line_eq)

A linear regression output looks as follws: linear regression outpu

Adding a linear regression line to the scatter plot

fig1, ax1=plt.subplots(figsize=(15, 10))
plt.scatter(x_values,y_values,s=175, color="blue")
plt.plot(x_values,regress_values,"r-")
plt.xlabel('Weight(g)',fontsize=14)
plt.ylabel('Average Tumore Volume (mm3)',fontsize=14)
ax1.annotate(line_eq, xy=(20, 40), xycoords='data',xytext=(0.8, 0.95), textcoords='axes fraction',horizontalalignment='right', verticalalignment='top',fontsize=30,color="red")
plt.savefig("../Images/linear_regression.png", bbox_inches="tight")
plt.show()

A linear regression plot looks as follws: linear_regression plot

Copyright

Trilogy Education Services © 2020. All Rights Reserved.

About

This respository apply a Python Matplotlib to visualize real-world pharmaceutical data. The data is sourced from Pymaceuticals Inc., a burgeoning pharmaceutical company based out of San Diego.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

60 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Matplotlib - The Power of Plots

"Visual storytelling of one kind or another has been around since caveman were drawing on the walls." Frank Darabont

Laboratory

Background

This respository apply a Python Matplotlib to visualize a real-world pharmaceutical data. The data is sourced from Pymaceuticals Inc., a burgeoning pharmaceutical company based out of San Diego. Pymaceuticals specializes in anti-cancer pharmaceuticals. In its most recent efforts, it began screening for potential treatments for squamous cell carcinoma (SCC), a commonly occurring form of skin cancer.

These analysis used a complete data from their most recent animal study in two datasets in CSV format. Data set one is Mouse_metadata.csv wich includes 249 mice identified data with SCC tumor growth were treated through a variety of drug regimens, and their Sex, Age_months and Weight (g) identified. The other dataset is Study_results.csv file which includes the results of the study in each columns Mouse I,Timepoint,Tumor Volume (mm3), and Metastatic Sites.

The purpose of this study was to compare the performance of Pymaceuticals' drug of interest, Capomulin, versus the other treatment regimens. The analysis also generated all of the table and figures needed for the technical, and top-level summary report of the study. For this analysis both datasets imported, merged,cleaned and the aggregate data diplayed in to Python Pandas dataframes, visualized in Matplotlib, and other libraries used in order to make a stastical analysis. The project is conducted in Jupyter notebook to showcase, and communicate the analysis report the following link is created: Jupyter Notebook Viewer

Observable Trends

  • The bar graph showed the Drug Regimen Capomulin has the maximum mice number (230), and Zoniferol has the smaller mice number (182).By removing duplicates the total number of mice is 248. The total count of mice by gender also showed that 124 female mice and 125 male mice.
  • The correlation between mouse weight, and average tumor volume is 0.84. It is a strong positive correlation, when the mouse weight increases the average tumor volume also increases.
  • The regression analysis helped us to understand how much the average tumor volume (dependent variable) will change when weight of mice change(independent variables). The R-squared value is 0.70, which means 70% the model fit the data, wich is fairely good to predict the data from the model. Higher R-squared values represent smaller differences between the observed data, and the fitted value. 70% the model explains all of the variation in the response variable around its mean.
  • From the selected treatments Capomulin and Ramicane reduces the size of tumors better.

Table of Contents

Solutions

Data Cleaning

  • The data was loaded, read, combined, duplicate removed, and the head (5 rows on the top) of cleaned data out put looks as follows
Mouse IDDrug RegimenSexAge_monthsWeight (g)TimepointTumor Volume (mm3)Metastatic Sites
0k403RamicaneMale2116045.0000000
1k403RamicaneMale2116538.8258980
2k403RamicaneMale21161035.0142711
3k403RamicaneMale21161534.2239921
4k403RamicaneMale21162032.9977291

Summary statistics

  • A summary statistics table was generated by using two techniques one is by creating multiple series, and putting them all together at the end, and the other method produces everything in a single groupby function. The summery statistic table consis the mean, median, variance, standard deviation, and SEM of the tumor volume for each drug regimen. The summery stastics tables looks as follws:
MeanMedianVarianceStandard DeviationSEM
Drug Regimen
Capomulin40.67574141.55780924.9477644.9947740.329346
Ceftamin52.59117251.77615739.2901776.2681880.469821
Infubinol52.88479551.82058443.1286846.5672430.492236
Ketapril55.23563853.69874368.5535778.2797090.603860
Naftisol54.33156552.50928566.1734798.1347080.596466
Placebo54.03358152.28893461.1680837.8210030.581331
Propriva52.32093050.44626643.8520136.6220850.544332
Ramicane40.21674540.67323623.4867044.8463080.320955
Stelasyn54.23314952.43173759.4505627.7104190.573111
Zoniferol53.23650751.81847948.5333556.9665890.516398

Bar and Pie Charts

  • Two identical bar charts was generated by using both Pandas's DataFrame.plot() and Matplotlib's pyplot that shows the number of total mice for each treatment regimen throughout the course of the study.

    The Bar Cahrts looks as follows:

Bar Chart on the Number of Mice per Treatment (Pandas's DataFrame.plot())

Pandas's DataFrame.plot()

Bar Chart on the Number of Mice per Treatment (Matplotlib's pyplot)

Matplotlib's pyplot

  • Two identical pie plot was generated by using both Pandas's DataFrame.plot() and Matplotlib's pyplot that shows the distribution of female or male mice in the study.

Pi Chart on the distribution of female or male mice in the study (Pandas's DataFrame.plot())

Pandas's DataFrame.plot()

Pi Chart on the distribution of female or male mice in the study (Matplotlib's pyplot)

Matplotlib's pyplot

Quartiles, Outliers and Boxplots

  • The final tumor volume of each mouse across four of the most promising treatment regimens was created: Capomulin, Ramicane, Infubinol, and Ceftamin. Afterward the quartiles, IQR, and potential outliers across all the four treatment regimens was quantitatively determined.

Capomulin Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0b12845CapomulinFemale92238.9828782
1b74245CapomulinMale72138.9396330
2f96620CapomulinMale161730.4859850
3g28845CapomulinMale31937.0740241
4g31645CapomulinFemale222240.1592202

Capomulin Quartiles and IQR

Capomulin_tumors=Capomulin_merge["Tumor Volume (mm3)"]
quartiles=Capomulin_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of Capomulin tumors: {lowerq}")
print(f"The upper quartile of Capomulin tumors: {upperq}")
print(f"The interquartile range of Capomulin tumors: {iqr}")
print(f"The median of Capomulin tumors: {quartiles[0.5]} ")

The output looks as follws: Capomulinc

Capomulin Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Capomulin outliers_upper and lower_bounds

Ramicane Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a41145RamicaneMale32238.4076181
1a44445RamicaneFemale102543.0475430
2a52045RamicaneMale132138.8103661
3a64445RamicaneFemale71732.9785221
4c45830RamicaneFemale232038.3420082

Ramicane Quartiles and IQR

Ramicane_tumors=Ramicane_merge["Tumor Volume (mm3)"]
quartiles=Ramicane_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of Ramicane tumors is: {lowerq}")
print(f"The upper quartile of Ramicane tumors is: {upperq}")
print(f"The interquartile range of Ramicane tumors is: {iqr}")
print(f"The median of Ramicane tumors is: {quartiles[0.5]} ")

The output looks as follws: Ramicane quartiles and IQR

Ramicane Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Ramicane outliers_upper and lower_bounds

Infubinol Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a20345InfubinolFemale202367.9734192
1a25145InfubinolFemale212565.5257431
2a57730InfubinolFemale62557.0318622
3a68545InfubinolMale83066.0830663
4c13945InfubinolMale112872.2267312

Infubinol Quartiles and IQR

Infubinol_last=Infubinol_df.groupby('Mouse ID').max()['Timepoint']
Infubinol_vol=pd.DataFrame(Infubinol_last)
Infubinol_merge=pd.merge(Infubinol_vol, Combined_data, on=("Mouse ID","Timepoint"),how="left")
Infubinol_merge.head()

The output looks as follws: Infubinol quartiles and IQR

Infubinol Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Infubinol outliers_upper and lower_bounds

Ceftamin Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a27545CeftaminFemale202862.9993563
1b4470CeftaminMale23045.0000000
2b48725CeftaminFemale62856.0577491
3b75930CeftaminFemale122555.7428291
4f43615CeftaminFemale32548.7220782

Ceftamin Quartiles and IQR

Ceftamin_tumors=Ceftamin_merge["Tumor Volume (mm3)"]
quartiles=Ceftamin_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of treatment Cap: {lowerq}")
print(f"The upper quartile of temperatures is: {upperq}")
print(f"The interquartile range of temperatures is: {iqr}")
print(f"The the median of temperatures is: {quartiles[0.5]} ")

The output looks as follws: Ceftamin quartiles and IQR

Ceftamin Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Ceftamin outliers_upper and lower_bounds

Box and Whisker Plot

  • A box and whisker plot of the final tumor volume for all four treatment regimens was generated, and a potential outliers highlighted by using color, and style.

A box and whisker plot looks as follws: Ceftamin outliers_upper and lower_bounds

Line and Scatter Plots

Line Plot

  • A line plot created on selected mouse (b742) that was treated with Capomulin, and generate a line plot of time point versus tumor volume for that mouse.

    A line plot looks as follws: Line Plot

Scatter Plot

  • A scatter plot of mouse weight versus average tumor volume for the Capomulin treatment regimen was created.

    A scatter plot looks as follws: Scatter Plot

Correlation and Regression

  • A correlation coefficient, and linear regression analysis was conducted between mouse weight and average tumor volume for the Capomulin treatment. A Plot of the linear regression model created on top of the previous scatter plot.

Correlation

corr=round(st.pearsonr(avg_capm_vol['Weight (g)'],avg_capm_vol['Tumor Volume (mm3)'])[0],2)
print(f"The correlation between mouse weight and average tumor volume is {corr}")

A line plot looks as follws: ![Correlation Coefficient Out put](Images/correlation coefficient.png)

Regression

x_values=avg_capm_vol['Weight (g)']
y_values=avg_capm_vol['Tumor Volume (mm3)']
(slope, intercept, rvalue, pvalue, stderr) =linregress(x_values, y_values)
regress_values=x_values*slope+interceptprint(f"slope:{slope}")
print(f"intercept:{intercept}")
print(f"rvalue (Correlation coefficient):{rvalue}")
print(f"pandas (Correlation coefficient):{corr}")
print(f"stderr:{stderr}")
line_eq="y = "+str(round(slope,2)) +"x + "+str(round(intercept,2))
print(line_eq)

A linear regression output looks as follws: linear regression outpu

Adding a linear regression line to the scatter plot

fig1, ax1=plt.subplots(figsize=(15, 10))
plt.scatter(x_values,y_values,s=175, color="blue")
plt.plot(x_values,regress_values,"r-")
plt.xlabel('Weight(g)',fontsize=14)
plt.ylabel('Average Tumore Volume (mm3)',fontsize=14)
ax1.annotate(line_eq, xy=(20, 40), xycoords='data',xytext=(0.8, 0.95), textcoords='axes fraction',horizontalalignment='right', verticalalignment='top',fontsize=30,color="red")
plt.savefig("../Images/linear_regression.png", bbox_inches="tight")
plt.show()

A linear regression plot looks as follws: linear_regression plot

Copyright

Trilogy Education Services © 2020. All Rights Reserved.

About

This respository apply a Python Matplotlib to visualize real-world pharmaceutical data. The data is sourced from Pymaceuticals Inc., a burgeoning pharmaceutical company based out of San Diego.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Latest commit

History

60 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Matplotlib - The Power of Plots

"Visual storytelling of one kind or another has been around since caveman were drawing on the walls." Frank Darabont

Laboratory

Background

This respository apply a Python Matplotlib to visualize a real-world pharmaceutical data. The data is sourced from Pymaceuticals Inc., a burgeoning pharmaceutical company based out of San Diego. Pymaceuticals specializes in anti-cancer pharmaceuticals. In its most recent efforts, it began screening for potential treatments for squamous cell carcinoma (SCC), a commonly occurring form of skin cancer.

These analysis used a complete data from their most recent animal study in two datasets in CSV format. Data set one is Mouse_metadata.csv wich includes 249 mice identified data with SCC tumor growth were treated through a variety of drug regimens, and their Sex, Age_months and Weight (g) identified. The other dataset is Study_results.csv file which includes the results of the study in each columns Mouse I,Timepoint,Tumor Volume (mm3), and Metastatic Sites.

The purpose of this study was to compare the performance of Pymaceuticals' drug of interest, Capomulin, versus the other treatment regimens. The analysis also generated all of the table and figures needed for the technical, and top-level summary report of the study. For this analysis both datasets imported, merged,cleaned and the aggregate data diplayed in to Python Pandas dataframes, visualized in Matplotlib, and other libraries used in order to make a stastical analysis. The project is conducted in Jupyter notebook to showcase, and communicate the analysis report the following link is created: Jupyter Notebook Viewer

Observable Trends

  • The bar graph showed the Drug Regimen Capomulin has the maximum mice number (230), and Zoniferol has the smaller mice number (182).By removing duplicates the total number of mice is 248. The total count of mice by gender also showed that 124 female mice and 125 male mice.
  • The correlation between mouse weight, and average tumor volume is 0.84. It is a strong positive correlation, when the mouse weight increases the average tumor volume also increases.
  • The regression analysis helped us to understand how much the average tumor volume (dependent variable) will change when weight of mice change(independent variables). The R-squared value is 0.70, which means 70% the model fit the data, wich is fairely good to predict the data from the model. Higher R-squared values represent smaller differences between the observed data, and the fitted value. 70% the model explains all of the variation in the response variable around its mean.
  • From the selected treatments Capomulin and Ramicane reduces the size of tumors better.

Table of Contents

Solutions

Data Cleaning

  • The data was loaded, read, combined, duplicate removed, and the head (5 rows on the top) of cleaned data out put looks as follows
Mouse IDDrug RegimenSexAge_monthsWeight (g)TimepointTumor Volume (mm3)Metastatic Sites
0k403RamicaneMale2116045.0000000
1k403RamicaneMale2116538.8258980
2k403RamicaneMale21161035.0142711
3k403RamicaneMale21161534.2239921
4k403RamicaneMale21162032.9977291

Summary statistics

  • A summary statistics table was generated by using two techniques one is by creating multiple series, and putting them all together at the end, and the other method produces everything in a single groupby function. The summery statistic table consis the mean, median, variance, standard deviation, and SEM of the tumor volume for each drug regimen. The summery stastics tables looks as follws:
MeanMedianVarianceStandard DeviationSEM
Drug Regimen
Capomulin40.67574141.55780924.9477644.9947740.329346
Ceftamin52.59117251.77615739.2901776.2681880.469821
Infubinol52.88479551.82058443.1286846.5672430.492236
Ketapril55.23563853.69874368.5535778.2797090.603860
Naftisol54.33156552.50928566.1734798.1347080.596466
Placebo54.03358152.28893461.1680837.8210030.581331
Propriva52.32093050.44626643.8520136.6220850.544332
Ramicane40.21674540.67323623.4867044.8463080.320955
Stelasyn54.23314952.43173759.4505627.7104190.573111
Zoniferol53.23650751.81847948.5333556.9665890.516398

Bar and Pie Charts

  • Two identical bar charts was generated by using both Pandas's DataFrame.plot() and Matplotlib's pyplot that shows the number of total mice for each treatment regimen throughout the course of the study.

    The Bar Cahrts looks as follows:

Bar Chart on the Number of Mice per Treatment (Pandas's DataFrame.plot())

Pandas's DataFrame.plot()

Bar Chart on the Number of Mice per Treatment (Matplotlib's pyplot)

Matplotlib's pyplot

  • Two identical pie plot was generated by using both Pandas's DataFrame.plot() and Matplotlib's pyplot that shows the distribution of female or male mice in the study.

Pi Chart on the distribution of female or male mice in the study (Pandas's DataFrame.plot())

Pandas's DataFrame.plot()

Pi Chart on the distribution of female or male mice in the study (Matplotlib's pyplot)

Matplotlib's pyplot

Quartiles, Outliers and Boxplots

  • The final tumor volume of each mouse across four of the most promising treatment regimens was created: Capomulin, Ramicane, Infubinol, and Ceftamin. Afterward the quartiles, IQR, and potential outliers across all the four treatment regimens was quantitatively determined.

Capomulin Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0b12845CapomulinFemale92238.9828782
1b74245CapomulinMale72138.9396330
2f96620CapomulinMale161730.4859850
3g28845CapomulinMale31937.0740241
4g31645CapomulinFemale222240.1592202

Capomulin Quartiles and IQR

Capomulin_tumors=Capomulin_merge["Tumor Volume (mm3)"]
quartiles=Capomulin_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of Capomulin tumors: {lowerq}")
print(f"The upper quartile of Capomulin tumors: {upperq}")
print(f"The interquartile range of Capomulin tumors: {iqr}")
print(f"The median of Capomulin tumors: {quartiles[0.5]} ")

The output looks as follws: Capomulinc

Capomulin Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Capomulin outliers_upper and lower_bounds

Ramicane Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a41145RamicaneMale32238.4076181
1a44445RamicaneFemale102543.0475430
2a52045RamicaneMale132138.8103661
3a64445RamicaneFemale71732.9785221
4c45830RamicaneFemale232038.3420082

Ramicane Quartiles and IQR

Ramicane_tumors=Ramicane_merge["Tumor Volume (mm3)"]
quartiles=Ramicane_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of Ramicane tumors is: {lowerq}")
print(f"The upper quartile of Ramicane tumors is: {upperq}")
print(f"The interquartile range of Ramicane tumors is: {iqr}")
print(f"The median of Ramicane tumors is: {quartiles[0.5]} ")

The output looks as follws: Ramicane quartiles and IQR

Ramicane Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Ramicane outliers_upper and lower_bounds

Infubinol Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a20345InfubinolFemale202367.9734192
1a25145InfubinolFemale212565.5257431
2a57730InfubinolFemale62557.0318622
3a68545InfubinolMale83066.0830663
4c13945InfubinolMale112872.2267312

Infubinol Quartiles and IQR

Infubinol_last=Infubinol_df.groupby('Mouse ID').max()['Timepoint']
Infubinol_vol=pd.DataFrame(Infubinol_last)
Infubinol_merge=pd.merge(Infubinol_vol, Combined_data, on=("Mouse ID","Timepoint"),how="left")
Infubinol_merge.head()

The output looks as follws: Infubinol quartiles and IQR

Infubinol Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Infubinol outliers_upper and lower_bounds

Ceftamin Final Tumor Volume

Mouse IDTimepointDrug RegimenSexAge_monthsWeight (g)Tumor Volume (mm3)Metastatic Sites
0a27545CeftaminFemale202862.9993563
1b4470CeftaminMale23045.0000000
2b48725CeftaminFemale62856.0577491
3b75930CeftaminFemale122555.7428291
4f43615CeftaminFemale32548.7220782

Ceftamin Quartiles and IQR

Ceftamin_tumors=Ceftamin_merge["Tumor Volume (mm3)"]
quartiles=Ceftamin_tumors.quantile([.25,.5,.75])
lowerq=quartiles[0.25]
upperq=quartiles[0.75]
iqr=upperq-lowerqprint(f"The lower quartile of treatment Cap: {lowerq}")
print(f"The upper quartile of temperatures is: {upperq}")
print(f"The interquartile range of temperatures is: {iqr}")
print(f"The the median of temperatures is: {quartiles[0.5]} ")

The output looks as follws: Ceftamin quartiles and IQR

Ceftamin Outliers using upper and lower bounds

lower_bound=lowerq- (1.5*iqr)
upper_bound=upperq+ (1.5*iqr)
print(f"Values below {lower_bound} could be outliers.")
print(f"Values above {upper_bound} could be outliers.")

The output looks as follws:

Ceftamin outliers_upper and lower_bounds

Box and Whisker Plot

  • A box and whisker plot of the final tumor volume for all four treatment regimens was generated, and a potential outliers highlighted by using color, and style.

A box and whisker plot looks as follws: Ceftamin outliers_upper and lower_bounds

Line and Scatter Plots

Line Plot

  • A line plot created on selected mouse (b742) that was treated with Capomulin, and generate a line plot of time point versus tumor volume for that mouse.

    A line plot looks as follws: Line Plot

Scatter Plot

  • A scatter plot of mouse weight versus average tumor volume for the Capomulin treatment regimen was created.

    A scatter plot looks as follws: Scatter Plot

Correlation and Regression

  • A correlation coefficient, and linear regression analysis was conducted between mouse weight and average tumor volume for the Capomulin treatment. A Plot of the linear regression model created on top of the previous scatter plot.

Correlation

corr=round(st.pearsonr(avg_capm_vol['Weight (g)'],avg_capm_vol['Tumor Volume (mm3)'])[0],2)
print(f"The correlation between mouse weight and average tumor volume is {corr}")

A line plot looks as follws: ![Correlation Coefficient Out put](Images/correlation coefficient.png)

Regression

x_values=avg_capm_vol['Weight (g)']
y_values=avg_capm_vol['Tumor Volume (mm3)']
(slope, intercept, rvalue, pvalue, stderr) =linregress(x_values, y_values)
regress_values=x_values*slope+interceptprint(f"slope:{slope}")
print(f"intercept:{intercept}")
print(f"rvalue (Correlation coefficient):{rvalue}")
print(f"pandas (Correlation coefficient):{corr}")
print(f"stderr:{stderr}")
line_eq="y = "+str(round(slope,2)) +"x + "+str(round(intercept,2))
print(line_eq)

A linear regression output looks as follws: linear regression outpu

Adding a linear regression line to the scatter plot

fig1, ax1=plt.subplots(figsize=(15, 10))
plt.scatter(x_values,y_values,s=175, color="blue")
plt.plot(x_values,regress_values,"r-")
plt.xlabel('Weight(g)',fontsize=14)
plt.ylabel('Average Tumore Volume (mm3)',fontsize=14)
ax1.annotate(line_eq, xy=(20, 40), xycoords='data',xytext=(0.8, 0.95), textcoords='axes fraction',horizontalalignment='right', verticalalignment='top',fontsize=30,color="red")
plt.savefig("../Images/linear_regression.png", bbox_inches="tight")
plt.show()

A linear regression plot looks as follws: linear_regression plot

Copyright

Trilogy Education Services © 2020. All Rights Reserved.

About

This respository apply a Python Matplotlib to visualize real-world pharmaceutical data. The data is sourced from Pymaceuticals Inc., a burgeoning pharmaceutical company based out of San Diego.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages