1 year ago
#361546
jk00010
Is there a way to subset data for Python statsmodels .get_margeff() like in R margins()?
I created a model using mnlogit() from statsmodels that looks something similar to this:
formula = "Switch_Variable ~ Prior_Complication_categ * C(Prior_Delivery_Type) +
C(RaceName) + C(EthnicityName) + AgeInYears + C(Insurance) +
TotalScore + Mortality_Score + Readmission_Score + num_deliveries" logmodel = smf.mnlogit(formula, data=analysis2_lagged).fit()
I know that you can use logmodel.getmargeff() to get marginal effects for the model. There is atexog parameter that allows you to get marginal effects for counterfactual dataset, where it changes the value of whatever variable you put into atexog for all observations and estimates the marginal effects based on that.
Instead, I wonder whether I could get marginal effects for a subset of data (such as dataset for Prior_Delivery_Type = 1). I know that R margins() allows you to subset data within the margins() function directly (details here).
If there is no such feature in statsmodels, is there a workaround without using R? Any help would be appreciated!
python
subset
logistic-regression
statsmodels
marginal-effects
0 Answers
Your Answer