-
Notifications
You must be signed in to change notification settings - Fork 28
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
smooth_estimates()
returns random smooths for levels on in the by
smooth
#311
Comments
Thanks @StefanoMezzini; I'll take a look at what's going wrong here, most likely is the special internal method use for |
Hmm @StefanoMezzini I can't reproduce this with a similar example. # Analyse the Rat hormone data from Fahrmeir et al (2013) Regression: Models,
# Methods and Applications. Springer
pkgs <- c("mgcv", "lme4", "ggplot2", "readr", "dplyr", "forcats", "tidyr",
"gratia")
# load data
vapply(pkgs, library, logical(1), character.only = TRUE, logical.return = TRUE,
quietly = TRUE)
rats_url <- "https://bit.ly/rat-hormone"
rats <- read_table(rats_url, col_types = "dddddddddddd-")
# ignore the warning - it"s due to trailing white space at the ends of each
# row in the file
rats <- rats |>
mutate(treatment = fct_recode(factor(group, levels = c(1, 2, 3)),
Low = "1",
High = "2",
Control = "3"),
treatment = fct_relevel(treatment, c("Control", "Low", "High")),
subject = factor(subject))
rats |>
na.omit() |>
count(subject) |>
count(n, name = "n_rats")
plt_labs <- labs(y = "Head height (distance in pixels)",
x = "Age in days",
colour = "Treatment")
ggplot(rats, aes(x = time, y = response,
group = subject, colour = treatment)) +
geom_point(size = 1) +
geom_line() +
facet_wrap(~ treatment, ncol = 3) +
plt_labs
K <- 7
# fit model
m <- bam(
response ~ treatment + s(time, subject, by = treatment, bs = "fs", k = 7),
discrete = TRUE, nthreads = 6
)
# plot
draw(m) Produces It looks like you are using a pretty old version of the package if you need to index the If I've misunderstood, can you show me the code you're using and the specific model you are fitting? |
Yes, I think I was using an old version because I don't have the issue after updating |
Thanks for confirming that the issue is fixed in the latest version @StefanoMezzini. |
Hi Gavin,
I have a dataset with control and treatment animals (
C_*
andT_*
, respectively). Plotting the partial effect ofs(doy, animal_year, by = group, bs = 'fs')
returns the random smooths for all levels for both groups rather than only the levels within each group. This results in unnecessary, flat smooth estimates with the sample-level CIs. (alpha
is 0.1 for allgeom_ribbon
s.)Cheers,
Stefano
The text was updated successfully, but these errors were encountered: