Re: [R] integrate

2007-08-22 Thread Ravi Varadhan
] Subject: Re: [R] integrate Hi Andy, Thank your very much for your input. I also tried something like that which gives a value close to 20, basically using the same trapezoidal rule. > sum(apply(as.matrix(seq(-10,10,by=0.1)),1,my.fcn))*0.1 [1] 20.17385 Actually my function is much more complica

Re: [R] integrate

2007-08-22 Thread Santanu Pramanik
To .umd.edu> Sent by: cc [EMAIL PROTECTED] at.math.ethz.ch

Re: [R] integrate

2007-08-22 Thread apjaworski
at.math.ethz.ch Subject [R] integrate 08/22/2007 02:56

Re: [R] integrate

2007-08-22 Thread Duncan Murdoch
On 8/22/2007 3:54 PM, Santanu Pramanik wrote: > Hi, > I am trying to integrate a function which is approximately constant > over the range of the integration. The function is as follows: That's not a function of the input mu. It includes a random component: > my.fcn(10) [1] 0.9786558 > my.fcn(

[R] integrate

2007-08-22 Thread Santanu Pramanik
Hi, I am trying to integrate a function which is approximately constant over the range of the integration. The function is as follows: > my.fcn = function(mu){ + m = 1000 + z = 0 + z.mse = 0 + for(i in 1:m){ + z[i] = rnorm(1, mu, 1) + z.mse = z.mse + (z[i] - mu)^2 + } + return(z.mse/m) + } > my.

[R] integrate

2007-08-22 Thread Santanu Pramanik
Hi, I am trying to integrate a function which is approximately constant over the range of the integration. The function is as follows: > my.fcn = function(mu){ + m = 1000 + z = 0 + z.mse = 0 + for(i in 1:m){ + z[i] = rnorm(1, mu, 1) + z.mse = z.mse + (z[i] - mu)^2 + } + return(z.mse/m) + } > my.

Re: [R] integrate over polygon

2007-02-15 Thread Duncan Murdoch
On 2/14/2007 9:06 PM, Haiyong Xu wrote: > Hi there, > > I want to integrate a function over an irregular polygon. Is there > any function which can implement this easily? Otherwise, I am > thinking of divide the polygon into very small rectangles and use > "adapt" to approximate it. Do you h

Re: [R] integrate over polygon

2007-02-15 Thread rolf
If you can integrate over a trapezoid (with horizontal base and vertical sides) then it's fairly easy to integrate over any (non-self intersecting) polygon. ``Draw'' a line which is below the polygon. For each segment in the polygon, integrate over trapezoid whose base is on the aforesaid line and

Re: [R] integrate over polygon

2007-02-15 Thread Paul Lynch
Oops. I just re-read your message and saw you were trying to integrate a function over a polygon, not calculate its area. I'm sorry I didn't read more carefully. --Paul On 2/15/07, Paul Lynch <[EMAIL PROTECTED]> wrote: > I'm still pretty ignorant about R, but I think it might be possibl

Re: [R] integrate over polygon

2007-02-15 Thread Paul Lynch
I'm still pretty ignorant about R, but I think it might be possible to work out an algorithm using cross products. First you would want to subdivide the polygon into convex polygons. I haven't tried to do that before, but it looks like it might be possible by looking at the sign of cross product

Re: [R] integrate over polygon

2007-02-14 Thread ecatchpole
Haiyong, There may be better ways, but this what I'd do. (And I'm not an expert on this.) (a) surround the polygon with a rectangle, (b) define, via an indicator function, a new function that is equal to your desired function within the polygon, and zero outside it, (c) use adapt() to integr

[R] integrate over polygon

2007-02-14 Thread Haiyong Xu
Hi there, I want to integrate a function over an irregular polygon. Is there any function which can implement this easily? Otherwise, I am thinking of divide the polygon into very small rectangles and use "adapt" to approximate it. Do you have any suggestions to get the fine division? Any

Re: [R] integrate and quadratic forms

2007-01-19 Thread Thomas Lumley
As the documentation for integrate() says, the function must be vectorized f: an R function taking a numeric first argument and returning a numeric vector of the same length. so you can't use sum(). You need matrix operations or an explicit loop to add up the terms. -th

Re: [R] integrate and quadratic forms

2007-01-19 Thread rdporto1
Thanks Jim. But a narrower problem still remains. Please, look at this new code: lambda=c(.6,.3) integral = function(u) { theta = (atan(.6*u) + atan(.3*u))/2 - .1*u/2 rho = (1+.6^2*u^2)^(1/4) * (1+.3^2*u^2)^(1/4) integrand = sin(theta)/(u*rho) } > integrate(integral,0,Inf)$value [1] 1.22268

Re: [R] integrate and quadratic forms

2007-01-18 Thread jim holtman
The do give the same answer, unfortunately the examples you sent were not the same. Integral2 was missing a 'sin'. So I would assume there might be something else wrong with your functions. You might want to try breaking it down into smaller steps so you can see what you are doing. It definite

