2

I have a nonlinear mixed-effects model that I have implemented in nlme that I would like to implement in TMB to decrease computation times and hopefully some occasional convergence issues.

In its simplest form, the model is given by

y_ij = f((1 - b_i) * t_ij, knot_values) + e_ij

where y_ij is the observation at time t_ij, f is a natural cubic spline interpolation function with values knot_values at a set of given knot points, b_i is a parameter that decides how fast subject i progresses through the trajectory and e_ij is a normally distributed error terms.

An example of an implementation of this model in nlme is

# Mean function, v0, v1 and v2 are knot values
f <- function(t, v0, v1, v2, b) {
 months <- c(0, 6, 12) # Predefined observation times
 b <- cbind(0, b, b)
 t_out <- (1 - b[cbind(1:length(t), match(t, months))]) * t 
 
 spline(x = months,
 y = c(v0[1], v1[1], v2[1]),
 method = 'natural',
 xout = t_out)$y
}
# Fit model
gnls(model = y ~ f(M, v0, v1, v2, b),
 data = dat,
 params = list(v0 + v1 + v2 ~ 1,
 b ~ group + 0),
 start = start_vec)

While it is straightforward to implement conventional spline models in TMB that are linear in the interpolation values (knot_values), my problem with porting this model is that the model is nonlinear in the parameter b_i. Is there a nice way to implement such a model in TMB?

asked Apr 9, 2023 at 13:51
2
  • I would probably try passing the spline basis to TMB as data and solving for the spline coefficients internally ... ?? Commented Apr 9, 2023 at 16:03
  • @BenBolker That is how I would handle the spline coefficients v0, v1, v2, but for b_i, I believe I need to access the functional form of the spline from C++ so that the automatic differentiation magic can happen. Commented Apr 9, 2023 at 19:05

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.