0

I ran my twopart model and I have tried following the but the margins and the AME commands to get the marginal effects on all the variables, but I am running into a really weird issue with the data frame for some reason.

> margin(tpmodel1)
Error in `[.data.frame`(newdata, , term) : undefined columns selected

But when looking at the guide for the twopm package, it says that all I need to do is just AME(tpmodel1) or margin(tpmodel1) to get all the marginal effects and it is still giving that error. so then i did

> margin(tpmodel1, newdata = NULL, term = NULL, se=TRUE)
Error in `[.data.frame`(newdata, , term) : undefined columns selected

And

 > margin(tpmodel1, newdata = dfasthma, term = NULL, se=TRUE)
Error in margin(tpmodel1, newdata = dfasthma, term = NULL, se = TRUE) : 

some of independent variables of the two-part model are not available in the newdata set

of which doesnt make sense cause The data set i created for the variables I am using is dfasthma.

the code from the package:

margin(object, newdata = NULL, term = NULL, value = NULL,
se = TRUE, se.method = c("delta","bootstrap"), CI = TRUE, CI.boots = FALSE,
level = 0.95,eps = 1e-7,na.action = na.pass, iter = 50)

The image attached is a guide to the margin command from the package

enter image description here

Phil
  • 7,287
  • 3
  • 36
  • 66
pika
  • 1
  • 1
    Welcome to Stack Overflow! Can you please read and incorporate elements from [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269/1082435). Especially the aspects of using `dput()` for the input and then an explicit example of your expected dataset? – wibeasley Dec 07 '22 at 00:46
  • @wibeasley have never used dput() function and I have no clue what it is. the example given in the package pdf is #fit two-part model with different regressors in both parts(This is formula i used for the 2 part regression) tpmodel = tpm(formula_part1 = exp_tot~female+age, formula_part2 = exp_tot~female+age+ed_colplus,data = meps,link_part1 = "logit", family_part2 = Gamma(link = "log")) tpmodel summary(tpmodel) ##Predictive margins and corresponding ratios for all variables with ##standard errors and CIs. margin(tpmodel) – pika Dec 07 '22 at 19:30
  • "...I have no clue what it is". I understand. The post I referenced explains `dput()` and other strategies to receive helpful responses on SO. – wibeasley Dec 08 '22 at 20:06

0 Answers0