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

derivatives can't handle by variable smooths #47

Closed
bart-larsen opened this issue Sep 6, 2019 · 3 comments
Closed

derivatives can't handle by variable smooths #47

bart-larsen opened this issue Sep 6, 2019 · 3 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@bart-larsen
Copy link

I really like the derivatives function, but I have been running into this issue.
The issue occurs whether I use ordered or unordered factors in the by-factor smooths. I have been mostly testing this with gamm, but it seems to not work for gam either.
For example:

modobj <- gamm(y ~ s(age,by = sex),random=list(ID=~1)
df <- derivatives(modobj,'age)

This returns the derivative for the first level of the by factor smooth, but returns all zeros for the derivative and standard error for the next level.

If I run this in the ordered factor case to test for interactions,
modobj <- gamm(y ~ s(age) +oSex + s(age,by = oSex),random=list(ID=~1)
df <- derivatives(modobj,'age)

It returns the derivative for the reference smooth (s(age)), but all zeros for the derivative and standard error of the by factor smooth.

@gavinsimpson gavinsimpson self-assigned this Sep 10, 2019
@gavinsimpson gavinsimpson added bug Something isn't working enhancement New feature or request labels Sep 10, 2019
@gavinsimpson
Copy link
Owner

gavinsimpson commented Sep 12, 2019

Here's a reproducible example using gam()

set.seed(1)
dat <- gamSim(4, n = 400, verbose = FALSE)
m <- gam(y ~ fac + s(x2, by = fac), data = dat)
d <- derivatives(m)
draw(d) # clearly shows the problem

and another one for testing

m2 <- gam(y ~ x1 + s(x2) + fac + s(x0, by = fac), data = dat)

and another one for testing, this time ordered factor

dat <- transform(dat, ofac = ordered(fac))
m3 <- gam(y ~ x1 + s(x2) + ofac + s(x0) + s(x0, by = ofac), data = dat)

@gavinsimpson
Copy link
Owner

An immediate issue is that derivative_data() is only returning data for the first level of the factor. This needs fixing.

@gavinsimpson
Copy link
Owner

This is now working for both ordered and ordinary factor by smooths for gam() and gamm() models.

Thanks for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants