Guidelines for writing model term functions (?)
Well, there are examples like log, too, and poly() is a good one. poly, ns and bs are special because they participate in the safe prediction scheme (?SafePrediction). If you don't need that, just return a vector or matrix (whose columns will be treated as a set of vectors).
On Fri, 2 Jul 2004, Roger D. Peng wrote:
Are there any general guidelines for writing functions that appear in model formulas for functions like lm()/glm()? The ones I can think of are ns()/bs() in `splines' and s() in `mgcv'. It seems that ns()/bs() basically create matrix with a number of attributes and a class, while s() returns a list of parameters. It seems that gam() in `mgcv' has its own way of dealing with formulas so maybe that's not a great example, but are there any suggestions for writing a function that might appear in the formula for, say, lm() or glm()?
Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595