Note 2023--4-1: This version of RCausal uses an older version of Tetrad from at least 5 years ago. We have updated our Python integration to the most recent version of Tetrad in a separste project--see rpy-tetrad.
R-causal has not been maintained for some time now, as the tireless maintainer has since moved on to different work :-)... but going back through some of the issues posted for r-causal gives some hints as to additional functionality that pytetrad/R should have. We'll try to get caught up.
NEWS 2024-09-05: We are working on a new wrapping of Tetrad using rJava; please see r-tetrad. This will be a standalong implementation that requires only R to be installed; the JDK and Tetrad jars used will be downloaded programmatically by the R scripts.
R Wrapper for Tetrad Library
- Install the R library requirements:
install.packages("stringr")
install.packages("rJava")
- Install r-causal from github:
library(devtools)
install_github("bd2kccd/r-causal")
library(rcausal)
data("charity") #Load the charity dataset
tetradrunner.getAlgorithmDescription(algoId = 'fges')
#Compute FGES search
tetradrunner <- tetradrunner(algoId = 'fges',df = charity,scoreId = 'sem-bic',
dataType = 'continuous',faithfulnessAssumed=TRUE,maxDegree=-1,verbose=TRUE)
tetradrunner$nodes #Show the result's nodes
tetradrunner$edges #Show the result's edges
graph <- tetradrunner$graph
graph$getAttribute('BIC')
nodes <- graph$getNodes()
for(i in 0:as.integer(nodes$size()-1)){
node <- nodes$get(i)
cat(node$getName(),": ",node$getAttribute('BIC'),"\n")
}
library(rcausal)
data("audiology") #Load the charity dataset
#Compute FGES search
tetradrunner <- tetradrunner(algoId = 'fges',df = audiology,scoreId = 'cg-bic-score',dataType = 'discrete',
faithfulnessAssumed=TRUE,maxDegree=-1,verbose=TRUE)
tetradrunner$nodes #Show the result's nodes
tetradrunner$edges #Show the result's edges
graph <- tetradrunner$graph
graph$getAttribute('BIC')
nodes <- graph$getNodes()
for(i in 0:as.integer(nodes$size()-1)){
node <- nodes$get(i)
cat(node$getName(),": ",node$getAttribute('BIC'),"\n")
}
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)
tetradrunner <- tetradrunner(algoId = 'fges',df = charity,scoreId = 'fisher-z',
dataType = 'continuous',alpha=0.1,faithfulnessAssumed=TRUE,maxDegree=-1,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')
tetradrunner <- tetradrunner(algoId = 'fges',df = audiology,scoreId = 'bdeu',dataType = 'discrete',
alpha=0.1,faithfulnessAssumed=TRUE,maxDegree=-1,verbose=TRUE, priorKnowledge = prior)
library(DOT)
graph_dot <- tetradrunner.tetradGraphToDot(tetradrunner$graph)
dot(graph_dot)