I am trying to understand semantics of Splus because I need to convert my R
code
to Splus code.
Could somebody give me references in the language manual/guide for the
following piece of the code
and its results?
Code:
------------------------------------------------------
conc1 <- c(0.3330, 0.1670, 0.0833, 0.0416,
0.0208, 0.0104, 0.0052)
vel1<- c(3.636, 3.636, 3.236, 2.666, 2.114, 1.466, 0.866)
stframe1<-function(conc,vel){
conc<-conc
vel<-vel
fit <- nls(vel~Vm*conc/(K+conc), start=list(K=0.02,Vm=3.7))
return(fit)
}
stframe<-function(conc,vel){
##conc<-conc
##vel<-vel
fit <- nls(vel~Vm*conc/(K+conc), start=list(K=0.02,Vm=3.7))
return(fit)
}
----------------------------------------------------------------------------
----
Results:
----------------------------------------------------------------------------
-----
> stframe(conc1,vel1)
Problem in nls(vel ~ (Vm * conc)/(K + conc), start = list(K = ..: Object
"conc" not found, while call
ing subroutine setup_nonlin
Use traceback() to see the call stack
> stframe1(conc1,vel1)
Residual sum of squares : 0.02257289
parameters:
K Vm
0.01788673 3.910935
formula: vel ~ (Vm * conc)/(K + conc)
7 observations
>
----------------------------------------------------------------------------
--------------------
My guess:
The function nls uses something like sys.frame(sys.parent()).
If the parameter conc is an integer, it is in the frame of stframe but
if it is a vector, it is not in the frame and only after you touch it as
conc<-conc
as in stframe1, it becomes visible for function nls.
I understand that it may be done for some kind of "lazy evaluation" but I
consider
it as a fundamental flaw of the language. The designers of nls did
sys.frame(sys.parent()) in order to
let the function be called from some frame but sometimes parameters of
the initial function are not in the frame if they are vectors and the
results are bad.
Please send me your comments and references.
Thanks,
-Igor Fomenko,
SI Lead at Amgen.
|