Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GAM interaction demo code no longer runs #8

Open
aolney opened this issue Mar 22, 2018 · 0 comments
Open

GAM interaction demo code no longer runs #8

aolney opened this issue Mar 22, 2018 · 0 comments

Comments

@aolney
Copy link

aolney commented Mar 22, 2018

The demo for code here for gam interactions no longer runs and gives error "Error in predict.gam(new.fit.Y, type = "response", newdata = pred.data.t) : 0 not in original fit". This appears to be an error that happens when predict.gam is given unknown factor levels.

Strangely if I comment out control as below it runs or if I set "control=treat" it runs. However I get different results in with these two methods. The commenting out method gives a summary result that is closer to the old vignette:

model.m <- lm(job_seek ~ treat + depress1 + econ_hard + sex + age + occp + marital
                 + nonwhite + educ + income, data = jobs)

model.y <- gam(depress2 ~ treat + s(job_seek, by = treat) + s(job_seek, by = control)
               + depress1 + econ_hard + sex + age + occp + marital + nonwhite + educ + income,
               data = jobs)

out.5 <- mediation::mediate(model.m, model.y, sims = 1000, boot = TRUE,
                            treat = "treat", mediator = "job_seek",
                            #control = "control"
                       )
summary(out.5)

However the result isn't close enough for me to feel confident that this is correct (e.g. within .01).

Both the paper referenced in mediate's documentation for gam and the old vignette imply that the by variables should be indicator variables. The current jobs data does not have this form: treat is binary but control is a factor. If I create a new variable jobs$control.1 <- 1 - jobs$treat I can then set the by options sensibly, but again I don't get the values from the old vignette. I've also tried just using the spline by factor control since the gam documentation suggests that creates an interaction by itself anyways. Altogether I've explored a number of alternatives, and the closest to the old vignette seems to be the "comment out control" listing above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant