On Tue, 7 Jun 2005, Liaw, Andy wrote:
The easiest way, perhaps, is to assign the internal functions to frame 1:
Another easy way is to use the MC() function in section 3.3.1 of the R
FAQ, which makes function closures in a way that works in S-PLUS.
-thomas
p.s. This modification gave the same answer for me in both S-Plus 6.2
and R 2.1.0 patched under Windows XP.
Spencer Graves wrote:
How about the following:
mainfunc <- function(x){
est <- function(x,par){
abs(sum(par*x))
}
func <- function(par,x, est.=est){
est.(x,par)
}
est.theta <- fu
How about the following:
mainfunc <- function(x){
est <- function(x,par){
abs(sum(par*x))
}
func <- function(par,x, est.=est){
est.(x,par)
}
est.theta <- function(x, func.=func, est.=est){
optimize(func.,lower=-10, upper=20,x=x,
est.=est.)$minimum
}
est.theta(x, func.
Victor Gravenholt wrote:
Sorry to bother you about a S-Plus related problem, but I hope someone
can help.
I have tried to "translate" some code from R to S-Plus (I have colleague
that insists on using S-Plus. And yes, I have tried to make him change
to R...)
The following code works out fine
The easiest way, perhaps, is to assign the internal functions to frame 1:
> mainfunc <- function(x){
+
+ est <- function(x,par){
+ abs(sum(par*x))
+ }
+
+ func <- function(par,x){
+ est(x,par)
+ }
+
+ est.theta <- function(x){
+ optimize(func,lower=-10, upper=20,x=x)$minimum
+ }
+