1
$\begingroup$

I'm modelling a time series of detection records for two different viruses. My outcome variable is the count of virus detections per month through time.

I have included a cyclic spline for month to capture cyclical patterns in annual virus detection records. For this cyclic spline I have set knot locations as I read here that this can help to reduce bias and error. However, I have also included a second spline to capture long-term trends in virus detection records.

Q: How will the knot locations be set for my second spline s(Time)? Will the knot locations for this spline also be dictated by my call knots = knots - this is not my intention, nor what I want. If possible, I would like to set the knot locations for s(nMonth) but let the gam() function set/decide the knot locations for all other smooths/splines that may be included in my model. Is this possible?

knots <- list(month = c(0.5, seq(1, 12, length = 10), 12.5))

gam(Number ~ State + Virus + State*Virus + s(nMonth, bs = "cc", k = 12, by = Virus) + s(Time, k = 12, by = Virus), 
            data = supply.pad, 
            family = nb(), 
            method = "REML", 
            knots = knots)
$\endgroup$

1 Answer 1

3
$\begingroup$

For cyclic splines you can just set the end points, which is better than what you did as you don't have equally-spaced knots.

knots <- list(month = c(0.5, 12.5))

with that, {mgcv} will spread the required number of knots evenly over the requested interval.

Any covariate that isn't named in knots will just have the knots for the basis (if needed) set using the default approach - evenly over the interval. However, because you didn't specify bs in the second smooth, you get the default spline which is a low-rank thin plate regression spline. These splines have a knot at each unique data location (unique covariate value), but to make them low-rank, Simon does an eigen decomposition of the full basis retaining only the k first eigen vectors to preserve much of the original full basis without actually requiring one basis function per unique value of the covariate. As a result, there aren't knots in you don't specify them for the TPRS basis.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.