R Wrapper for Tetrad Library
R >= 3.2.0, stringr, rJava, graph, [RBGL] (http://bioconductor.org/packages/release/bioc/html/RBGL.html), [Rgraphviz] (http://bioconductor.org/packages/release/bioc/html/Rgraphviz.html)
- Install the R library requirements:
install.packages("stringr")
install.packages("rJava")
## try http:// if https:// URLs are not supported
source("https://bioconductor.org/biocLite.R")
biocLite("graph")
biocLite("RBGL")
biocLite("Rgraphviz") # For plotting graph
- Install r-causal from github:
library(devtools)
install_github("bd2kccd/r-causal")
library(rcausal)
data("charity") #Load the charity dataset
#Compute FGES search
fges <- fges(df = charity, penaltydiscount = 2, maxDegree = -1,
faithfulnessAssumed = TRUE, numOfThreads = 2, verbose = TRUE)
fges$parameters #Show the FGES's parameters
fges$datasets #Show the dataset
fges$nodes #Show the result's nodes
fges$edges #Show the result's edges
library(Rgraphviz)
plot(fges$graphNEL) #Plot the causal model
library(rcausal)
data("audiology") #Load the charity dataset
#Compute FGES search
fges.discrete <- fges.discrete(df=audiology,structurePrior=1.0,samplePrior=1.0,
maxDegree = -1, faithfulnessAssumed = TRUE, numOfThreads = 2,verbose = TRUE)
fges.discrete$parameters #Show the FGES Discrete's parameters
fges.discrete$datasets #Show the dataset
fges.discrete$nodes #Show the result's nodes
fges.discrete$edges #Show the result's edges
library(Rgraphviz)
plot(fges.discrete$graphNEL) #Plot the causal model
forbid <- list(c('TangibilityCondition','Impact')) # List of forbidden directed edges
require <- list(c('Sympathy','TangibilityCondition')) # List of required directed edges
forbiddenWithin <- c('TangibilityCondition','Imaginability')
class(forbiddenWithin) <- 'forbiddenWithin' # Make this tier forbidden within
temporal <- list(forbiddenWithin, c('Sympathy','AmountDonated'),c('Impact')) # List of temporal node tiers
prior <- priorKnowledge(forbiddirect = forbid, requiredirect = require, addtemporal = temporal)
fges <- fges(df = charity, penaltydiscount = 2, depth = -1, ignoreLinearDependence = TRUE,
heuristicSpeedup = TRUE, numOfThreads = 2, verbose = TRUE, priorKnowledge = prior)
# knowledge file: audiology.prior
# /knowledge
# forbiddirect
# class tymp
# class age_gt_60
# class notch_at_4k
#
# requiredirect
# history_noise class
#
# addtemporal
# 0* bser late_wave_poor tymp notch_at_4k o_ar_c ar_c airBoneGap air bone o_ar_u airBoneGap
# 1 history_noise history_dizziness history_buzzing history_roaring history_recruitment history_fluctuating history_heredity history_nausea
# 2 class
prior <- priorKnowledgeFromFile('audiology.prior')
fges.discrete <- fges.discrete(df=audiology,structurePrior=1.0,samplePrior=1.0,
depth = -1, heuristicSpeedup = TRUE, numOfThreads = 2,verbose = TRUE, priorKnowledge = prior)
library(igraph)
igraph <- igraph.from.graphNEL(fges.discrete$graphNEL)
plot(igraph)