Was this page helpful?

R-Windows Notes

    Setting the default directory to read data

    1. open the properties of the shortcut to R-GUI
    2. in the shortcut tab, set Start in: to be the desired directory.  you must have read/write access 

    Read a tab delimited file into a matrix (2D)

    1. for a 2-row, 3 column matrix,
      m <- matrix( scan(file="mat_2_3.txt"), c(2,3) )

    Read in GeneGo Data

    1. store data in Day12_GeneGoList.xslx as "text, tab delimited"  csv would work as well, but the separator=","
    2. day12<-read.delim("Day12_GeneGoList.txt",sep="\t")
    3.  day24<-read.delim("Day24_GeneGoList.txt",sep="\t")
    4.  day48<-read.delim("Day48_GeneGoList.txt",sep="\t")
    5.  day60<-read.delim("Day60_GeneGoList.txt",sep="\t")

    Merge GeneGo Data

    1. a1<-merge(day12,day24,by="Common.Name",all=TRUE,suffixes=c(".12",".24"))
    2. a2<-merge(day48,day60,by="Common.Name",all=TRUE,suffixes=c(".48",".60"))
    3. a4<-merge(a1,a2,by="Common.Name",all=TRUE)

    Extract means columns

    1. amean<-cbind(a4[3],a4[6],a4[9],a4[12])

    Replace <NA> values with zeroes

      for ( i in 1:118 ) {
          acopy[ i, is.na( acopy[i,] ) ] <- 0
      }
    

    Make correlation based distance matrix

    1. first transpose so that the rows are the days so we can get correlations between metabolites
    2. get the correlation matrix
    3. convert to distance
         at<-t(acopy)
         acor<-cor(acopy)
         adist<-(as.dist(1.0-acor)/2)
    

    Hierarchical clustering by average distance

    1. aclust1<-hclust(adist,method="average",members=NULL)
    2. plot(aclust) 
    3. pdf("avclust.pdf");plot(aclust1);dev.off()
    avclust.jpg


     

     

     Principal components

    1.  pca<-prcomp(at,scale=T) 
    2. summary(pca)
     Importance of components:
                             PC1   PC2   PC3      PC4
     Standard deviation     7.000 6.520 5.146 5.91e-15
     Proportion of Variance 0.415 0.360 0.224 0.00e+00
     Cumulative Proportion  0.415 0.776 1.000 1.00e+00
    

    PCA plots

    1. x<-pca$rotation[,1]
    2. y<-pca$rotation[,2]
    3. jpeg("pca1.jpg");
    4. plot(x,y)
    5. points(x[1:46],y[1:46],pch=1,color=mycolors[1])
    6. points(x[47:78],y[47:78],pch=2,col=mycolors[2])
    7. points(x[79:93],y[79:93],pch=3,col=mycolors[3])
    8. points(x[94:118],y[94:118],pch=4,col=mycolors[4])
    9. dev.off()
    pca1.jpg

    PCA Biplot

    1. jpeg("pca2.jpg");
    2. biplot(pca)
    3. dev.off()

    pca2.jpg

     

    Was this page helpful?
    Tag page (Edit tags)
    • No tags

    Files 4

    FileSizeDateAttached by 
     avclust.jpg
    No description
    22.33 kB11:45, 7 Aug 2009gribskovActions
     avclust.pdf
    No description
    17.03 kB11:43, 7 Aug 2009gribskovActions
     pca1.jpg
    No description
    11.89 kB12:25, 7 Aug 2009gribskovActions
     pca2.jpg
    No description
    23.21 kB12:27, 7 Aug 2009gribskovActions
    You must login to post a comment.