Hi people, I am new in this list and could not find a FAQ for it in particular, furthermore I could not find my question answered in the official R FAQ or docs. I have simply something like this:> f<-approxfun(data[,1],data[,2])and f is:> ffunction (v) .C("R_approx", as.double(x), as.double(y), as.integer(n), xout = as.double(v), as.integer(length(v)), as.integer(method), as.double(yleft), as.double(yright), as.double(f), NAOK = TRUE, PACKAGE = "base")$xout <environment: 02106C24> I also used "locPoly". Both yield either a function or a data frame of values. Is there a way to get a mathematical representation of the function, e.g. a polynomial of any order? Something like ax^3+bx^2+cx^1+d or similar if it is of degree 3? Basically, I want to create functions of measured values. Thanks in advance for any hints. -- Holger -- Holger
Hi seems to me like you are looking for lm or nls. If not you shall be more specific. HTH Petr On 17 Jul 2006 at 13:05, Holger Flick wrote: Date sent: Mon, 17 Jul 2006 13:05:37 +0200 From: "Holger Flick" <hflick at gmail.com> To: R-help at stat.math.ethz.ch Subject: [R] information about a function> Hi people, > > I am new in this list and could not find a FAQ for it in particular, > furthermore I could not find my question answered in the official R > FAQ or docs. > > I have simply something like this: > > > f<-approxfun(data[,1],data[,2]) > > and f is: > > > f > function (v) > .C("R_approx", as.double(x), as.double(y), as.integer(n), xout > as.double(v), > as.integer(length(v)), as.integer(method), as.double(yleft), > as.double(yright), as.double(f), NAOK = TRUE, PACKAGE > "base")$xout > <environment: 02106C24> > > I also used "locPoly". > > Both yield either a function or a data frame of values. > > Is there a way to get a mathematical representation of the function, > e.g. a polynomial of any order? Something like > ax^3+bx^2+cx^1+d or similar if it is of degree 3? > > Basically, I want to create functions of measured values. > > Thanks in advance for any hints. > > -- > Holger > > > > -- > Holger > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlPetr Pikal petr.pikal at precheza.cz
On Mon, 17 Jul 2006, Holger Flick wrote:> Hi people, > > I am new in this list and could not find a FAQ for it in particular, > furthermore I could not find my question answered in the official R > FAQ or docs. > > I have simply something like this: > > > f<-approxfun(data[,1],data[,2]) > > and f is: > > > f > function (v) > .C("R_approx", as.double(x), as.double(y), as.integer(n), xout = as.double(v), > as.integer(length(v)), as.integer(method), as.double(yleft), > as.double(yright), as.double(f), NAOK = TRUE, PACKAGE = "base")$xout > <environment: 02106C24> > > I also used "locPoly". > > Both yield either a function or a data frame of values. > > Is there a way to get a mathematical representation of the function, > e.g. a polynomial of any order? Something like > ax^3+bx^2+cx^1+d or similar if it is of degree 3?No, because they are not polynomials or any other simple-to-describe function.> Basically, I want to create functions of measured values.Perhaps you should use tools that fit the sort of functions you are interested in: see e.g. lm() and poly(). -- Brian D. Ripley, ripley at 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
It's not clear to me what you want; the on-line help states that approxfun() does linear or constant interpolation (the default is linear). It is trivial to write down a ``mathematical representation'' of the resulting function --- but why would you want to? The function f() you created does the calculations for you; all you would be doing is reinventing the wheel. cheers, Rolf Turner rolf at math.unb.ca