Re: [R] R object as a function

2008-01-23 Thread Tim Hesterberg
This function is a vectorized alternative to integrate: CumIntegrate <- function(f, a = 0, b = 1, nintervals = 5, ...){ # Cumulative integral. f is a function, a and b are endpoints # return list(x,y) of two vectors, # where x = seq(a, b, length = nintervals) # and y = \int_a^{x} f(

Re: [R] R object as a function

2008-01-22 Thread Sebastian Mueller
On Tuesday 22 January 2008 13:52:29 Thomas Steiner wrote: > Thank you very much Duncan for your quick answers. > > > You're not passing a function as myfunk1, you're passing mf, which is > > the result of evaluating myfun1, so it's a numeric vector. > > Yes, this is exacty my problem. > If I leave

Re: [R] R object as a function

2008-01-22 Thread Thomas Steiner
Dear Duncan, thanks a lot for your answer. I was think a was distracted by the FED rate cut ;) Now it works. Have a nice day Thomas myfun1<-function(x,pa) { return(pa[1]*x^2+pa[2]*x+pa[3]) } myfun2<-function(x,param,myfunk1,pa) { return(param[1]*myfunk1(x,pa)+param[2]*myfunk1(-x,pa)) } test<-

Re: [R] R object as a function

2008-01-22 Thread Duncan Murdoch
On 1/22/2008 7:52 AM, Thomas Steiner wrote: > Thank you very much Duncan for your quick answers. > >> You're not passing a function as myfunk1, you're passing mf, which is >> the result of evaluating myfun1, so it's a numeric vector. > > Yes, this is exacty my problem. > If I leave it away, the p

Re: [R] R object as a function

2008-01-22 Thread Thomas Steiner
Thank you very much Duncan for your quick answers. > You're not passing a function as myfunk1, you're passing mf, which is > the result of evaluating myfun1, so it's a numeric vector. Yes, this is exacty my problem. If I leave it away, the problem will not be resolved (it needs pa or not) myfun1

Re: [R] R object as a function

2008-01-22 Thread Duncan Murdoch
On 22/01/2008 6:51 AM, Thomas Steiner wrote: > Okay, let me try to better say what I meant: > > myfun1<-function(x=5,pa) { > return(pa[1]*x^2+pa[2]*x+pa[3]) > } > myfun2<-function(x=5,param,myfunk1) { > return(param[1]*myfunk1(x)+param[2]*myfunk1(x)) > } > test<-function(pars1,pars2,lo,up){ >

Re: [R] R object as a function

2008-01-22 Thread Duncan Murdoch
On 22/01/2008 5:30 AM, Thomas Steiner wrote: > I want to use a function as an argument to ingtegrate it twice. > See the following (senseless) example of a double integration: > > test<-function(sf,lo,up,rest) { > innerFkn<-function(sf,lo) { > inte=integrate(f=sf,lower=lo,upper=4) > retu

Re: [R] R object as a function

2008-01-22 Thread Thomas Steiner
Okay, let me try to better say what I meant: myfun1<-function(x=5,pa) { return(pa[1]*x^2+pa[2]*x+pa[3]) } myfun2<-function(x=5,param,myfunk1) { return(param[1]*myfunk1(x)+param[2]*myfunk1(x)) } test<-function(pars1,pars2,lo,up){ mf=myfun1(x=2,pa=8*pars1) integ=integrate(f=myfun2,lower=lo,u

[R] R object as a function

2008-01-22 Thread Thomas Steiner
I want to use a function as an argument to ingtegrate it twice. See the following (senseless) example of a double integration: test<-function(sf,lo,up,rest) { innerFkn<-function(sf,lo) { inte=integrate(f=sf,lower=lo,upper=4) return( inte$value ) } integral=integrate(f=innerFkn,lower=