Chapter 5 Including clinical variables
5.1 Preparation of data
One of the important reasons of the Bayesian network analysis is assessing the relationship between gene expressions and clinical variables. CBNplot
offers incorporating metadata into inference. As a demonstrative purpose, the enrichment analysis results from GSE133624 is applied on data from The Cancer Genome Atlas Program (TCGA) (Cancer Genome Atlas Research Network et al. 2013). Specifically, TCGA-BLCA data is downloaded by the useful library TCGAbiolinks
(Colaprico et al. 2016).
library(TCGAbiolinks)
## Load dataset
load(file="tcgablcaData.rda")
We filtered the metadata based on the variables to be included in the inference. In this analysis, age_at_diagnosis
and paper_Combined T and LN category
, which is a sum of Tumor stage T 1/2 (0) vs. 3/4 (1) and LN negative (0) vs positive (1), are included. We again applied VST on the data.
5.2 Inference of pathway relationship including clinical variables
We assess the relationship between the curated biological pathway information and clinical variables mentioned above. Variables other than expression data can be specified with otherVar
, as well as otherVarName
for their name. The order of otherVar
must be same as column order of expression data. We use all the significant pathways of corrected p-values below 0.05.
<- bnpathplot(pway,
bnCov
vstedTCGA,nCategory = 1000,
adjpCutOff = 0.01,
expSample=rownames(metadata),
algo="hc", strType="normal",
otherVar=metadata,
otherVarName=c("Age", "Category"),
R=50, cl=parallel::makeCluster(10),
returnNet=T,
shadowText=T)
## Check DAG
::is.dag(as.igraph(bnCov$av)) igraph
FALSE [1] TRUE
## Fit the parameter to network based on the data
<- bn.fit(bnCov$av, bnCov$df) bnFit
Plot the resulting network.
$plot bnCov
5.3 Conditional probability query
Next we perform conditional probability queries by the bnlearn function cpdist
to elucidate how the clinical variables affect pathway regulation. First we fit the inferred network to the original data. These are stored in the named list. Logic sampling is performed unless otherwise stated.
Perform cpdist
, and visualize the distribution of “Molecules associated with elastic fibres” conditional on the tumor category using ggdist
.
library(bnlearn)
library(ggdist)
library(ggplot2)
<- "Molecules associated with elastic fibres"
candPath
<- cpdist(bnFit, nodes=c(candPath), evidence=(Category==0))
efz <- cpdist(bnFit, nodes=c(candPath), evidence=(Category==1))
efo <- cpdist(bnFit, nodes=c(candPath), evidence=(Category==2))
eft
= data.frame(
effect val = c(efz[,1], efo[,1], eft[,1]),
stage = c(rep("0",nrow(efz)), rep("1", nrow(efo)), rep("2", nrow(eft)))
)
<- effect %>% group_by(stage) %>% summarise(mean=mean(val))
disMean <- paste0(disMean$stage, " (mean=", round(disMean$mean,3), ")")
stageWMean $stageLabel <- c(rep(stageWMean[1],nrow(efz)), rep(stageWMean[2], nrow(efo)), rep(stageWMean[3], nrow(eft)))
effect
ggplot(effect, aes(x=val, y=stage, color=stageLabel, fill=stageLabel)) +
scale_color_manual(values=c("steelblue","gold","tomato")) +
scale_fill_manual(values=c("steelblue","gold","tomato")) +
stat_dotsinterval() + theme_bw() + ggtitle(candPath)
How the down-regulation in “Cell Cycle Checkpoints” affects the other pathways? This time using the importance sampling method, likelihood weighting.
<- names(bnFit)
predNodes <- predNodes[predNodes != "Cell Cycle Checkpoints"]
predNodes <- max(bnCov$df[candPath])
maxVal <- min(bnCov$df[candPath])
minVal
<- cpdist(bnFit, nodes=predNodes, evidence=list("Cell Cycle Checkpoints"=minVal), method="lw")
lowCCC <- attributes(lowCCC)$weights
lowW <- cpdist(bnFit, nodes=predNodes, evidence=list("Cell Cycle Checkpoints"=maxVal), method="lw")
highCCC <- attributes(highCCC)$weights
highW
## Remove the factor
$Category <- NULL
highCCC$Category <- NULL
lowCCC
<- apply(highCCC, 2, function(x) weighted.mean(x, highW)) - apply(lowCCC, 2, function(x) weighted.mean(x, lowW))
difMeanCCC
## Top absolute value
kable(head(difMeanCCC[order(abs(difMeanCCC), decreasing=TRUE)]), col.names=c("difference"))
difference | |
---|---|
M Phase | 23.15520 |
Mitotic Prometaphase | 20.93115 |
Mitotic Metaphase and Anaphase | 20.70000 |
Mitotic Anaphase | 20.56985 |
Separation of Sister Chromatids | 19.35587 |
Resolution of Sister Chromatid Cohesion | 19.16356 |
## Reflect the difference in the plot modifying ggplot2 object
<- bnCov$plot$data
changeCol <- difMeanCCC[changeCol$name]
difMeanCCC names(difMeanCCC) <- changeCol$name
$color <- difMeanCCC
changeCol
## Replace the color, change the legend
$plot$data <- changeCol
bnCov$plot + scale_color_continuous(low="blue",high="red",name="difference") bnCov
5.4 Gene relationship with variables
For the genes in interesting pathway, clinical variables can be incorporated too. We investigated the genes involved in the reactome “Molecules associated with elastic fibres”.
<- which(pway@result$Description=="Molecules associated with elastic fibres")
num <- bngeneplot(pway,
bnGeneCov pathNum=num,
vstedTCGA, expSample=rownames(metadata),
otherVar=metadata,
hub=5, R=100,
otherVarName=c("Age","Category"),
cl=parallel::makeCluster(10),
returnNet=T)
Plot the resulting network of genes.
## Plot
$plot bnGeneCov
## Check DAG
::is.dag(as.igraph(bnGeneCov$av)) igraph
FALSE [1] TRUE
## Fit the parameter to network based on the data
<- bn.fit(bnGeneCov$av, bnGeneCov$df) bnFitGene
Perform cpdist
, and examine the mean and distribution using ggdist
. We can see that the expression of the gene EFEMP1, which is reported to be a candidate for a biomarker of aggressive bladder cancer or therapeutic targets (Han et al. 2017), is going up with each stage.
<- "EFEMP1"
candGene <- cpdist(bnFitGene, nodes=c(candGene), evidence=(Category==0))
efz <- cpdist(bnFitGene, nodes=c(candGene), evidence=(Category==1))
efo <- cpdist(bnFitGene, nodes=c(candGene), evidence=(Category==2))
eft
= data.frame(
effect val = c(efz[,1], efo[,1], eft[,1]),
stage = c(rep("0",nrow(efz)), rep("1", nrow(efo)), rep("2", nrow(eft)))
)
<- effect %>% group_by(stage) %>% summarise(mean=mean(val))
disMean <- paste0(disMean$stage, " (mean=", round(disMean$mean,3), ")")
stageWMean $stageLabel <- c(rep(stageWMean[1],nrow(efz)), rep(stageWMean[2], nrow(efo)), rep(stageWMean[3], nrow(eft)))
effect
ggplot(effect, aes(x=val, y=stage, color=stageLabel, fill=stageLabel)) +
scale_color_manual(values=c("steelblue","gold","tomato")) +
scale_fill_manual(values=c("steelblue","gold","tomato")) +
stat_dotsinterval() + theme_bw() + ggtitle(candGene)
We can reflect the difference to the plot. In the previous EFEMP1 plot:
<- names(bnFitGene)
candGene <- candGene[candGene != "Category"]
candGene <- cpdist(bnFitGene, nodes=candGene, evidence=(Category==0))
efz2 <- cpdist(bnFitGene, nodes=candGene, evidence=(Category==2))
eft2
<- apply(eft2, 2, mean) - apply(efz2, 2, mean)
difMean
<- bnGeneCov$plot$data
changeCol <- difMean[changeCol$name]
difMean names(difMean) <- changeCol$name
$color <- difMean
changeCol
## Replace shape and color
$shape <- rep(19, dim(bnGeneCov$plot$data)[1])
changeCol$plot$data <- changeCol
bnGeneCov$plot + scale_color_continuous(low="blue",high="red",name="difference") bnGeneCov
5.5 Confirming the existing knowledge
To confirm the validity of the inferred Bayesian network, we can focus on some genes that is already validated to be related to clinical information or is incorporated into the daily clinical practice. To obtain the pathways that include the specific gene, one can use obtainPath
function. This time we focus on the gene MMP2, as the gene has been reported to be related to clinical variables in bladder cancer (Vasala, Pääkkö, and Turpeenniemi-Hujanen 2003; Fouad et al. 2019; Winerdal et al. 2018).
<- obtainPath(pway, "MMP2") pathSub
Using the top pathway involving MMP2, construct the network and plot.
<- bngeneplot(pathSub,
bnGeneCov2 pathNum=1,
vstedTCGA, expSample=rownames(metadata),
otherVar=metadata,
hub=5, R=100, algo="hc",
otherVarName=c("Age","Category"),
cl=parallel::makeCluster(10),
returnNet=T)
$plot bnGeneCov2
<- bn.fit(bnGeneCov2$av, bnGeneCov2$df) bnGeneCov2Fit
Predict the distribution.
<- "MMP2"
candGene
<- cpdist(bnGeneCov2Fit, nodes=c(candGene), evidence=(Category==0), method="ls")
mz <- cpdist(bnGeneCov2Fit, nodes=c(candGene), evidence=(Category==1), method="ls")
mo <- cpdist(bnGeneCov2Fit, nodes=c(candGene), evidence=(Category==2), method="ls")
mt
= data.frame(
effect val = c(mz[,1], mo[,1], mt[,1]),
stage = c(rep("0",nrow(mz)), rep("1", nrow(mo)), rep("2", nrow(mt)))
)
<- effect %>% group_by(stage) %>% summarise(mean=mean(val))
disMean <- paste0(disMean$stage, " (mean=", round(disMean$mean,3), ")")
stageWMean $stageLabel <- c(rep(stageWMean[1],nrow(mz)), rep(stageWMean[2], nrow(mo)), rep(stageWMean[3], nrow(mt)))
effect
ggplot(effect, aes(x=val, y=stage, color=stageLabel, fill=stageLabel)) +
scale_color_manual(values=c("steelblue","gold","tomato")) +
scale_fill_manual(values=c("steelblue","gold","tomato")) +
stat_dotsinterval() + theme_bw() + ggtitle(candGene)
It is interesting to investigate whether the result is similar in the other database, like Gene Ontology doing the same analysis.
## Perform the same analysis on GO enrichment result
<- obtainPath(pwayGO, "MMP2")
pathSubGO @result[1:5, c("Description","geneID","Count")] pathSubGO
FALSE Description
FALSE GO:0001968 fibronectin binding
FALSE GO:0004222 metalloendopeptidase activity
FALSE GO:0008237 metallopeptidase activity
FALSE GO:0004252 serine-type endopeptidase activity
FALSE GO:0008236 serine-type peptidase activity
FALSE geneID
FALSE GO:0001968 MYOC/FSTL3/FBLN1/MMP2/CCDC80/VEGFA/CCN2/THBS1/SFRP2/EPHA1/IGFBP6/LRRC15/SSC5D
FALSE GO:0004222 NRDC/MMP2/MMP11/ADAM2/COPS5/NLN/MMP19/MMP24/ADAMTS8/MMP27/MMP13/ADAM10/ECE2/ADAM33/ADAM17/ADAMTS1/ADAMTS5/ADAMTS4/MMP10/ADAMTS20/PAPPA/LMLN/MMP23B/MMP1/TRABD2B
FALSE GO:0008237 NAALAD2/NRDC/MMP2/MMP11/CPQ/ADAM2/PSMD14/COPS5/CPXM2/XPNPEP2/NLN/MMP19/STAMBP/MMP24/CPA4/ADAMTS8/MMP27/MMP13/ADAM10/ECE2/ADAM33/ADAM17/ADAMTS1/ADAMTS5/ADAMTS4/MYSM1/CPA3/MMP10/ADAMTS20/PAPPA/LMLN/MMP23B/MMP1/TRABD2B
FALSE GO:0004252 LTF/MMP2/CMA1/TPSD1/MMP11/ACR/CTSG/GZMH/GZMK/TPSG1/MMP19/PCSK2/F10/MASP1/F12/CTSV/MMP13/C1R/MMP10/KLK6/TPSAB1/C1S/MMP1/TPSB2/GZMM/ELANE/CFD
FALSE GO:0008236 LTF/NAALAD2/MMP2/CMA1/TPSD1/MMP11/ACR/CTSG/GZMH/CPVL/GZMK/TPSG1/MMP19/PCSK2/F10/MASP1/F12/CTSV/MMP13/C1R/MMP10/KLK6/TPSAB1/C1S/MMP1/TPSB2/GZMM/ELANE/CFD
FALSE Count
FALSE GO:0001968 13
FALSE GO:0004222 25
FALSE GO:0008237 34
FALSE GO:0004252 27
FALSE GO:0008236 29
<- 1:2
num <- bngeneplot(pathSubGO,
bnCovGO
vstedTCGA,pathNum=num,
algo="hc",
expSample=rownames(metadata),
otherVar=metadata,
R=300, layout="sugiyama",
otherVarName=c("Age","Category"),
cl=parallel::makeCluster(10),
returnNet=TRUE)
$av$nodes$Category bnCovGO
FALSE $mb
FALSE [1] "CCDC80"
FALSE
FALSE $nbr
FALSE [1] "CCDC80"
FALSE
FALSE $parents
FALSE character(0)
FALSE
FALSE $children
FALSE [1] "CCDC80"
<- bn.fit(bnCovGO$av, bnCovGO$df)
bnGeneCovGOFit
<- cpdist(bnGeneCovGOFit, nodes=c(candGene), evidence=(Category==0), method="ls")
mz <- cpdist(bnGeneCovGOFit, nodes=c(candGene), evidence=(Category==1), method="ls")
mo <- cpdist(bnGeneCovGOFit, nodes=c(candGene), evidence=(Category==2), method="ls")
mt
= data.frame(
effect val = c(mz[,1], mo[,1], mt[,1]),
stage = c(rep("0",nrow(mz)), rep("1", nrow(mo)), rep("2", nrow(mt)))
)
<- effect %>% group_by(stage) %>% summarise(mean=mean(val))
disMean <- paste0(disMean$stage, " (mean=", round(disMean$mean,3), ")")
stageWMean $stageLabel <- c(rep(stageWMean[1],nrow(mz)), rep(stageWMean[2], nrow(mo)), rep(stageWMean[3], nrow(mt)))
effect
ggplot(effect, aes(x=val, y=stage, color=stageLabel, fill=stageLabel)) +
scale_color_manual(values=c("steelblue","gold","tomato")) +
scale_fill_manual(values=c("steelblue","gold","tomato")) +
stat_dotsinterval() + theme_bw() + ggtitle(candGene) + labs(caption=paste(pathSubGO@result$Description[num], collapse="\n"))
5.6 Investigating the network based on the clinical question
After confirming the knowledge, it is interesting to test how difference in clinical variables affect gene expression. bnlearn
can naturally handle this again using cpdist
. We now include two more variables, age_at_diagnosis
, gender
, paper_Noninvasive.bladder.cancer.therapy
, paper_Combined.T.and.LN.category
. Inference based on these information, we can ask:
Which genes have the biggest expression differences between those treated with BCG and with none, considering the networks of genes and clinical variables of age, gender, tumor category in TCGA-BLCA dataset using genes significantly differed in GSE133624 and involved in curated biological pathways related to MMP2?
## Subset to significant pathways, and those related to MMP2
@result <- subset(pway@result, p.adjust<0.05)
pway<- obtainPath(pway, "MMP2")
pathSub
<- bngeneplot(pathSub,
bnCovGene3
vstedBCG,pathNum = seq_len(nrow(pathSub)),
expSample=rownames(metadata),
otherVar=metadata,
hub=5, R=50,
otherVarName=c("Age","Gender","Therapy","Category"),
cl=parallel::makeCluster(10),
returnNet=T)
<- bn.fit(bnCovGene3$av, bnCovGene3$df)
bnCovGene3Fit
<- names(bnCovGene3$av$nodes)
allGenes <- allGenes[!allGenes %in% c("Age","Gender","Therapy","Category")]
allGenes <- cpdist(bnCovGene3Fit, nodes=allGenes, evidence=(Therapy=="none"), method="ls")
no <- cpdist(bnCovGene3Fit, nodes=allGenes, evidence=(Therapy=="Bacillus Calmette.Guerin (BCG)"), method="ls")
bcg
<- data.frame(apply(bcg, 2, mean)-apply(no, 2, mean))
difMean $name <- rownames(difMean)
difMeancolnames(difMean) <- c("difference","name")
<- difMean[order(abs(difMean$difference), decreasing=T),]
difMean kable(head(difMean, n=5))
difference | name | |
---|---|---|
COL25A1 | 0.2344216 | COL25A1 |
MFAP5 | 0.1834830 | MFAP5 |
COL11A1 | 0.1494830 | COL11A1 |
COL10A1 | 0.1381034 | COL10A1 |
LAMC2 | -0.1340511 | LAMC2 |
5.7 Classification using BN
Inferred BN can be used as a classifier of conditions. In this analysis, we perform the classification of whether the cancer samples are harboring TP53 mutation or not (column paper_mutation in TP53
). First, we make a metadata table as same as the above examples.
<- data.frame(tcgaData@colData) %>%
metadata ::select(age_at_diagnosis, gender, paper_mutation.in.TP53, paper_Combined.T.and.LN.category) %>% na.omit() %>%
dplyrfilter(paper_mutation.in.TP53!="ND") %>%
filter(paper_Combined.T.and.LN.category!="ND")
table(metadata$paper_mutation.in.TP53)
FALSE
FALSE no yes
FALSE 184 163
## Set TP53 status to numeric of 0/1.
$paper_mutation.in.TP53 <- as.numeric(as.factor(metadata$paper_mutation.in.TP53))-1
metadata$age_at_diagnosis <- as.numeric(scale(metadata$age_at_diagnosis))
metadata$paper_Combined.T.and.LN.category <- as.factor(metadata$paper_Combined.T.and.LN.category)
metadata$gender <- as.factor(metadata$gender) metadata
Split the data to train/test according to TP53 mutation status using caret
(Kuhn 2008). In this analysis, the five-fold cross validation (stratified) is performed. Fit the model using the expression of genes in the pathway. This time the classification performance of significant pathways (corrected p < 1e-5
) are to be compared. onlyDf
option can be enabled to return only the data.frame containing data for prediction, useful for testing purpose, and using the resulting data for the other softwares.
set.seed(53) # Seed for split
<- caret::createFolds(factor(metadata$paper_mutation.in.TP53), k = 5, list = TRUE, returnTrain=TRUE)
trainIndex <- list() ## Store network in the list
allnets <- list() ## Store prediction in the list
allClassRes
## Already VSTed DF
load("trainDf.rda")
load("testDf.rda")
for (f in seq_len(5)) {
<- list()
nets <- list()
classRes <- trainIndex[[f]]
foldTrainIndex ## Recursively fit and test for significant pathways
for (pnum in seq(1, dim(subset(pway@result, p.adjust<1e-5))[1], 1)) {
<- parallel::makeCluster(12)
cl <- bngeneplot(pway, assay(trainDf[[f]]), pathNum=pnum, layout="sugiyama",
bnCovTrain expSample=rownames(metadata[foldTrainIndex,]), algo="hc", strType="normal",
otherVar=metadata[foldTrainIndex,], otherVarName=c("Age","Gender","TP53","Category"),
R=50, cl=cl, returnNet=T)
## Return only DF for testing
<- bngeneplot(pway, assay(testDf[[f]]), pathNum=pnum,
bnCovTest expSample=rownames(metadata[-foldTrainIndex,]),
otherVar=metadata[-foldTrainIndex,], otherVarName=c("Age","Gender","TP53","Category"),
onlyDf=T)
## If DAG and TP53 have parents
if ( igraph::is.dag(bnlearn::as.igraph(bnCovTrain$av)) && length(bnCovTrain$av$nodes$TP53$parents) >= 1 ){
<- bnlearn::bn.fit(bnCovTrain$av, bnCovTrain$df)
bnCovLargeFit <- sigmoid::sigmoid(predict(bnCovLargeFit, node="TP53", data=bnCovTest, method = "bayes-lw")) # Use sigmoid function
pred @result$Description[pnum]]] <- pred
classRes[[pway@result$Description[pnum]]] <- bnCovTrain
nets[[pwayelse {
} message(paste0("Among pathway ", pway@result$Description[pnum], ", no parent node of TP53 is found, or inferred network is not dag."))
}::stopCluster(cl)
parallel
}<- nets
allnets[[f]] <- classRes
allClassRes[[f]] }
Using the library pROC
, calculate the area under ROC (auROC) (Robin et al. 2011).
library(pROC)
library(ggplotify)
<- c()
rocDf <- list()
allRocList for (f in seq_len(5)) {
<- metadata[-trainIndex[[f]],]$paper_mutation.in.TP53
correct <- data.frame(allClassRes[[f]])
predDf $label <- correct
predDf
<- list()
rocList for (i in seq_len(dim(predDf)[2]-1)){
names(predDf)[i]]] <- roc(predDf$label, predDf[,i], ci=TRUE, direction="<") # check direction
rocList[[
}<- data.frame(t(data.frame(purrr::map(rocList, function(x) as.numeric(x$auc)))))
tmpRocDf colnames(tmpRocDf) <- c(paste0("auc",f))
$name <- rownames(tmpRocDf)
tmpRocDf<- tmpRocDf
allRocList[[f]]
}
<- allRocList %>%
allRocListDf ::reduce(left_join, by = "name")
purrr
<- allRocListDf %>%
rocMean rowwise() %>%
mutate(Min = min(c_across(starts_with("auc")), na.rm=T),
Max = max(c_across(starts_with("auc")), na.rm=T),
Mean = mean(c_across(starts_with("auc")), na.rm=T),
Sd = sd(c_across(starts_with("auc")), na.rm=T)) %>%
select(name ,Mean, Sd) %>%
arrange(desc(Mean))
kable(rocMean, row.names=FALSE, booktab=TRUE) %>%
kable_styling(font_size = 10)
name | Mean | Sd |
---|---|---|
DNA.strand.elongation | 0.7586171 | 0.0476902 |
S.Phase | 0.7442158 | 0.0417892 |
RHO.GTPases.Activate.Formins | 0.7361936 | 0.0372955 |
Activation.of.ATR.in.response.to.replication.stress | 0.7313293 | 0.0309443 |
Amplification..of.signal.from.unattached..kinetochores.via.a.MAD2..inhibitory.signal | 0.7298620 | 0.0356467 |
Resolution.of.Sister.Chromatid.Cohesion | 0.7245308 | 0.0627438 |
Homologous.DNA.Pairing.and.Strand.Exchange | 0.7236192 | 0.0361203 |
HDR.through.Homologous.Recombination..HRR. | 0.7108159 | 0.0408204 |
EML4.and.NUDC.in.mitotic.spindle.formation | 0.6847067 | 0.0969711 |
Mitotic.Spindle.Checkpoint | 0.6727978 | 0.0843631 |
Separation.of.Sister.Chromatids | 0.5731690 | 0.1567807 |
Show the resulting network with the top auROC, and the ROC plot using pROC
(Robin et al. 2011).
<- rocMean[1,"name"]
topPath <- as.numeric(allRocListDf %>% filter(name == as.character(topPath)) %>% summarize(which.max(c_across(starts_with("auc")))))
candFold
## With the CI
<- data.frame(metadata[-trainIndex[[candFold]],]$paper_mutation.in.TP53)
candRoc colnames(candRoc) <- c("label")
$pred <- as.numeric(unlist(allClassRes[[candFold]][gsub("[.]", " ", as.character(topPath))]))
candRoc
<- plot.roc(candRoc$label, candRoc$pred, print.auc = TRUE, ci=TRUE, col="black", direction="<",
rocobj1 main = "Mutation in TP53", percent=TRUE)
<- ci.se(rocobj1, specificities = seq(0, 100, 5), progress="none")
ciobj plot(ciobj, type = "shape", col = "steelblue")
## Along with the network
<- allnets[[candFold]][[gsub("[.]", " ", topPath)]]
topNet $plot topNet
Using bnlearn::cpdist
, check the difference in the distribution mean when the value of the node TP53 is above and below 0.5.
<- bnlearn::bn.fit(topNet$av, topNet$df)
topFit
<- names(topNet$av$nodes)
candNodes <- candNodes[!candNodes %in% c("TP53","Category","Gender")]
candNodes
<- cpdist(topFit, nodes=candNodes, evidence=(TP53 < 0.5))
tp53low dim(tp53low)
FALSE [1] 5225 21
<- cpdist(topFit, nodes=candNodes, evidence=(TP53 > 0.5))
tp53high dim(tp53high)
FALSE [1] 4717 21
<- apply(tp53high, 2, mean) - apply(tp53low, 2, mean)
difMeanTp53 kable(head(difMeanTp53[order(abs(difMeanTp53), decreasing=T)]), col.names=c("difference"))
difference | |
---|---|
MCM2 | 0.3978904 |
RFC4 | 0.3534718 |
MCM8 | 0.3250150 |
PRIM1 | 0.3243060 |
PRIM2 | 0.3031842 |
GINS4 | 0.2868035 |
<- topNet$plot$data
changeCol <- difMeanTp53[changeCol$name]
difMeanTp53 names(difMeanTp53) <- changeCol$name
$color <- difMeanTp53
changeCol
## Replace shape and color
$plot$data <- changeCol
topNet$plot + scale_color_continuous(low="blue",high="red",name="difference") topNet
When the TP53 takes the extreme values on logic sampling.
<- bnlearn::bn.fit(topNet$av, topNet$df)
topFit
<- names(topNet$av$nodes)
candNodes <- candNodes[!candNodes %in% c("TP53","Category","Gender")]
candNodes
<- cpdist(topFit, nodes=candNodes, evidence=(TP53 < 0.01))
tp53low dim(tp53low)
FALSE [1] 1760 21
<- cpdist(topFit, nodes=candNodes, evidence=(TP53 > 0.99))
tp53high dim(tp53high)
FALSE [1] 1552 21
<- apply(tp53high, 2, mean) - apply(tp53low, 2, mean)
difMeanTp53 kable(head(difMeanTp53[order(abs(difMeanTp53), decreasing=T)]), col.names=c("difference"))
difference | |
---|---|
MCM2 | 0.7375946 |
RFC4 | 0.6955627 |
MCM8 | 0.5989058 |
PRIM1 | 0.5895650 |
PRIM2 | 0.5783348 |
GINS1 | 0.4874811 |
<- topNet$plot$data
changeCol <- difMeanTp53[changeCol$name]
difMeanTp53 names(difMeanTp53) <- changeCol$name
$color <- difMeanTp53
changeCol
## Replace shape and color
$plot$data <- changeCol
topNet$plot + scale_color_continuous(low="blue",high="red",name="difference") topNet
Perform likelihood weighting.
<- cpdist(topFit, nodes=candNodes, evidence=list(TP53 = 0), method="lw")
tp53low <- cpdist(topFit, nodes=candNodes, evidence=list(TP53 = 1), method="lw")
tp53high
<- apply(tp53high, 2, function(x) weighted.mean(x, attributes(tp53high)$weights)) - apply(tp53low, 2, function(x) weighted.mean(x, attributes(tp53low)$weights))
difMeanTp53
<- topNet$plot$data
changeCol <- difMeanTp53[changeCol$name]
difMeanTp53
kable(head(difMeanTp53[order(abs(difMeanTp53), decreasing=T)]), col.names=c("difference"))
difference | |
---|---|
MCM2 | 0.5113805 |
RFC4 | 0.4569469 |
MCM8 | 0.4353333 |
PRIM1 | 0.4136929 |
PRIM2 | 0.3935092 |
GINS1 | 0.3680252 |
names(difMeanTp53) <- changeCol$name
$color <- difMeanTp53
changeCol
## Replace shape and color
$plot$data <- changeCol
topNet$plot + scale_color_continuous(low="blue",high="red",name="difference") topNet
queryCpDistLw
function performs sampling by likelihood weighting using cpdist, and returns the data.frame with weights. It just performs cpdist
on the queried level and produce a plot. queryCpDistLs
performs logic sampling.
## Only likelihood weighting is supported in queryCpDist.
<- queryCpDistLw(topFit, names(difMeanTp53)[1], evidence="TP53", level=c(0,0.5,1))
q1 kable(head(q1$df[,c(names(difMeanTp53)[1],"weights")]))
RFC2 | weights |
---|---|
11.29786 | 0.8774882 |
10.16672 | 0.3570390 |
10.30900 | 0.2065809 |
10.82745 | 0.8837212 |
10.36271 | 0.8340634 |
10.50688 | 0.7633695 |