User Tools

Site Tools


r-tutorial

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
r-tutorial [2011/10/13 00:09]
liuyipei
r-tutorial [2011/10/15 12:05] (current)
liuyipei [Problem Set 1 Hints]
Line 280: Line 280:
  
  
-====Basics====+====Problem Set 1 Hints and Other Tricks==== 
 +<code> 
 +setwd('/Users/liuyipei/BMI215/Module 1 - Nick/DrugSafety-Homework'
 +dz<-read.csv('single_drug_event_frequencies.csv'
 +head(dz) 
 + 
 +cd1<-read.csv('cholesterol_drugs.txt', col.names=F) 
 +colnames(cd1)<-c('singlet'
 +cd1$chole<-'choles' 
 +head(cd0) 
 + 
 +cd0<-data.frame(singlet=setdiff(as.character(unique(dz$singlet)), cd1$singlet),chole=0) 
 +cd0$chole<-'noncholes' 
 +cd.table<-rbind(cd1, cd0) 
 +head(cd1) 
 +head(cd0) 
 +head(cd.table) 
 + 
 +q1.table <- merge(cd.table, dz) 
 +q1.table$hifreq <- ifelse(q1.table$freq > 0.1, 'hifr', 'lofr'
 +head(q1.table) 
 +nrow(q1.table) 
 +ncol(q1.table) 
 + 
 +sum(q1.table$chole == 'choles'
 +sum(q1.table$chole == 'noncholes'
 +table(q1.table$chole, q1.table$hifreq) 
 + 
 +library(plyr) 
 +hard.work<-function(x){ 
 +  c(nrow(x), ncol(x), x$chole[1]=='choles'
 +
 +ddply(q1.table, .(singlet), .fun=hard.work)->lets.talk.about.what.happened 
 +head(lets.talk.about.what.happened) 
 +dim(lets.talk.about.what.happened) 
 +summary(lets.talk.about.what.happened) 
 +colnames(lets.talk.about.what.happened)<-c('singlet', 'row.count', 'col.count', 'ch.drug'
 + 
 +library(caTools) 
 +my.x<-c(0:10)*0.1 
 +my.y<-c(0,1,3,5,6,7,7,9,9,10,10)*0.1 
 +plot(my.x, my.y) 
 +trapz(my.x, my.y) 
 + 
 +data.frame(a=c(8,12),b=c(31,41))->
 +
 +fisher.test(t)->f.t 
 +ls(f.t) 
 +f.t$p.value 
 +f.t$conf.int 
 + 
 +</code>
r-tutorial.1318489763.txt.gz · Last modified: 2011/10/13 00:09 by liuyipei