library(RMySQL) mycon <- dbConnect(MySQL(), user='root', dbname="project_aers", host="127.0.0.1", port=3307, password='kuancfit') data <- dbGetQuery(mycon, "select * from corr_drug_drug") compute.p.values <- function(row) { x <- c(rep(1,row[4]), rep(1,row[5]), rep(0,row[6]), rep(0,row[7])) y <- c(rep(1,row[4]), rep(0,row[5]), rep(1,row[6]), rep(0,row[7])) return(cor.test(x,y)$p.value) } data$pvalues <- apply(data, 1, compute.p.values) library(RMySQL) mycon <- dbConnect(MySQL(), user='root', dbname="project_aers", host="localhost", port=3306, password='kuancfit') data <- dbGetQuery(mycon, "select * from corr_drug_drug") compute.p.values <- function(row) { x <- c(rep(1,row[4]), rep(1,row[5]), rep(0,row[6]), rep(0,row[7])) y <- c(rep(1,row[4]), rep(0,row[5]), rep(1,row[6]), rep(0,row[7])) return(cor.test(x,y)$p.value) } data$pvalues <- apply(data, 1, compute.p.values) head(data) data <- dbGetQuery(mycon, "select * from corr_drug_drug_old") data$pvalue <- apply(data, 1, compute.p.values) head(data) ?write.csv write.csv(data, "~/corr_drug_drug_011012.csv", row.names=F, quote=F) data <- dbGetQuery(mycon, " select o.z_score1 as offsides, s.z_score1 as sider, shared_indication is not null as shared from drug_similarity_b o join drug_similarity_sider s using (stitch_id1, stitch_id2) left join drug_shared_indication using (stitch_id1, stitch_id2) ") mycon <- dbConnect(MySQL(), user='root', dbname="project_aers", host="localhost", port=3306, password='kuancfit') data <- dbGetQuery(mycon, " select o.z_score1 as offsides, s.z_score1 as sider, shared_indication is not null as shared from drug_similarity_b o join drug_similarity_sider s using (stitch_id1, stitch_id2) left join drug_shared_indication using (stitch_id1, stitch_id2) ") mycon <- dbConnect(MySQL(), user='root', dbname="project_aers", host="localhost", port=3306, password='kuancfit') data <- dbGetQuery(mycon, " select o.z_score1 as offsides, s.z_score1 as sider, shared_indication is not null as shared from drug_similarity_b o join drug_similarity_sider s using (stitch_id1, stitch_id2) left join drug_shared_indication using (stitch_id1, stitch_id2) ") head(data) sum(is.na(data)) sum(is.na(data$offsides)) data <- data[!is.na(data$offsides),] head(data) fit <- glm(shared ~ offsides + sider, data, family="binomial") summary(fit) pred <- prediction(predict(fit), data$shared) performance(pred, measure="auc")@y.values[[1]] library(ROCR) pred <- prediction(predict(fit), data$shared) performance(pred, measure="auc")@y.values[[1]] install.packages('ROCR') library(ROCR) pred <- prediction(predict(fit), data$shared) performance(pred, measure="auc")@y.values[[1]] perf <- performance(pred, measure="tpr", x.measure="fpr") perf names(perf) head(perf) ?perf ?performance head(perf) head(perf$x) write.csv(perf, '~/Dropbox/performance.csv') head(perf$x.values) head(perf#x.values) # ) head(perf@x.values) write.csv(cbind(perf@x.values, perf@y.values), '~/Dropbox/performance.csv', row.names=F, quote=F) x <- cbind(perf@x.values, perf@y.values) head(x) head(as.numeric(perf@x.values)) head(as.data.frame(perf@x.values)) head(as.matrix(perf@x.values)) head(as.matrix(perf@y.values)) head(as.matrix(perf@y.values[[1]])) head(perf@y.values[[1]]) write.csv(cbind(perf@x.values[[1]], perf@y.values[[1]]), '~/Dropbox/performance.csv', row.names=F, quote=F) write.csv(cbind(perf@x.values[[1]], perf@y.values[[1]]), '~/Dropbox/performance.csv', row.names=F, col.names=F, quote=F) pred <- prediction(data$sider, data$shared) performance(pred, measure="auc")@y.values[[1]] pred <- prediction(data$offsides, data$shared) performance(pred, measure="auc")@y.values[[1]] pred <- prediction(predict(fit), data$shared) performance(pred, measure="auc")@y.values[[1]] summary(fit) pred <- prediction(data$sider, data$shared) perf <- performance(pred, measure="tpr", x.measure="fpr") write.csv(cbind(perf@x.values[[1]], perf@y.values[[1]]), '~/Dropbox/performance.csv', row.names=F, quote=F) pred <- prediction(data$offsides, data$shared) perf <- performance(pred, measure="tpr", x.measure="fpr") write.csv(cbind(perf@x.values[[1]], perf@y.values[[1]]), '~/Dropbox/performance.csv', row.names=F, quote=F) summary(fit) pred <- prediction(data$sider, data$shared) performance(pred, measure="auc")@y.values[[1]] pred <- prediction(data$offsides, data$shared) performance(pred, measure="auc")@y.values[[1]] pred <- prediction(predict(fit), data$shared) performance(pred, measure="auc")@y.values[[1]] summary(fit) head(data) data <- dbGetQuery(mycon, " select stitch_id1, stitch_id2, o.z_score1 as offsides, s.z_score1 as sider, shared_indication is not null as shared from drug_similarity_b o join drug_similarity_sider s using (stitch_id1, stitch_id2) left join drug_shared_indication using (stitch_id1, stitch_id2) where o.z_score1 is not null and s.z_score1 is not null ") mycon <- dbConnect(MySQL(), user='root', dbname="project_aers", host="localhost", port=3306, password='kuancfit') library(RMySQL) mycon <- dbConnect(MySQL(), user='root', dbname="project_aers", host="localhost", port=3306, password='kuancfit') data <- dbGetQuery(mycon, " select stitch_id1, stitch_id2, o.z_score1 as offsides, s.z_score1 as sider, shared_indication is not null as shared from drug_similarity_b o join drug_similarity_sider s using (stitch_id1, stitch_id2) left join drug_shared_indication using (stitch_id1, stitch_id2) where o.z_score1 is not null and s.z_score1 is not null ") fit <- glm(shared ~ offsides + sider, data, family="binomial") summary(fit) data$both <- predict(fit) head(data) write.csv(data, '~/drug_similarity_bsider_logreg_indication.csv', row.names=F, header=F, quote=F) write.csv(data, '~/drug_similarity_bsider_logreg_indication.csv', row.names=F, quote=F)