[R] rls() fails on function calling spline()

Hengstberger Florian Florian.Hengstberger at ait.ac.at
Tue Oct 18 17:14:17 CEST 2011


Hello everybody

I want to use rls() on a multi-dimensional function, where parts of it are modeled using a spline.
I tried to condense my problem into the following code example,
which tries to fit the y-values of a spline interpolation:

---------------------------------------------------------------------------
rm(list=ls(all=TRUE))

x<-c(1,2,3,4,5,6,7,8,9)
y<-x^2

f<-function(x,c1,c3,c6,c9){
ys<-spline(c(1,3,6,9),y=c(c1,c3,c6,c9),xout=x)$y
print(ys)
print(c1)
return(ys)
}

print('Function evaluation')

f(x,1,1,1,1)
f(x,1,1,1,2)

print('Fit')

fit<-nls(y~f(x,c1,c3,c6,c9),start=list(c1=1,c3=1,c6=1,c9=1),
control=nls.control(maxiter=5))

-------------------------------------------------------------------

When I run the program, nls() does not change the parameters c1,c3,c6,c9,
and the iteration does no converge (here stopped after maxiter).
Moreover, ys always contains y=x^2 for some odd reason.
Using splinefun instead does no change the result.

Is there something with scope rule I do not understand?
Any ideas?

Kind regards
Florian Hengstberger

DI Dr. FLORIAN HENGSTBERGER
Energy Department
Sustainable Thermal Energy Systems

AIT Austrian Institute of Technology GmbH
Giefinggasse 2  |  1210 Vienna  | Austria
T +43(0) 50550-6609 | M +43(0) 664 6207849  |  F +43(0) 50550-6679
florian.hengstberger at ait.ac.at  |  http://www.ait.ac.at

FN: 115980 i HG Wien  |  UID: ATU14703506
This email and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient, please notify the sender by return e-mail or by telephone and delete this message from your system and any printout thereof. Any unauthorized use, reproduction, or dissemination of this message is strictly prohibited. Please note that e-mails are susceptible to change. AIT Austrian Institute of Technology GmbH shall not be liable for the improper or incomplete transmission of the information contained in this communication, nor shall it be liable for any delay in its receipt.



More information about the R-help mailing list