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

Cole, Tim tim.cole at ucl.ac.uk
Fri Mar 27 18:30:16 CET 2015


Dear Mario,

You'll remember I was struggling to find a way of passing a function to nlme within a package. After about 5 years I have finally cracked it!

This is the structure I want, but unless both instructions are in globalenv nlme does not see fitnlme.
fitnlme <- function(...) {...}
nlme(y ~ fitnlme(...), fixed = ..., random = ..., ...)

The solution is as follows: create a new environment, write fitnlme to it and then attach it:
fitenv <- new.env()
fitenv$fitnlme <- function(...) {...}
attach(fitenv)
on.exit(detach(fitenv))
nlmecode <- "text containing nlme command code"
nlme.out <- eval(parse(text=nlmecode))

It works!

Best wishes,
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