Contrasts in R


In this post I discuss how to create custom contrasts for factor variables in R. First lets create some simulated data. Create the data, and factor Disease status:

Disease <- c(rep("RA", 5), rep("SLE", 5), rep("Scleroderma", 5), 
             rep("Myositis", 5), rep("Control", 5))
set.seed(1234)
sex <-  rbinom(25,1, 0.5)
age <-  rnorm(25, 40, 5)
y <- rnorm(25, 0.5, 0.12)
data <- data.frame(y,sex,age,Disease=factor(Disease))
str(data)
## 'data.frame':	25 obs. of  4 variables:
##  $ y      : num  0.506 0.323 0.552 0.492 0.513 ...
##  $ sex    : int  0 1 1 1 1 1 0 0 1 1 ...
##  $ age    : num  44.4 46.9 31.6 36.9 40.1 ...
##  $ Disease: Factor w/ 5 levels "Control","Myositis",..: 3 3 3 3 3 5 5 5 5 5 ...

We want the following contrasts:

  • Control versus all 4 diseases combined
  • RA versus the combination of (SLE, Scleroderma, Myositis), leaving out the Controls
Read more »

Testing RMarkdown


This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00
Read more »

Gradient Descent


I am taking the Machine Learning course on Coursera being taught by Andrew Ng. It is turning out to be useful so far, and he has presented the material clearly. It’s a nice introduction to the Machine Learning/Computer Science language, since I come from a statistics background.

I learned about gradient descent today for simple linear regression. The following is my code in R and I compare it to the lm function in base R.

Read more »

Linux: Thunderbird and McGill mail


The Microsoft Outlook web app is terrible for Linux. Simple tasks such as saving addresses or deleting messages by filter is painfully difficult, especially when you have had experience with good email clients on Windows, or even Mac OS. I always knew Thunderbird existed for Linux, but didn’t know my university’s specific settings.

Read more »

CDPATH in Bash


Instead of constantly typing the full path when using the cd command, BASH has a built-in feature called CDPATH. Thanks to lhunath who explained in this SO Post how to use this feature.

Read more »