0

Im trying to plot the marginal effect of non wife income (nwifeinc) across the range of non-wife income, holding the values of other variables fixed at their sample means. holding is the logistic regression I made. But I dont know what function I should use other than dlogis to get a graph. Also, there is an error for object of type 'closure' is not subsettable. So, there aren't any points on my graph. Sorry if that is confusing.

h1<-rep(0,nrow(mroz))
for(i in 1:nrow(mroz)){
  holding<-{
    logit <- glm(inlf ~ nwifeinc + educ + age + exper +
                   kidsge6 + kidslt6 +unem+ city,
                 data = sample, family = binomial(link="logit"))
    X <- sample %>% select(nwifeinc, educ, age, exper, kidslt6, kidsge6, unem, city)
    ones <- rep(1, nrow(X))
    X <- cbind(ones, X)
    X_means <- colMeans(X)
    betas <- logit$coefficients
    linear_part <- X_means %*% betas
    PEA <- logit$coefficients[2] * (exp(linear_part)/((1 + exp(linear_part))^2))
  }
  h1[i]<-dlogis(holding)*data$nwifeinc[i]
}

h1_df<-as.data.frame(h1)
ggplot(data=h1_df, aes(x=h1))+
  geom_density()+
  xlab("Marginal Effect of Non Wife Income")+
  ylab("")

Phil
  • 7,287
  • 3
  • 36
  • 66
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. My guess is this is a typo. Maybe the problem is `data$nwifeinc`. Do you have `data` defined anywhere? I don't see that in your code. Your data seems to be named `sample` – MrFlick Nov 11 '20 at 05:29
  • [edit] the question to include the complete error message . – IRTFM Nov 11 '20 at 05:57

0 Answers0