[R] integrate and quadratic forms

2007-01-18 Thread rdporto1
Hi all. I'm trying to numerically invert the characteristic function of a quadratic form following Imhof's (1961, Biometrika 48) procedure. The parameters are: lambda=c(.6,.3,.1) h=c(2,2,2) sigma=c(0,0,0) q=3 I've implemented Imhof's procedure two ways that, for me, should give the same answer:

Re: [R] integrate R code to WinEdt file

2006-11-23 Thread Uwe Ligges
Aimin Yan wrote: > I want to integrate R code to my WinEdt file. > Can someone tell me how to do this? > I copy R code to my WinEdt file, but it does't work. I do not understand your question. Are you trying to install the RWinEdt package, which acts as a plug in for WinEdt to support writing R

[R] integrate R code to WinEdt file

2006-11-22 Thread Aimin Yan
I want to integrate R code to my WinEdt file. Can someone tell me how to do this? I copy R code to my WinEdt file, but it does't work. Aimin Yan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the post

Re: [R] integrate() problem {was "mathematica -> r ..."}

2006-08-08 Thread Martin Maechler
> "Leo" == Leo G?rtler <[EMAIL PROTECTED]> > on Tue, 08 Aug 2006 00:13:19 +0200 writes: Leo> Dear R-list, Leo> I try to transform a mathematica script to R. Leo> ###relevant part of the Mathematica script Leo> (* p_sv *) Leo> dd = NN (DsD - DD^2); Leo> lown

Re: [R] integrate

2006-06-23 Thread Spencer Graves
Thomas Lumley wrote: > On Fri, 23 Jun 2006, Rogério Rosa da Silva wrote: > >> Dear All, >> >> My doubt about how to integrate a simple kernel density estimation >> goes on. >> >> I have seen the recent posts on integrate density estimation, which seem >> similar to my question. However, I haven

Re: [R] integrate

2006-06-23 Thread Thomas Lumley
On Fri, 23 Jun 2006, Rogério Rosa da Silva wrote: Dear All, My doubt about how to integrate a simple kernel density estimation goes on. I have seen the recent posts on integrate density estimation, which seem similar to my question. However, I haven't found a solution. I have made two simple

[R] integrate

2006-06-23 Thread Rogério Rosa da Silva
Dear All, My doubt about how to integrate a simple kernel density estimation goes on. I have seen the recent posts on integrate density estimation, which seem similar to my question. However, I haven't found a solution. I have made two simple kernel density estimation by: kde.1 <-density(x

Re: [R] Integrate functions with loops

2005-09-19 Thread A.Brennan
Thankyou Brian > integrandtotest <- function(x) colSums(outer(t, x, "^")) > This worked fine >in fact this integration can be done analytically (it is a > sum of exponentials). I know but i have another five terms in the integrand as well as the one that was causing the trouble Many, m

Re: [R] Integrate functions with loops

