########################################################### # An R script implements Bayesian network marker selection # based on the Thresholded Graph Laplacian Gaussian (TGLG) prior # # Authors: Qingpo Cai, Jian Kang and Tianwei Yu ########################################################### # clean up the working space (optional) rm(list=ls(all=TRUE)) # set up the working directory including TGLG_lib.R setwd("/Users/jiankang/Dropbox/Umich/People/jiankang/Rpackage/TGLG_R_Example/") ################################################################## # Please make sure you have installed the following packages # igraph, MCMCpack, pROC, glmnet, truncnorm, mvnfast ################################################################## #Load R functions for TGLG fiting source("TGLG_lib.R") # Toy Example for continuous outcome # Set seed set.seed(12152018) # Set graph net = TF_graph(nTarget = 5, nTF = 3) # plot graph plot(net) # get the number of nodes in the network p = vcount(net) # set sample size n = 100 # simulate network markers X = matrix(rnorm(n*p),nrow=n,ncol=p) # set the true beta beta = c(rep(c(1,-1),length=6),rep(0,length=p-6)) # simulate the outcome variable y = X%*%beta + matrix(rnorm(n),nrow=n,ncol=1) # fit the model for continuous outcome res = TGLG_continuous(X,y,net) # print the summary statistics print(res$post_summary) # compute the mse mse = mean((res$post_summary$betaEst-beta)^2) print(mse) # Toy Example for binary outcome y_binary = as.numeric(y>0) res_binary = TGLG_binary(X,y_binary,net) mse_binary = mean((res_binary$post_summary$betaEst-beta)^2) print(mse)