ronikobrosly / causal-curve

A python package with tools to perform causal inference using observational data when the treatment of interest is continuous.
MIT License
271 stars 18 forks source link

External vector of GPS #42

Open athammad opened 2 years ago

athammad commented 2 years ago

Hi guys,

It seems to me that the GPS is calculated internally. What if I have a vector with the GPS (calculated using my own code) and I would like to "plug it" into the model to estimate the DRF?

Thank you very much.

ronikobrosly commented 2 years ago

Hi @athammad ! You are correct, it is calculated internally, but I believe you should be able to substitute in your estimates of GPS values here: https://github.com/ronikobrosly/causal-curve/blob/bb9dab9362bbf88aef42967d023ed9ceee3672fd/causal_curve/gps_core.py#L462

That is, after you run the ‘fit’ function you can do something like this

‘gps.gps_at_grid = [your array of your own GPS values at the treatment grid points]’

… and then you can calculate the CDRC as usual. Does that make sense?

athammad commented 2 years ago

HI @ronikobrosly! Thank you for getting back to me. What do you mean by "GPS values at the treatment grid points"? I have a vector with the calculated GPS for every observation in my Dataframe. Are you suggesting that I should recalculate the GPS with a multinomial regression after creating a quantile-based grid across the values of the treatment equivalent to the one I would have to select in GPS_Regressor(treatment_grid_num = 100)?

Best wishes

ronikobrosly commented 2 years ago

Thinking about this a bit more, I think there is a simpler approach here that will save you time @athammad . If you already have an estimate of the GPS for each observation, then you really dont even need this package: you can estimate the CDRC directly using the treatment values, GPS values, and outcome values. See the methods section of this paper for more details: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5969262/

Specifically the section “ 2.3. Estimation of the dose‐response function using the GPS”.

ronikobrosly commented 2 years ago

Probably easier than adapting the package to fit your GPS, if that makes sense