r functions: pca

Summary

Started a github repository to put online R functions I've create for some common types of analysis and plots. Aim to have a core set of functions to make figures look prettier, even on preliminary analysis. A couple examples are included focusing on the first function: principal component analysis.

A GitHub repository can be found at: R plotting functions.

For those who want to dive right in, the git repository (includes a readme):

R plotting functions

Update: The PCA script presented here could be greatly simplified using ggplot, a very useful graphics program in R. I'll leave implementation for a future post.


Been writing a lot of R functions and trying to make them generalizable and accepting of multiple input types. Since I was helped by others who posted code and other useful information about R online, thought I should contribute back.

There are a multitude of packages to help create useful and pretty plots with R. But sometimes it is also helpful to have functions that combine features of these packages into one nice example. That is what I hope to achieve with this repository. Each type of plot or analysis will have its own functions, examples and plots. This will allow users to verify that the functions work. Further, I hope those who just want to see a particular R feature implemented within a wider, working function can benefit from this.

left: USA Crime PCA: high population urban centers cluster in this high-dimension analysis.

I have included two example images created with my first function, a script to do principal component analysis on arbitrary datasets. By getting the scores from the PCA object R creates, I can create a plot that is softer on the eyes that biplot or other standard functions. In addition, it allows me to input any arbitrary list and have the function highlight the subset of items in that list on the component graph. This allow easier visualization and understanding for human readers.

The first example looks at multiple crime statistics in the USA across states. Analyzing each individually might not tell us much about crime in the US at it relates to each state, but by doing PCA we see that there is some relation between these variables and that states with large urban populations group together, seen by looking at the clustering of the 70th percentile states.

Next, I included some preliminary data, mostly uninformative to the uninitiated but visually nice, looking at biophysical protein properties across the entire yeast genome and then highlight the kinases to show this analysis can properly group related protein subsets. Obviously this is a rough first-analysis, but you get the picture.

S. cer protein properties: yeast kinases group together when analyzing several biophysical protein properties.

Alright, this was supposed to be short, so I'll end it here. In the future I'll include code and explain the thought process behind it.

-biafra
bahanonu [at] alum.mit.edu

more articles to enjoy:

bash scripting: batch file renamer
25 february 2013 | programming

Bit by bit, I have replaced repetitive tasks completed using downloaded programs with scripts that do the same thing more efficiently, with[...]out the residual registry and file junk many programs leave, and with the flexibility to allow me to modify the script to suite specific needs in the future. This was the case with batch renaming files. I've included the script and briefly go over the code.

singapore: final report
16 september 2012 | singapore

Before finishing my adventures in Singapore, I was asked to put together a final report describing my experiences and where the program cou[...]ld improve. Rather than bore you with details, I've included a link to download the report. This is a draft form and I'll update the link with a finished version in the future.

from the archives: declaration of independence, internet edition
11 july 2013 | america

A revised Declaration of Independence I did awhile ago (i.e. high school) for a writing class. It is slightly a mockery of the style of wri[...]ting sometimes used back then, e.g. finding unnecessarily complicated ways of saying a simple concept; long, ponderous sentences; and an abuse of the Capital.

imaging pain-related neural activity in freely-moving animals
30 may 2022 | neuroscience

Our book chapter detailing the entire pipeline from surgeries to analysis for calcium imaging of pain-related neural activity has been publ[...]ished.

This can prove a useful reference for those new to calcium imaging (esp. in freely moving animals) or researchers who want to see how others perform certain experimental and analytical steps along with the rationale. Please reach out if you have any specific questions, happy to help!

©2006-2024 | Site created & coded by Biafra Ahanonu | Updated 17 April 2024
biafra ahanonu