I have a dataset consisting of time periods, at the end of each one the individual either develops a disease, or doesn't and is right-censored. I suspect that the rate of developing the disease is determined by a power function of another known variable, N, a an unknown power b, and an unknown multiplier a determined by a random effect across the different individuals id.
I found this page very helpful, but I would like to use a survival model as the response variable (lhs), and a mixed non-linear model as the input (rhs).
The data look something like this (where I've made the power parameter 0.4).
library(tidyverse)
library(survival)
library(lme4)
Nsamples = 100
Z = tibble(ev = sample(0:1, size = Nsamples, replace = T), #event outcome
N = rpois(n = Nsamples, lambda = 100), #known input variable
dur = N^0.4*rnorm(n = Nsamples, mean = 1, sd = 0.1), #length of follow-up
id = rep(letters[1:2], each = Nsamples/2) #a random effect
)
I use a deriv function to define the non-linear part:
power.f = deriv(~a * N^b, namevec=c('a', 'b'), function.arg=c('a', 'N','b'))
And a survival function to define the output:
surv_obj <- with(Z, Surv(time = dur, event = ev))
Putting these together, and using the lme4::nlmer function with format Output ~ Non-linear part ~ Random effect
nlmer(surv_obj ~ power.f(a, N, b) ~ (a|id), data = Z, start=c(a=1, b=0.5))
However, I get the following error
# Error in resp$ptr() : dimension mismatch
In principle this should work I think, but I am not sure if these functions are compatible with each other and the error message doesn't mean much to me. Please help if you know how to get this to work, or some other way to fit a survival rates model like this with a power law in the input variables.
Thank you!