dowhy
dowhy copied to clipboard
Mediation Analysis key error
Hi,
when trying to name nodes in the graph with some expressive names I found out that this is currently not possible when initiating mediation analysis.
For example: having the following graph structure gml
graph_gml = """graph[directed 1 node[id "v0" label "v0"] node[id "FD0" label "FD0"] node[id "behavior" label "behavior"] edge[source "v0" target "FD0"] edge[source "v0" target "behavior"] edge[source "FD0" target "behavior"]] """
with the mediation model
model_mediation = CausalModel( data=df, treatment='v0', outcome='behavior', graph=graph_gml )
model_mediation.estimate_effect(...) raises the following key error: KeyError: 'b'
It seems that the outcome_name checks only for the first letter of the original graph outcome node 'behavior'
BR Michael
That's odd and should not be happening. I will check this---thanks for raising it @mijantscher.
Btw, one reason this could be happening is because internal methods process treatment and outcome as arrays. Can you try inputting the outcome as an array,
model_mediation = CausalModel( data=df, treatment='v0', outcome=['behavior'], graph=graph_gml )
In any case, I will look into it.
Inputting the outcome as an array yields to the same error output
@mijantscher There was an error in the estimation code for frontdoor/mediation. Fixed it now in master.
You can install the latest version using git clone and then using pip install -e dowhy to install dowhy from your local filesystem.
Hope this works!
It will be updated in the new release in January.