Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(cvq2)
- #library(leaps)
- # cia is karto jau pKd skirtumas imtas:
- selectivity<-read.table("selectivityCA12.csv", sep=",", header=TRUE)
- qsar12_1<-data.frame(K<-selectivity$CA12.1)
- qsar12_1$x<-as.matrix(read.table("edragon_descriptors_fix4.csv", sep=",", skip=1))
- #random numbers:
- #> test <- sort(round(runif(10, 1, 40)))
- #> test
- test <- c(2, 3, 8, 9, 10, 16, 18, 19, 29, 35)
- #tada:
- train <- c(1, 4, 5, 6, 7, 11, 12, 13, 14, 15, 17, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 36, 37, 38, 39, 40)
- r2=NULL
- r2good=NULL
- for (i in 1:1317 ) {
- fit.single<-lm(qsar12_1$K[train]~qsar12_1$x[train,i])
- r2[i]<-summary(fit.single)$r.squared
- if(r2[i]>0.3) {
- r2good[i]<-r2[i]
- }
- }
- #leaps<-regsubsets(qsar12_1$K[train]~qsar12_1$x[train,c(1:31)], data=qsar12_1, nvmax=5)
- #plot(leaps, scale="r2")
- qsar_12_1_train<-lm(qsar12_1$K[train] ~ qsar12_1$x[train, 105] + qsar12_1$x[train, 333] + qsar12_1$x[train, 1205])
- print(summary(qsar_12_1_train))
- qsar_12_1_test_pred_values<-coef(qsar_12_1_train)[1]+coef(qsar_12_1_train)[2]*qsar12_1$x[test, 105]+coef(qsar_12_1_train)[3]*qsar12_1$x[test, 333]+coef(qsar_12_1_train)[4]*qsar12_1$x[test, 1205]
- qsar_12_1_test<-lm(qsar_12_1_test_pred_values ~ qsar12_1$K[test])
- print(summary(qsar_12_1_test))
- x<-cbind(qsar12_1$x[train,c(105,333,1205)], qsar12_1$K[train])
- colnames(x)[4]<-"y"
- qsar_12_1_q2<-cvq2(x)
- print(qsar_12_1_q2)
- #==========================================
- qsar12_2<-data.frame(K<-selectivity$CA12.2)
- qsar12_2$x<-as.matrix(read.table("edragon_descriptors_fix4.csv", sep=",", skip=1))
- r2=NULL
- r2good=NULL
- for (i in 1:1317 ) {
- fit.single<-lm(qsar12_2$K[train]~qsar12_2$x[train,i])
- r2[i]<-summary(fit.single)$r.squared
- if(r2[i]>0.3) {
- r2good[i]<-r2[i]
- }
- }
- #kaip ir be leaps variantas:
- #tada imti didziausia is r2good ir salinti koreliacijas su kitais, rasti kuris nekoreliuoja
- #r2very_good istrintos koreliacijos su 1231 kuris labai geras sitame....
- #arba r2good kas gero tada dar ziureti su leaps
- qsar_12_2_train<-lm(qsar12_2$K[train] ~ qsar12_2$x[train, 293] +qsar12_2$x[train, 308] + qsar12_2$x[train, 311])
- print(summary(qsar_12_2_train))
- qsar_12_2_test_pred_values<-coef(qsar_12_2_train)[1]+coef(qsar_12_2_train)[2]*qsar12_2$x[test, 293]+coef(qsar_12_2_train)[3]*qsar12_2$x[test, 308]+coef(qsar_12_2_train)[4]*qsar12_2$x[test, 311]
- qsar_12_2_test<-lm(qsar_12_2_test_pred_values ~ qsar12_2$K[test])
- print(summary(qsar_12_2_test))
- x<-cbind(qsar12_2$x[train,c(293,308,311)], qsar12_2$K[train])
- colnames(x)[4]<-"y"
- qsar_12_2_q2<-cvq2(x)
- print(qsar_12_2_q2)
- #=============================================
- qsar12_6<-data.frame(K<-selectivity$CA12.6)
- qsar12_6$x<-as.matrix(read.table("edragon_descriptors_fix4.csv", sep=",", skip=1))
- r2=NULL
- r2good=NULL
- for (i in 1:1317 ) {
- fit.single<-lm(qsar12_6$K[train]~qsar12_6$x[train,i])
- r2[i]<-summary(fit.single)$r.squared
- if(r2[i]>0.3) {
- r2good[i]<-r2[i]
- }
- }
- good_deskr_nr<-NULL
- for (i in 1:1317 ) {
- if(r2[i]>0.3) {
- good_deskr_nr<-c(good_deskr_nr, i)
- }
- }
- leaps<-regsubsets(qsar12_6$K[train]~qsar12_6$x[train,good_deskr_nr[1:25]], data=qsar12_6, nvmax=3)
- plot(leaps, scale="r2")
- qsar_12_6_train<-lm(qsar12_6$K[train] ~ qsar12_6$x[train, 38] + qsar12_6$x[train, 283] + qsar12_6$x[train, 299])
- print(summary(qsar_12_6_train))
- qsar_12_6_test_pred_values<-coef(qsar_12_6_train)[1]+coef(qsar_12_6_train)[2]*qsar12_6$x[test, 38]+coef(qsar_12_6_train)[3]*qsar12_6$x[test, 283]+coef(qsar_12_6_train)[4]*qsar12_6$x[test, 299]
- qsar_12_6_test<-lm(qsar_12_6_test_pred_values ~ qsar12_6$K[test])
- print(summary(qsar_12_6_test))
- x<-cbind(qsar12_6$x[train,c(38,283,299)], qsar12_6$K[train])
- colnames(x)[4]<-"y"
- qsar_12_6_q2<-cvq2(x)
- print(qsar_12_6_q2)
- #===============================================
- qsar12_7<-data.frame(K<-selectivity$CA12.7)
- qsar12_7$x<-as.matrix(read.table("edragon_descriptors_fix4.csv", sep=",", skip=1))
- r2=NULL
- r2good=NULL
- for (i in 1:1317 ) {
- fit.single<-lm(qsar12_7$K[train]~qsar12_7$x[train,i])
- r2[i]<-summary(fit.single)$r.squared
- if(r2[i]>0.3) {
- r2good[i]<-r2[i]
- }
- }
- good_deskr_nr<-NULL
- for (i in 1:1317 ) {
- if(r2[i]>0.3) {
- good_deskr_nr<-c(good_deskr_nr, i)
- }
- }
- leaps<-regsubsets(qsar12_7$K[train]~qsar12_7$x[train,good_deskr_nr[1:25]], data=qsar12_7, nvmax=3)
- plot(leaps, scale="r2")
- qsar_12_7_train<-lm(qsar12_7$K[train] ~ qsar12_7$x[train, 300] + qsar12_7$x[train, 463] + qsar12_7$x[train, 841])
- print(summary(qsar_12_7_train))
- qsar_12_7_test_pred_values<-coef(qsar_12_7_train)[1]+coef(qsar_12_7_train)[2]*qsar12_7$x[test, 300]+coef(qsar_12_7_train)[3]*qsar12_7$x[test, 463]+coef(qsar_12_7_train)[4]*qsar12_7$x[test, 841]
- qsar_12_7_test<-lm(qsar_12_7_test_pred_values ~ qsar12_7$K[test])
- print(summary(qsar_12_7_test))
- x<-cbind(qsar12_7$x[train,c(300,463,841)], qsar12_7$K[train])
- colnames(x)[4]<-"y"
- qsar_12_7_q2<-cvq2(x)
- print(qsar_12_7_q2)
- #===============================================
- qsar12_13<-data.frame(K<-selectivity$CA12.13)
- qsar12_13$x<-as.matrix(read.table("edragon_descriptors_fix4.csv", sep=",", skip=1))
- r2=NULL
- r2good=NULL
- for (i in 1:1317 ) {
- fit.single<-lm(qsar12_13$K[train]~qsar12_13$x[train,i])
- r2[i]<-summary(fit.single)$r.squared
- if(r2[i]>0.3) {
- r2good[i]<-r2[i]
- }
- }
- good_deskr_nr<-NULL
- for (i in 1:1317 ) {
- if(r2[i]>0.3) {
- good_deskr_nr<-c(good_deskr_nr, i)
- }
- }
- leaps<-regsubsets(qsar12_13$K[train]~qsar12_13$x[train,good_deskr_nr], data=qsar12_13, nvmax=3)
- plot(leaps, scale="r2")
- qsar_12_13_train<-lm(qsar12_13$K[train] ~ qsar12_13$x[train, 278] + qsar12_13$x[train, 300] + qsar12_13$x[train, 1153])
- print(summary(qsar_12_13_train))
- qsar_12_13_test_pred_values<-coef(qsar_12_13_train)[1]+coef(qsar_12_13_train)[2]*qsar12_13$x[test, 278]+coef(qsar_12_13_train)[3]*qsar12_13$x[test, 300]+coef(qsar_12_13_train)[4]*qsar12_13$x[test, 1153]
- qsar_12_13_test<-lm(qsar_12_13_test_pred_values ~ qsar12_13$K[test])
- print(summary(qsar_12_13_test))
- x<-cbind(qsar12_13$x[train,c(278,300,1153)], qsar12_13$K[train])
- colnames(x)[4]<-"y"
- qsar_12_13_q2<-cvq2(x)
- print(qsar_12_13_q2)
- #===============================================
- qsarSUM<-data.frame(K<-selectivity$SUMsCA12)
- qsarSUM$x<-as.matrix(read.table("edragon_descriptors_fix4.csv", sep=",", skip=1))
- r2=NULL
- r2good=NULL
- for (i in 1:1317 ) {
- fit.single<-lm(qsarSUM$K[train]~qsarSUM$x[train,i])
- r2[i]<-summary(fit.single)$r.squared
- if(r2[i]>0.3) {
- r2good[i]<-r2[i]
- }
- }
- good_deskr_nr<-NULL
- for (i in 1:1317 ) {
- if(r2[i]>0.3) {
- good_deskr_nr<-c(good_deskr_nr, i)
- }
- }
- leaps<-regsubsets(qsarSUM$K[train]~qsarSUM$x[train,good_deskr_nr], data=qsarSUM, nvmax=3)
- plot(leaps, scale="r2")
- qsar_SUM_train<-lm(qsarSUM$K[train] ~ qsarSUM$x[train, 1167] + qsarSUM$x[train, 1178] + qsarSUM$x[train, 1232])
- print(summary(qsar_SUM_train))
- qsar_SUM_test_pred_values<-coef(qsar_SUM_train)[1]+coef(qsar_SUM_train)[2]*qsarSUM$x[test, 1167]+coef(qsar_SUM_train)[3]*qsarSUM$x[test, 1178]+coef(qsar_SUM_train)[4]*qsarSUM$x[test, 1232]
- qsar_SUM_test<-lm(qsar_SUM_test_pred_values ~ qsarSUM$K[test])
- print(summary(qsar_SUM_test))
- x<-cbind(qsarSUM$x[train,c(1167,1178,1232)], qsarSUM$K[train])
- colnames(x)[4]<-"y"
- qsar_SUM_q2<-cvq2(x)
- print(qsar_SUM_q2)
- #===============================================
- #grafiko asys nuo/iki:
- minK<-5.8
- maxK<-9
- qsar1<-coef(qsar_12_1_train)[1]+coef(qsar_12_1_train)[2]*qsar$x[, 275]+coef(qsar_12_1_train)[3]*qsar$x[, 1074]+coef(qsar_12_1_train)[4]*qsar$x[, 1107]
- qsar2<-coef(qsar_12_2_train)[1]+coef(qsar_12_2_train)[2]*qsar$x[, 649]+coef(qsar_12_2_train)[3]*qsar$x[, 1074]+coef(qsar_12_2_train)[4]*qsar$x[, 1259]
- qsar3<-coef(qsar_12_3_train)[1]+coef(qsar_12_3_train)[2]*qsar$x[, 100]+coef(qsar_12_3_train)[3]*qsar$x[, 275]+coef(qsar_12_3_train)[4]*qsar$x[, 300]
- grafikui<-cbind(qsar$K, qsar1, qsar2, qsar3)
- colnames(grafikui)[1]<-"pKd"
- mod_qsar1<-lm(grafikui[train,1]~grafikui[train,2])
- mod_qsar2<-lm(grafikui[train,1]~grafikui[train,3])
- mod_qsar3<-lm(grafikui[train,1]~grafikui[train,4])
- mod_qsar1t<-lm(grafikui[test,1]~grafikui[test,2])
- mod_qsar2t<-lm(grafikui[test,1]~grafikui[test,3])
- mod_qsar3t<-lm(grafikui[test,1]~grafikui[test,4])
- png("Edita2013_grafikas2.png", width=600, height=900)
- par(mfrow=c(3,2), mar=c(1,1,0,0), oma=c(6,6,0,0), cex.axis=2)
- plot(grafikui[train,1], grafikui[train,2], tck = 0.02, pch=15, cex=3, xlim=c(minK, maxK), ylim=c(minK, maxK), ann=FALSE, xaxt="n")
- abline(mod_qsar1)
- title('QSAR1', line = -3, cex.main=3)
- axis(1,col.axis = "transparent", tck = 0.02)
- plot(grafikui[test,1], grafikui[test,2], tck = 0.02, pch=15, cex=3, xlim=c(minK, maxK), ylim=c(minK, maxK), xlab=NA, ylab=NA, xaxt="n", yaxt="n")
- abline(mod_qsar1t)
- title('QSAR1 test set', line = -3, cex.main=3)
- axis(1,col.axis = "transparent", tck = 0.02)
- axis(2,col.axis = "transparent", tck = 0.02)
- plot(grafikui[train,1], grafikui[train,3], tck = 0.02, pch=15, cex=3, xlim=c(minK, maxK), ylim=c(minK, maxK), ann=FALSE, xaxt="n")
- abline(mod_qsar2)
- title('QSAR2', line = -3, cex.main=3)
- plot(grafikui[test,1], grafikui[test,3], tck = 0.02, pch=15, cex=3, xlim=c(minK, maxK), ylim=c(minK, maxK), ann=FALSE, xaxt="n", yaxt="n")
- abline(mod_qsar2t)
- title('QSAR2 test set', line = -3, cex.main=3)
- axis(1,col.axis = "transparent", tck = 0.02)
- axis(2,col.axis = "transparent", tck = 0.02)
- plot(grafikui[train,1], grafikui[train,4], tck = 0.02, pch=15, cex=3, xlim=c(minK, maxK), ylim=c(minK, maxK), ann=FALSE)
- abline(mod_qsar3)
- title('QSAR3', line = -3, cex.main=3)
- plot(grafikui[test,1], grafikui[test,4], tck = 0.02, pch=15, cex=3, xlim=c(minK, maxK), ylim=c(minK, maxK), yaxt="n", cex.lab=3)
- abline(mod_qsar3t)
- title('QSAR3 test set', line = -3, cex.main=3)
- axis(2,col.axis = "transparent", tck = 0.02)
- mtext('pKd (experimental)', SOUTH<-1, line=2.5, cex=2, outer=TRUE)
- mtext('pKd (calculated)', WEST<-2, line=2.5, cex=2, outer=TRUE)
- dev.off()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement