drizopoulos / JM

Joint Models for Longitudinal & Survival Data under Maximum Likelihood
34 stars 7 forks source link

error when applying weight function to ins() #29

Open agstone90 opened 3 years ago

agstone90 commented 3 years ago

Hi Dr. Rizopoulos,

I am having trouble getting the standard normal density function from your book to work with the DerivSplines and was wondering if I need to adapt it in some way. I am currently using <

g <- function(u, pow = 0) { f <- function(t) integrate(function(s) s^pow dnorm(t - s), 0, t)$value sapply(u, f) } iform_cew<-list(fixed=~-1+I(g(time))+ ins(time,knots=3,weight.fun =g)+ I(g(time)(cov)), indFixed=1:5, random=~-1+I(g(time))+I(g(time,1)),indRandom=1:2)

corresponding to lme object with code < lmefit<-lme(longvar~ns(time,3)+cov,random=~time|ID, data=data,control=lmeControl(opt="optim"))

Running the model with this derivForm returns an error: "Error in integrate(function(s) s^pow dnorm(t - s), 0, t) : evaluation of function gave a result of wrong length In addition: Warning messages: 1: In s^pow : longer object length is not a multiple of shorter object length 2: In s^pow dnorm(t - s) : longer object length is not a multiple of shorter object length"

I haven't been able to find any sample syntax for applying weighting functions to splines for JM and would appreciate any guidance. Thank you!