jtextor / dagitty

Graphical analysis of structural causal models / graphical causal models.
GNU General Public License v2.0
255 stars 47 forks source link

Enhanced JS function for DAG-to-lavaan syntax conversion #83

Closed GustavoGarciaPereira closed 8 months ago

GustavoGarciaPereira commented 8 months ago

motivation for the contribution: I was having to manually dictate the DAG code to convert to lavaan, so I decided to create a new session that provides me with the direct code I made for my own use. Then I decided to send it to someone who might find it useful.

two test cases:

image

dag:

dag {
A [selected,pos="-2.200,-1.520"]
B [pos="1.400,-1.460"]
D [outcome,pos="1.400,1.621"]
E [exposure,pos="-2.200,1.597"]
Z [adjusted,pos="-0.300,-0.082"]
A -> E
A -> Z [pos="-0.791,-1.045"]
B -> D
B -> Z [pos="0.680,-0.496"]
E -> D
}

lavaan:

E ~ A
Z ~ A
D ~ B
Z ~ B
D ~ E

image dag:

dag {
A [selected,pos="-2.200,-1.520"]
B [pos="1.400,-1.460"]
D [outcome,pos="1.400,1.621"]
E [exposure,pos="-2.200,1.597"]
Z [adjusted,pos="-0.300,-0.082"]
A -> E
A <-> Z
B -> D
B -> Z [pos="0.680,-0.496"]
E -> D
}

lavaan:

E ~ A
A ~~ Z
D ~ B
Z ~ B
D ~ E
jtextor commented 8 months ago

Hi, I appreciate the effort, but there is already a function in the dagitty Js library that converts to lavaan syntax:

console.log( GraphSerializer.toLavaan( Model.dag ) )

GustavoGarciaPereira commented 8 months ago

Ok, sorry for opening the PR for nothing. Thank you for responding, and I will continue watching the project so I can contribute in the future