Analyse de données biologiques

II - Langage et jeux de données (version 3.1)

Prof. Patrick E. Meyer

S: the first statistical language

S is developped

  • in 1976 by J. Chambers et al. in Bell laboratories with objective:
    • interactive
    • statistics with little programming
    • user friendly
  • 1988 Version 3
  • 1998 Version 4
  • 2008 licenses sold 25M

R history

  • 1991 R (S clone) is born

  • 1995 GNU License (freedom to use, study, share, copy, and modify the software)

  • 2000 Version 1

  • 2013 version 3

    • 4000+ packages

    • Easy graphics

Bioconductor

Specific for molecular biology and medical data

  • Reproductibility

  • 2001 Version 1 (15 packages)

  • 2013 Version 3 (750 packages)

Rstudio Desktop - Server (2011)

Numeric

  • a <- 5 #assigning
  • 5:10 #fromto
  • myvec <- c(1,2,4, 5:7) #concatenate
  • myvec[3] #accessing
  • myvec[3:5] #multiple accessing
  • myvec[c(2,6,4)] #multiple accessing
  • myvec2 <- c("hello", "world") #string
  • myvec2[-1] #omitting

Logical

  a <- T #assignation
  b <- F #assignation

Comparaisons: a == b, a != b, a >= b, a <= b, a > b, a < b

Numeric with logical condition

  • myvec <- c(1,2,4, 5:7) #concatenate
  • myvec[c(T,F,F,T,T,F)]
  • myvec>2
  • myvec<=6
  • myvec>3 & myvec<=6
  • myvec[myvec>3 & myvec<=6]

Functions

  • myvec*3 #operators such as (+ - * / ^2)
  • log(myvec)
  • sort(myvec)
  • max(myvec)
  • sum(myvec)
  • which(myvec==4)
  • cor(myvec, myvec2)
  • ?cor #help function

Main objects in R

  • numeric #vecteurs
    • numbers
    • logical #T,F
    • character #“hello”
  • list #mixed types
  • matrix #numeric in 2D
  • data.frame #list of numeric and factor

Matrices

 m1<-cbind(A=1:4, B=5:8, C=9:12)
 m2<-rbind(A=1:4, B=5:8, C=9:12)
 dim(m1)
 x <- matrix(1:12, nr=3, byrow=T)
 rownames(x) <- LETTERS[1:3]
 colnames(x) <- letters[1:3]
 x[2,3]
 x[2,]
 x[,3]
 x[1,-1]
 x[c(1,2), -c(2,3)]

Listes

Pour des objets différents

 list1 <- list(34,21,mot1="hi",vec=c(2,1),TRUE)
 list1[[1]]
 list1$mot1
 list1$vec[2]
  • Notons qu’un ficher .rdata peut (comme une liste) contenir différents objets dans l’environnement et se charge automatiquement en cliquant 2X dessus dans Rstudio, et sinon “manuellement” avec la fonction load("file.rdata")

Data.frame

  • liste de vecteurs de mêmes tailles
  • en ligne les experiences
  • en colonne les variables
  • Remarque: a quoi correspond une corrélation de colonnes vs de lignes dans un jeu de données d’expression?
  • La fonction data() permet de charger un dataset intégré (i.e. un dataset qui vient avec le logiciel) ex: data(airquality).

Pour résumer la notation

  • crochets simples (ex: randomName[1])
    #numeric
  • crochets avec virgule (ex: randomName[2,4])
    #element of a matrix or data.frame
  • doubles crochets (ex: randomName[[2]])
    #list elemt or column of data.frame
  • dollar (ex: randomName$name[4])
    #list elemt or column of data.frame
  • parenthèses (ex: randomName(10,"a",3,...))  #function