Re: [R] using integrate in a function definition

2007-02-23 Thread Ravi Varadhan
Your function jjj is not vectorized. Try this: jjj - function(www) sapply(www, function(x)2*integrate(dnorm,0,x)$value) plot(jjj, 0, 5) It should work. Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The

Re: [R] using integrate in a function definition

2007-02-23 Thread Alberto Monteiro
theo borm wrote: jjj-function(www) {2*integrate(dnorm,0,www)$value} kkk-function(www) {2*(pnorm(www)-0.5)} xxx-seq(0:5) yyy-jjj(xxx) zzz-kkk(xxx) produces no errors, but: yyy [1] 0.6826895 zzz [1] 0.6826895 0.9544997 0.9973002 0.367 0.994 1.000 Why is this?

Re: [R] using integrate in a function definition

2007-02-23 Thread theo borm
Ravi Varadhan wrote: Your function jjj is not vectorized. Try this: jjj - function(www) sapply(www, function(x)2*integrate(dnorm,0,x)$value) plot(jjj, 0, 5) It should work. Yes it does. Thanks! Thinking of it, it now starts to make some sort of sense that integrate should return a

Re: [R] using integrate in a function definition

2007-02-23 Thread theo borm
Hi, Many thanks for the explanation. Alberto Monteiro wrote: PS: fff - function(x) 1 integrate(fff, 0, 1) # error. why? Guess: because integrate itself expects a vectorized function ? fff(1:5) [1] 1 ggg-function(x) { sapply(x, function(x)1) } ggg(1:5) [1] 1 1 1 1 1