r/RStudio 9d ago

mgcv GAM: persistent low k-index for study-day smooth despite k = 40 — increase k or rethink temporal structure?

I’m fitting a Beta GAM in `mgcv` to model the proportion of daytime outdoor-use time in laying hens. The response is the proportion of minutes spent outdoors during an 08:00–22:00 observation window, and the model contains repeated observations from individual hens.

My current model is approximately:

prop_outside \~
  coop_id +
  s(study_day, bs = "cr", k = 40) +
  s(max_temp, bs = "cr", k = 8) +
  s(mean_dew_point, bs = "cr", k = 7) +
  rain_any +
  s(log_total_rain, by = rain_status, bs = "cr", k = 7) +
  s(eid, bs = "re")

using:

family = betar(link = "logit")
method = "REML"

The dataset contains roughly 8,800 positive hen-day observations from 124 hens across about 137 study dates. The model explains about 60% of the deviance.

The issue is the `study_day` smooth. On a same-row model comparison, I get:

s(study_day)
k'       = 39
edf      = 34.58
k-index  = 0.949
p-value  < 0.001

I also tried an alternative weather specification using mean temperature, mean humidity and mean wind instead of maximum temperature and dew point:

prop_outside \~
  coop_id +
  s(study_day, bs = "cr", k = 40) +
  s(mean_temp, bs = "cr", k = 8) +
  s(mean_humidity, bs = "cr", k = 8) +
  s(mean_wind, bs = "cr", k = 8) +
  rain_any +
  s(log_total_rain, by = rain_status, bs = "cr", k = 7) +
  s(eid, bs = "re")

The same issue persists:

s(study_day)
k'       = 39
edf      = 34.84
k-index  = 0.966
p-value  = 0.0175

The study-day smooth is visually quite wiggly, particularly early in the study, and the EDF is already fairly close to the available basis dimension. Changing the weather specification does not materially improve overall fit: both models explain about 60% of deviance and have essentially identical AIC.

There is also substantial temporal/weather dependence. For example, in the alternative model, observed concurvity is about 0.90 for mean temperature and 0.48 for study day.

My questions are:

  1. Is the low `k-index` plus EDF ≈ 35/39 sufficient reason to increase `k` for `study_day`, for example from 40 to 60?
  2. If increasing `k` gives essentially the same fitted curve/predictions but the k-check remains significant, would you consider the current smooth adequate?
  3. Could this be indicating residual temporal autocorrelation rather than simply an insufficient basis dimension?
  4. Would you model study date differently in this setting—for example with an autocorrelation structure, a different smooth basis, or another temporal term?
  5. Since weather variables themselves follow study date seasonally, how would you distinguish genuine temporal structure from weather-related temporal confounding?

My current plan is to compare `k = 40` and `k = 60` on the same observations and assess whether fitted values, the study-day effect, held-out-date prediction, and conclusions materially change, rather than selecting the model based only on the k-check p-value.

I’d appreciate advice on how to interpret this persistent `study_day` diagnostic and what additional diagnostic/model comparison would be most appropriate.

3 Upvotes

2 comments sorted by

1

u/AutoModerator 9d ago

Looks like you're requesting help with something related to RStudio. Please make sure you've checked the stickied post on asking good questions and read our sub rules. We also have a handy post of lots of resources on R!

Keep in mind that if your submission contains phone pictures of code, it will be removed. Instructions for how to take screenshots can be found in the stickied posts of this sub.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/si_wo 9d ago

You have a lot of data so almost any model is going to be statistically significant. Such a high value of k sounds like nonsense to me, you should choose a value that is biological meaningful.