[R-sig-ME] nlme prediction with predictor function

Cole, Tim tim.cole at ucl.ac.uk
Mon Mar 23 14:56:24 CET 2015


My sitar library fits an nlme model with (for example) a 5 df regression spline as follows, where a, b and c are mixed effects:

.fitnlme <<- function(x, s1, s2, s3, s4, s5, a, b, c) {
splinecoefs <- as.matrix(cbind(s1, s2, s3, s4, s5))
as.vector( a +
(splinecoefs * as.matrix(ns((x - ( b )) * exp( c ),
knots=knots, Boundary.knots=bounds))) %*%
matrix(rep(1, df), ncol=1))
}
nlme(y ~ .fitnlme(x, s1, s2, s3, s4, s5, a, b, c),
fixed = s1 + s2 + s3 + s4 + s5 + a + b + c ~ 1,
random = a + b + c ~ 1 | id,
etc)

Note that the function .fitnlme is written to globalenv to make it available during the fitting - I've not found a more elegant way to do it. I could include the function code within nlme, but I need the named function to use with predict.

Using predict.nlme(object, newdata) also requires .fitnlme. Again I could write it to globalenv but I'd prefer to pass it in the predict.nlme call. I've tried various incantations to achieve this, but none of them work. Is it possible, and can anyone advise?

I recognise that this is only marginally a mixed-models query...

Thanks,
Tim
---
Tim.Cole at ucl.ac.uk<mailto:Tim.Cole at ich.ucl.ac.uk> Phone +44(0)20 7905 2666 Fax +44(0)20 7905 2381
Population, Policy and Practice Programme
UCL Institute of Child Health, London WC1N 1EH, UK


	[[alternative HTML version deleted]]



More information about the R-sig-mixed-models mailing list