Open
Description
Applying as.matrix()
to a GAMM projection does not work:
# Source: Example section of `?rstanarm::stan_gamm4`.
library(projpred)
library(rstanarm)
options(mc.cores = parallel::detectCores(logical = FALSE))
dat <- mgcv::gamSim(1, n = 400, scale = 2) ## simulate 4 term additive truth
## Now add 20 level random effect`fac'...
dat$fac <- fac <- as.factor(sample(1:20, 400, replace = TRUE))
dat$y <- dat$y + model.matrix(~ fac - 1) %*% rnorm(20) * .5
br <- stan_gamm4(y ~ s(x0) + x1 + s(x2), data = dat, random = ~ (1 | fac),
chains = 1,
iter = 500, # for example speed
seed = 1140350788)
myproj <- project(br,
solution_terms = c("x1", "s(x2)", "(1 | fac)"),
nclusters = 2)
myprjmat <- as.matrix(myproj)
On branch develop
(for example), that last line raises the following error:
Error in names(population_effects) <- replace_intercept_name(names(population_effects)) :
attempt to set an attribute on NULL
The issue is probably that as.matrix.lm()
(which is used for submodels of class "gamm4"
) uses coef()
which in turn is NULL
for objects of class "gamm4"
:
coef(myproj$sub_fit[[1]])
## --> NULL
So for submodels of class "gamm4"
, the as.matrix.lm()
method probably can't be used.