dowhy icon indicating copy to clipboard operation
dowhy copied to clipboard

Mediation Analysis key error

Open mijantscher opened this issue 4 years ago • 3 comments

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

mijantscher avatar Dec 14 '20 08:12 mijantscher

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.

amit-sharma avatar Dec 14 '20 17:12 amit-sharma

Inputting the outcome as an array yields to the same error output

mijantscher avatar Dec 15 '20 14:12 mijantscher

@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.

amit-sharma avatar Dec 20 '20 17:12 amit-sharma