Re: [R] User defined function within a formula

2015-07-17 Thread Kunshan Yin
Thank you very much. It worked. I think I need to digest this further later. Thanks again for the help. On Thu, Jul 16, 2015 at 4:51 PM, William Dunlap wrote: > This might do what you want: > > OPoly <- function(x, degree=1, weight=1, coefs=NULL, rangeX=NULL){ > weight <- round(weight,0)# weig

Re: [R] User defined function within a formula

2015-07-17 Thread Kunshan Yin
Thanks Bill for your quick reply. I tried your solution and it did work for the simple user defined function xploly. But when I try with other function, it gave me error again: OPoly<-function(x,degree=1,weight=1){ weight=round(weight,0)# weight need to be integer if(length(weight)!=length(x)

Re: [R] User defined function within a formula

2015-07-16 Thread William Dunlap
This might do what you want: OPoly <- function(x, degree=1, weight=1, coefs=NULL, rangeX=NULL){ weight <- round(weight,0)# weight need to be integer if(length(weight)!=length(x)) { weight <- rep(1,length(x)) } if (is.null(rangeX)) { rangeX <- range(x) } p <- poly(4*(rep(x,wei

Re: [R] User defined function within a formula

2015-07-16 Thread William Dunlap
OPoly<-function(x,degree=1,weight=1){ weight=round(weight,0)# weight need to be integer if(length(weight)!=length(x))weight=rep(1,length(x)) p=poly(4*(rep(x,weight)-mean(range(x)))/diff(range(x)),degree) Z<-(t(t(p[cumsum(weight),])*sqrt(attr(p,"coefs")$norm2[- seq(2)]))[,degree]) class(Z)

Re: [R] User defined function within a formula

2015-07-16 Thread William Dunlap
Read about the 'makepredictcall' generic function. There is a method, makepredictcall.poly(), for poly() that attaches the polynomial coefficients used during the fitting procedure to the call to poly() that predict() makes. You ought to supply a similar method for your xpoly(), and xpoly() needs