I'm interested in how growth of a fish species is related to several environmental variables. Those variables are measured at the time of capture, but several fish can be captured in a single sample (tow), so will all have identical environmental variables. I'd like to nest the samples within towid to account for this, but I'm having trouble figuring out how the syntax works within mgcv in R.
My current best guess is the following formulation, where mar is the marginal growth and is the response variable, sal, temp, secchi are the three environmental variables of interest and towid is the id for the sampling event during which potentially multiple fish were captured.
model = gam(mar ~ s(sal, by = towid) + s(temp, by = towid) + s(secchi, by = towid),
data = df)
However, I'm unsure if every variable needs to have that by = towid argument or if I just need to add in a fishid variable that has it, for example:
model = gam(mar ~ s(sal) + s(temp) + s(secchi) + s(fishid, by = towid),
data = df)
thanks for your help.
by = towidargument – C. Denney Oct 08 '19 at 01:50gam(mar ~ s(age, by = towid) + s(towid, bs = 're') + s(temp) + s(sal) + s(secchi)
is that correct?
– C. Denney Oct 08 '19 at 02:15