`as.matrix.projection()` for GAMs: Duplicated linear term
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 114
- Forks
- 31
- PR merge metrics
- No merged PRs in 30d
Description
On branch develop (commit 96d8e11d6f0ad0a1f7836c51700cb676b364bee5), this reprex:
options(mc.cores = parallel::detectCores(logical = FALSE))
data("kidiq", package = "rstanarm")
kidiq <- head(kidiq, 45)
fit_gauss <- rstanarm::stan_gamm4(
kid_score ~ s(mom_iq),
data = kidiq,
iter = 500,
seed = 734572
)
library(projpred)
prj <- project(fit_gauss, solution_terms = c("mom_iq", "s(mom_iq)"),
ndraws = 25)
colnames(as.matrix(prj))
gives
[1] "b_Intercept" "b_mom_iq" "b_s(mom_iq).1" "b_s(mom_iq).2"
[5] "b_s(mom_iq).3" "b_s(mom_iq).4" "b_s(mom_iq).5" "b_s(mom_iq).6"
[9] "b_s(mom_iq).7" "b_s(mom_iq).8" "b_s(mom_iq).9" "sigma"
(so the output matrix includes a linear term for the smoothed predictor) whereas
colnames(as.matrix(fit_gauss))
(correctly) gives
[1] "(Intercept)" "s(mom_iq).1"
[3] "s(mom_iq).2" "s(mom_iq).3"
[5] "s(mom_iq).4" "s(mom_iq).5"
[7] "s(mom_iq).6" "s(mom_iq).7"
[9] "s(mom_iq).8" "s(mom_iq).9"
[11] "sigma" "smooth_sd[s(mom_iq)1]"
[13] "smooth_sd[s(mom_iq)2]"
Perhaps the problem is not really with as.matrix.projection(), but rather with project() which would need to project onto the submodel with the smoothed term only (and not an additional linear term), even if solution_terms = c("mom_iq", "s(mom_iq)")?
There's another issue with as.matrix.projection() for GAMs visible here (the smooth_sd parameters) which I'll open a new issue for.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the provided GAM example on the stated develop commit, then compare colnames(as.matrix(prj)) with colnames(as.matrix(fit_gauss)). Inspect project() and as.matrix.projection() to determine whether the duplicated linear term comes from projection or matrix conversion. Done means the expected smooth-term-only behavior is established and the returned matrix no longer includes an unintended linear term.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100