Skip to content

as.matrix.projection() for GAMs: Duplicated linear term #150

Open
@fweber144

Description

@fweber144

On branch develop (commit 96d8e11), 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    additiveIssues concerning additive models (GAMs and GAMMs).questionOpen questions.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions