Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

At our most recent R user group meeting we were delighted to have presentations from Mark Lawson and Steve Hoang, both bioinformaticians at Hemoshear. All of the code used in both demos is in our Meetup’s GitHub repo.

### Making heatmaps in R

Steve started with an overview of making heatmaps in R. Using the iris dataset, Steve demonstrated making heatmaps of the continuous iris data using the heatmap.2 function from the gplots package, the aheatmap function from NMF, and the hard way using ggplot2. The “best in class” method used aheatmap to draw an annotated heatmap plotting z-scores of columns and annotated rows instead of raw values, using the Pearson correlation instead of Euclidean distance as the distance metric.
library(dplyr)
library(NMF)
library(RColorBrewer)
iris2 = iris # prep iris data for plotting
rownames(iris2) = make.names(iris2$Species, unique = T) iris2 = iris2 %>% select(-Species) %>% as.matrix() aheatmap(iris2, color = "-RdBu:50", scale = "col", breaks = 0, annRow = iris["Species"], annColors = "Set2", distfun = "pearson", treeheight=c(200, 50), fontsize=13, cexCol=.7, filename="heatmap.png", width=8, height=16)  ### Classification and regression using caret Mark wrapped up with a gentle introduction to the caret package for classification and regression training. This demonstration used the caret package to split data into training and testing sets, and run repeated cross-validation to train random forest and penalized logistic regression models for classifying Fisher’s iris data. First, get a look at the data with the featurePlot function in the caret package: library(caret) set.seed(42) data(iris) featurePlot(x = iris[, 1:4], y = iris$Species,
plot = "pairs",
auto.key = list(columns = 3))


Next, after splitting the data into training and testing sets and using the caret package to automate training and testing both random forest and partial least squares models using repeated 10-fold cross-validation (see the code), it turns out random forest outperforms PLS in this case, and performs fairly well overall:
setosaversicolorvirginica
Sensitivity1.001.000.00
Specificity1.000.501.00
Pos Pred Value1.000.50NaN
Neg Pred Value1.001.000.67
Prevalence0.330.330.33
Detection Rate0.330.330.00
Detection Prevalence0.330.670.00
Balanced Accuracy1.000.750.50
A big thanks to Mark and Steve at Hemoshear for putting this together!