2005-09-19 Thread A.Brennan
Thanks Sundar what you suggested worked fine > You will see that "x" is a vector and "tt[i]^x" returns a vector of the > same length. You are trying to place this vector into "a[i]" which is > length 1. Try the following *untested* code instead: > > > integrandtotest <- function(x) { >sum

Re: [R] Integrate functions with loops

2005-09-16 Thread Prof Brian Ripley
Try to give a vector result with one element for each of element of x, e.g. integrandtotest <- function(x) colSums(outer(t, x, "^")) works, although in fact this integration can be done analytically (it is a sum of exponentials). On Fri, 16 Sep 2005, A.Brennan wrote: > Hi > > i am hav

Re: [R] Integrate functions with loops

2005-09-16 Thread Sundar Dorai-Raj
A.Brennan wrote: > Hi > > i am having a problem with the 'integrate' function > the function i want to integrate has the form > sum(vector^x) > > i have defined the function with a for loop first - > integrandtotest <- function(x) > {a<-rep(0,len=2) > for (i in 1:2) > {a[i]<-t[

[R] Integrate functions with loops

2005-09-16 Thread A.Brennan
Hi i am having a problem with the 'integrate' function the function i want to integrate has the form sum(vector^x) i have defined the function with a for loop first - integrandtotest <- function(x) {a<-rep(0,len=2) for (i in 1:2) {a[i]<-t[i]^x} sum(a) } the resul

Re: [R] integrate fails with errors

2005-07-19 Thread Thomas Lumley
On Tue, 19 Jul 2005, [iso-8859-1] [EMAIL PROTECTED] wrote: > > beta0,eta0,n are initialized as single integer, temp is a 1 dimension array > containing 9 integer. > > integrate(function(beta) > ((beta/(eta0)^beta)^n)*prod(temp^(1-beta)*exp(-sum(temp^beta)/(eta^beta)))*(1/(sqrt(2*pi))*exp(((beta-

[R] integrate fails with errors

2005-07-19 Thread [EMAIL PROTECTED]
Hi all, i'm new to R, I need to modelize in R a statistic algorithm, This algo use Weibull, normal law, linear regression, normalisation, root mean square, to find eta and beta fitting the weibull model (to analyse few results) and further when we will get more information apply bayes model . th

Re: [R] integrate() and complex values

2005-01-11 Thread Prof Brian Ripley
On Tue, 11 Jan 2005, Robin Hankin wrote: > The manpage for integrate() does not mention imaginary numbers. The help page does say f: an R function taking a numeric first argument and returning a numeric vector of the same length. and in R complex numbers are not numeric (see ?n

[R] integrate() and complex values

2005-01-11 Thread Robin Hankin
[apologies for possible multiple post] Hi The manpage for integrate() does not mention imaginary numbers. I found the following unexpected: > integrate(function(x){0*x+1+1i},0,1) 1 with absolute error < 1.1e-14 > (I would expect 1+1i here) One can write a little wrapper, but it's not straightforwar

[R] integrate()

2005-01-11 Thread Robin Hankin
Hi I found the following unexpected: > integrate(function(x){0*x+1+1i},0,1) 1 with absolute error < 1.1e-14 > One can write a little wrapper, but it's messy. Would it be hard to accommodate such functions? The manpage for integrate() does not mention imaginary numbers. -- Robin Hankin Uncertainty

Re: [R] integrate a function in R

2004-10-28 Thread Prof Brian Ripley
.ac.be/biostat/ > http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm > > > - Original Message - > From: "yyan liu" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Thursday, October 28, 2004 12:56 AM > Subject: [R] integrate a fu

RE: [R] integrate a function in R

2004-10-28 Thread Ted Harding
On 27-Oct-04 yyan liu wrote: > Hi: > I want to integrate the following function with > respect to "z", "u" is another argument in the > function. My program is a loop and in each loop the > argument "u" will be given a specified numeric values. > But how can I use the "integrate" function with "u

Re: [R] integrate a function in R

2004-10-28 Thread Dimitris Rizopoulos
riginal Message - From: "yyan liu" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, October 28, 2004 12:56 AM Subject: [R] integrate a function in R Hi: I want to integrate the following function with respect to "z", "u" is another argume

[R] integrate a function in R

2004-10-27 Thread yyan liu
Hi: I want to integrate the following function with respect to "z", "u" is another argument in the function. My program is a loop and in each loop the argument "u" will be given a specified numeric values. But how can I use the "integrate" function with "u" in R? The function is: zfz<-function(

RE: [R] integrate function

2004-08-26 Thread Wayne Jones
u might be interested in http://www.stats.gla.ac.uk/~simon/simon/ddefit.html Regards Wayne Jones -Original Message- From: Ronaldo Reis Jr. [mailto:[EMAIL PROTECTED] Sent: 25 August 2004 21:02 To: R-Help Subject: [R] integrate function Is possible to integrate this diferential equati

Re: [R] integrate function

2004-08-26 Thread Jari Oksanen
On Wed, 2004-08-25 at 23:44, Peter Dalgaard wrote: > "Ronaldo Reis Jr." <[EMAIL PROTECTED]> writes: > > > Is possible to integrate this diferential equation: > > > > dN/dt = Nr(1-(N/K)) > > > > in R using the integrate() function? > > No. > However, you could use N = K/(1 + exp(log((K-N0)/

Re: [R] integrate function

2004-08-25 Thread Peter Dalgaard
"Ronaldo Reis Jr." <[EMAIL PROTECTED]> writes: > Is possible to integrate this diferential equation: > > dN/dt = Nr(1-(N/K)) > > in R using the integrate() function? No. > Or any other diferential equation? Only if the right hand side does not depend on the dependent variable (N in this case

[R] integrate function

2004-08-25 Thread Ronaldo Reis Jr.
Is possible to integrate this diferential equation: dN/dt = Nr(1-(N/K)) in R using the integrate() function? Or any other diferential equation? If yes, how? If no, anybody know any software on linux that make this? Inte Ronaldo -- O problema de ter os dois pés bem firmes no chão é que você

[R] integrate over a serie

2004-05-14 Thread javier garcia - CEBAS
Hi all; I've got temporal series of data. And I'm plotting it with the type 'l', and with a interpolating slipe. Could you advise me about the best way to calculate the area under any of these curves. I know it is very easy to calculate the first one, although have no idea of the second on

[R] integrate

2003-06-02 Thread Rafael A. Irizarry
Im tryng to understand an error i get with integrate. this is 1.7.0 on solaris 2.8. ##i am trying to approximate an integral of this function, f<-function(b) exp(-(b-mu)^2/(2*tau2))/(p-exp(b))*10^6 ##with tau2 <- .005;mu <- 7.96;p <- 2000 ##from -inf to different upper limits. using integrate(f,