Title: | Personalized Disease Network |
---|---|
Description: | Building patient level networks for prediction of medical outcomes and draw the cluster of network. This package is based on paper Personalized disease networks for understanding and predicting cardiovascular diseases and other complex processes (See Cabrera et al. <http://circ.ahajournals.org/content/134/Suppl_1/A14957>). |
Authors: | Javier Cabrera <[email protected]>, Fei Wang <[email protected]> |
Maintainer: | Zhenbang Wang <[email protected]> |
License: | GPL-2 |
Version: | 0.1.0 |
Built: | 2024-11-20 04:05:30 UTC |
Source: | https://github.com/cran/PDN |
Building patient level networks for prediction of medical outcomes and draw the cluster of network. This pakcage is based on paper Personalized disease networks (PDN) for understanding and predicting cardiovascular diseases and other complex processes.
Package: | PDN |
Type: | Package |
Version: | 1.0 |
Date: | 2017-08-14 |
License: | GPL-2 |
Javier Cabrera and Fei Wang
Maintainer: Zhenbang Wang <[email protected]>
Cabrera, Javier and Kostis, John B and Wang, Fei and Kostis, William J. (2016) Personalized Disease Networks in Predicting Cardiovascular Outcomes
This function use data set with cut off information to create network matrix
buildnetworks(x, k1, del = 0)
buildnetworks(x, k1, del = 0)
x |
comorbidity data matrix with column correspond to ICD9 codes and row correspond to each patient |
k1 |
the cut off point between Diagnosis/Procedure A to another Diagnosis/Procedure B, it can be fix number, NULL and datecut |
del |
number of character deleted for each name of the input |
Network Matrix
# Select a subset of data for toy example comorbidity_data = comorbidity_data[c(1:10),] survival_data = survival_data[c(1:10),] k1 = datecut(comorbidity_data,survival_data[,1],survival_data[,2]) a = buildnetworks(comorbidity_data,k1)
# Select a subset of data for toy example comorbidity_data = comorbidity_data[c(1:10),] survival_data = survival_data[c(1:10),] k1 = datecut(comorbidity_data,survival_data[,1],survival_data[,2]) a = buildnetworks(comorbidity_data,k1)
This is the sample data set for Package PDN
comorbidity_data
comorbidity_data
100 rows and 10 column matrix
Performs Cox proportional hazards regression model on patients survival days based on different cutoffs
datecut(x, surdays, event)
datecut(x, surdays, event)
x |
comorbidity data matrix with column correspond to ICD9 codes and row correspond to each patient |
surdays |
survival days for each patient |
event |
indictor variable 1 represent patient died 0 represent patient survive |
Building and draw personized disease network
a vector of cutoff points that maximize the Z statistics for cox model between each Diagnosis/Procedure A to another Diagnosis/Procedure B
comorbidity_data survival_data #Select a subset of data for toy example comorbidity_data = comorbidity_data[c(1:10),] survival_data = survival_data[c(1:10),] k1 = datecut(comorbidity_data,survival_data[,1],survival_data[,2])
comorbidity_data survival_data #Select a subset of data for toy example comorbidity_data = comorbidity_data[c(1:10),] survival_data = survival_data[c(1:10),] k1 = datecut(comorbidity_data,survival_data[,1],survival_data[,2])
This is one of the sample data set. It contains the demographic information of each patients It has five variables which are sex, race, hispan, dshyr and prime
demographic_data
demographic_data
100 rows and 5 column matrix
Draw Personalized Disease Network based on newtwork matrix
draw.PDN(tt, labels)
draw.PDN(tt, labels)
tt |
one row of network matrix generated from comorbidity data matrix using buildnetworks |
labels |
names of each node in the network matrix |
#Select a subset of data for toy example comorbidity_data = comorbidity_data[c(1:10),] survival_data = survival_data[c(1:10),] # Getting the names k1 = datecut(comorbidity_data,survival_data[,1],survival_data[,2]) a = buildnetworks(comorbidity_data,k1) #Plot PDN for patient 7 nn = names(comorbidity_data) draw.PDN(a[7,],nn)
#Select a subset of data for toy example comorbidity_data = comorbidity_data[c(1:10),] survival_data = survival_data[c(1:10),] # Getting the names k1 = datecut(comorbidity_data,survival_data[,1],survival_data[,2]) a = buildnetworks(comorbidity_data,k1) #Plot PDN for patient 7 nn = names(comorbidity_data) draw.PDN(a[7,],nn)
Draw Personalized Disease Network based on newtwork matrix
draw.PDN.circle(a0, dak)
draw.PDN.circle(a0, dak)
a0 |
one row of network matrix generated from comorbidity data matrix using buildnetworks |
dak |
one row of Ranks matrix for corresponding comorbidity data matrix |
#Select a subset of data for toy example comorbidity_data = comorbidity_data[c(1:10),] survival_data = survival_data[c(1:10),] # Find date cuts k1 = datecut(comorbidity_data,survival_data[,1],survival_data[,2]) # Build networks a = buildnetworks(comorbidity_data,k1) # Graph individual patients datark = t(apply(comorbidity_data,1,rank)) dak = sort(datark[1,]) # draw PDN for the first patient draw.PDN.circle(a[1,],dak) # draw PDN for the whole comorbidity data set par(mfrow=c(2,5)) for(i in 1 : nrow(a)){ dak = apply(datark,2,sort) draw.PDN.circle(a[i,],dak[i,]) title(main=paste("Patient",i)) }
#Select a subset of data for toy example comorbidity_data = comorbidity_data[c(1:10),] survival_data = survival_data[c(1:10),] # Find date cuts k1 = datecut(comorbidity_data,survival_data[,1],survival_data[,2]) # Build networks a = buildnetworks(comorbidity_data,k1) # Graph individual patients datark = t(apply(comorbidity_data,1,rank)) dak = sort(datark[1,]) # draw PDN for the first patient draw.PDN.circle(a[1,],dak) # draw PDN for the whole comorbidity data set par(mfrow=c(2,5)) for(i in 1 : nrow(a)){ dak = apply(datark,2,sort) draw.PDN.circle(a[i,],dak[i,]) title(main=paste("Patient",i)) }
Draw Personalized Disease Network based on cluster information
draw.PDN.cluster(a0, dak)
draw.PDN.cluster(a0, dak)
a0 |
network matrix get from buildnetworks |
dak |
ranks data for comorbidity data matrix |
#Select a subset of data for toy example comorbidity_data = comorbidity_data[c(1:10),] survival_data = survival_data[c(1:10),] ##Clustering Example k1 = datecut(comorbidity_data,survival_data[,1],survival_data[,2]) a = buildnetworks(comorbidity_data,k1) datark = t(apply(comorbidity_data,1,rank)) require(survival) zsq = NULL for(i in 1:ncol(a)){ a1 = (summary(coxph(Surv(as.numeric(survival_data[,1]),survival_data[,2]) ~ a[,i], data=as.data.frame(a)))$coefficient[,4])^2 zsq = cbind(zsq,a1) } zsq = as.numeric(zsq) wi=zsq/sum(zsq,na.rm=TRUE) wi[wi<10^ -3]=10^ -3 wi[is.na(wi)]=10^ -3 #weighted matrix wa = NULL for(i in 1:ncol(a)){ wa = cbind(wa,a[,i]*wi[i]) } #PCA pr.out=prcomp(wa) x.svd=svd(wa) x.score1 <- wa %*% x.svd$v x.score2 <- x.svd$u %*% diag(x.svd$d) ##HC cluster using the first 8 PCA scores dp<-dist(x.score2[,1:8]) hcp<-hclust(dp, method="ward.D") ##Plot Network s1=rev(sort(apply(a[cutree(hcp,3)==2,],2,mean)))[1:50] dak = sort(apply(datark[cutree(hcp,3)==2,],2,mean,na.rm=TRUE)) names(dak) = unlist(strsplit(names(dak),"DAT")) draw.PDN.cluster(s1,dak)
#Select a subset of data for toy example comorbidity_data = comorbidity_data[c(1:10),] survival_data = survival_data[c(1:10),] ##Clustering Example k1 = datecut(comorbidity_data,survival_data[,1],survival_data[,2]) a = buildnetworks(comorbidity_data,k1) datark = t(apply(comorbidity_data,1,rank)) require(survival) zsq = NULL for(i in 1:ncol(a)){ a1 = (summary(coxph(Surv(as.numeric(survival_data[,1]),survival_data[,2]) ~ a[,i], data=as.data.frame(a)))$coefficient[,4])^2 zsq = cbind(zsq,a1) } zsq = as.numeric(zsq) wi=zsq/sum(zsq,na.rm=TRUE) wi[wi<10^ -3]=10^ -3 wi[is.na(wi)]=10^ -3 #weighted matrix wa = NULL for(i in 1:ncol(a)){ wa = cbind(wa,a[,i]*wi[i]) } #PCA pr.out=prcomp(wa) x.svd=svd(wa) x.score1 <- wa %*% x.svd$v x.score2 <- x.svd$u %*% diag(x.svd$d) ##HC cluster using the first 8 PCA scores dp<-dist(x.score2[,1:8]) hcp<-hclust(dp, method="ward.D") ##Plot Network s1=rev(sort(apply(a[cutree(hcp,3)==2,],2,mean)))[1:50] dak = sort(apply(datark[cutree(hcp,3)==2,],2,mean,na.rm=TRUE)) names(dak) = unlist(strsplit(names(dak),"DAT")) draw.PDN.cluster(s1,dak)
This is the sample data set for function datecut. The first column is the time difference between the patient admission date and death date The second column is the indictor variable with 1 corresponding to patient death, 0 corresponding to patient alive
survival_data
survival_data
100 rows and 2 column matrix