Re: [R] integrate with vector arguments

2015-02-27 Thread David Winsemius
On Feb 27, 2015, at 4:49 AM, marKo mton...@ffri.hr wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Gee. That simple. I knew that! Thanks a lot. Essentially, I needed only the diagonal elements. Easily solved by: diag(outer( X=v1,Y=v2, FUN= fV) I am sure that there are

Re: [R] integrate with vector arguments

2015-02-27 Thread marKo
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Yes. That's it. Thanks, a lot, really. Marko On 02/27/2015 02:46 PM, David Winsemius wrote: On Feb 27, 2015, at 4:49 AM, marKo mton...@ffri.hr wrote: Gee. That simple. I knew that! Thanks a lot. Essentially, I needed only the diagonal

Re: [R] integrate with vector arguments

2015-02-27 Thread marKo
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Gee. That simple. I knew that! Thanks a lot. Essentially, I needed only the diagonal elements. Easily solved by: diag(outer( X=v1,Y=v2, FUN= fV) I am sure that there are simpler options, but that works like a charm. Thanks a lot. Cheers, Marko

Re: [R] integrate with vector arguments

2015-02-26 Thread JS Huang
Hi, The following works. f2 function(z) { f1 - function(t) { z*t + z*t^2 } return(f1) } sapply(1:5,function(x)integrate(f2(x),0,1)$value) [1] 0.83 1.67 2.50 3.33 4.17 -- View this message in context:

Re: [R] integrate with vector arguments

2015-02-26 Thread David Winsemius
On Feb 26, 2015, at 1:49 PM, marKo mton...@ffri.hr wrote: v1-c(1:5) v2-c(1:5) f1-function (x) {v1*x+v2*x^2} The problem is that integrate(f1, 0, 1) does not work. I does not, even if a pas the arguments (v1, v2) f1-function (x, v1, v2) {v1*x+v2*x^2} or if i try to vectorize the

[R] integrate with vector arguments

2015-02-26 Thread marKo
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 I'm a bit stuck. I have to integrate a series of polynomial functions with vector arguments. v1-c(1:5) v2-c(1:5) f1-function (x) {v1*x+v2*x^2} The problem is that integrate(f1, 0, 1) does not work. I does not, even if a pas the arguments (v1, v2)

Re: [R] integrate with vector arguments

2015-02-26 Thread Hans W Borchers
marKo mtoncic at ffri.hr writes: I'm a bit stuck. I have to integrate a series of polynomial functions with vector arguments. v1-c(1:5) v2-c(1:5) f1-function (x) {v1*x+v2*x^2} The problem is that integrate(f1, 0, 1) does not work. The point is not that there are vector arguments, but

Re: [R] integrate

2013-11-21 Thread dan wang
That works. Thanks a lot! On Wed, Nov 20, 2013 at 11:52 PM, David Winsemius dwinsem...@comcast.netwrote: On Nov 20, 2013, at 8:39 PM, David Winsemius wrote: On Nov 20, 2013, at 7:12 PM, dan wang wrote: Hi all, Can anyone help me with below integrate function? Basically, I

[R] integrate

2013-11-20 Thread dan wang
Hi all, Can anyone help me with below integrate function? Basically, I want to calculate the integral of the sum of two kernel density functions. But the error shows that: In x - a : longer object length is not a multiple of shorter object length y1 = rnorm(10) y2 = rnorm(10) fhat -

Re: [R] integrate

2013-11-20 Thread David Winsemius
On Nov 20, 2013, at 7:12 PM, dan wang wrote: Hi all, Can anyone help me with below integrate function? Basically, I want to calculate the integral of the sum of two kernel density functions. But the error shows that: In x - a : longer object length is not a multiple of shorter

Re: [R] integrate

2013-11-20 Thread David Winsemius
On Nov 20, 2013, at 8:39 PM, David Winsemius wrote: On Nov 20, 2013, at 7:12 PM, dan wang wrote: Hi all, Can anyone help me with below integrate function? Basically, I want to calculate the integral of the sum of two kernel density functions. But the error shows that: In x - a :

Re: [R] Integrate with vectors and varying upper limit

2013-03-24 Thread Pete Brecknock
sunny0 wrote I'd like to integrate vectors 't' and 'w' for log(w)/(1-t)^2 where i can vary the upper limit of the integral to change with each value of 't' and 'w', and then put the output into another vector. So, something like this... w=c(.33,.34,.56) t=c(.2,.5,.1) k-c(.3,.4,.5)

Re: [R] integrate function

2013-02-12 Thread Prof. Dr. Matthias Kohl
use pmin instead of min. hth Matthias On 12.02.2013 16:41, dan wang wrote: Hi All, Can any one help to explain why min and max function couldn't work in the integrate function directly. For example, if issue following into R: integrand - function(x) {min(1-x, x^2)} integrate(integrand, lower

Re: [R] integrate function

2013-02-12 Thread William Dunlap
wang Sent: Tuesday, February 12, 2013 7:41 AM To: r-help@r-project.org Subject: [R] integrate function Hi All, Can any one help to explain why min and max function couldn't work in the integrate function directly. For example, if issue following into R: integrand - function(x) {min

Re: [R] integrate function

2013-02-12 Thread dan wang
Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of dan wang Sent: Tuesday, February 12, 2013 7:41 AM To: r-help@r-project.org Subject: [R] integrate function Hi All, Can

Re: [R] integrate: Don't do this?

2013-02-06 Thread Göran Broström
To answer my own question: I thought for a while that centering is the solution to the problem, but it is not: integrate(dnorm, 0, Inf, mean = 25) 3.187474e-05 with absolute error 5.9e-05 integrate(dnorm, -25, Inf, mean = 0) 3.187474e-05 with absolute error 5.9e-05 Here Don't do this is

[R] integrate: Don't do this?

2013-02-05 Thread Göran Broström
When I run the following function HQ2 - function(n) { nv - 6 * sqrt(n) fcn - function(z) { pchisq(z^2 / 36, n - 1) * dnorm(nv - z) } ## I want the integral from 0 to infinity: f.Inf - integrate(fcn, 0, Inf) ## Doc: Don't do this: f.100 - integrate(fcn,

Re: [R] integrate / Vectorize question

2012-10-04 Thread Gerrit Draisma
Dag Rui, Yes, it helped a lot! Thanks and greetings, Gerrit. Op 10/4/2012 12:06 AM, Rui Barradas schreef: Hello, Try Fnum - function(x, beta){ sapply(x, function(x) integrate(f,lower=-x,upper=0,beta=beta)$value) } And all results were the same. Hope this helps, Rui Barradas Em

[R] integrate / Vectorize question

2012-10-03 Thread Gerrit Draisma
Dear R-users, I want to use the function Fnum below in another integrate procedure. How do I write Fnum so that it returns a vector of values? And will the last integrate return the right answer? (I tried Vectorize() in several places, but got all sorts of errors.) Thanks for helping out.

Re: [R] integrate / Vectorize question

2012-10-03 Thread Rui Barradas
Hello, Try Fnum - function(x, beta){ sapply(x, function(x) integrate(f,lower=-x,upper=0,beta=beta)$value) } And all results were the same. Hope this helps, Rui Barradas Em 03-10-2012 21:59, Gerrit Draisma escreveu: Dear R-users, I want to use the function Fnum below in another

Re: [R] Integrate(dnorm) with different mean and standard deviation help

2012-07-27 Thread David Winsemius
...@ucalgary.ca To: kri...@ymail.com CC: chicagobrownb...@hotmail.com; r-help@r-project.org Subject: Re: [R] Integrate(dnorm) with different mean and standard deviation help On 2012-07-23 19:48, Pascal Oettli wrote: Hello, Maybe the following could help: f - function(x) dnorm(x, mean=2, sd=1

Re: [R] Integrate(dnorm) with different mean and standard deviation help

2012-07-27 Thread Rolf Turner
On 27/07/12 20:55, David Winsemius wrote: On Jul 26, 2012, at 10:06 AM, FJ M wrote: It would be a useful additon to the help page to add integrate(dnorm, lower = -1.96, upper = 1.96, mean = 2, sd = 1) Wouldn't most statisticians instead use the more accurate and undoubtedly faster:

Re: [R] Integrate(dnorm) with different mean and standard deviation help

2012-07-26 Thread FJ M
-project.org Subject: Re: [R] Integrate(dnorm) with different mean and standard deviation help On 2012-07-23 19:48, Pascal Oettli wrote: Hello, Maybe the following could help: f - function(x) dnorm(x, mean=2, sd=1) integrate(f, -1.96, 1.96) 0.4840091 with absolute error 1.4e-12

Re: [R] Integrate(dnorm) with different mean and standard deviation help

2012-07-26 Thread R. Michael Weylandt
. Thanks, Frank Chicago Date: Mon, 23 Jul 2012 19:54:45 -0700 From: ehl...@ucalgary.ca To: kri...@ymail.com CC: chicagobrownb...@hotmail.com; r-help@r-project.org Subject: Re: [R] Integrate(dnorm) with different mean and standard deviation help On 2012-07-23 19:48, Pascal Oettli wrote

[R] Integrate: compound distribution

2012-07-25 Thread tsakk
Dear All, thanks in advance for your attention. I'm struggling with this for a few weeks now, and figured it's time to get some help. I want to integrate(f(x), lower=-Inf, upper=Inf) with f(x) = ((gamma(K+1)/(gamma(r+1)*gamma(K-r+1)))*(q(x)^r)*(((1-q(x))^(K-r))*phi(x), where phi(x) is the

[R] Integrate(dnorm) with different mean and standard deviation help

2012-07-23 Thread FJ M
I'm trying to provide different parameters to the integrate function for various probability functions. I'm using dnorm as the simplest example here. For instance integrate(dnorm, -1.96, 1.96) produces the correct answer for a normal distribution with mean 0 and standard deviation 1. I've

Re: [R] Integrate(dnorm) with different mean and standard deviation help

2012-07-23 Thread Pascal Oettli
Hello, Maybe the following could help: f - function(x) dnorm(x, mean=2, sd=1) integrate(f, -1.96, 1.96) 0.4840091 with absolute error 1.4e-12 HTH Regards. Le 24/07/2012 11:23, FJ M a écrit : I'm trying to provide different parameters to the integrate function for various probability

Re: [R] Integrate(dnorm) with different mean and standard deviation help

2012-07-23 Thread Jorge I Velez
Try integrate(dnorm, mean = 2, sd = 1, -1.96, 1.96) 0.4840091 with absolute error 1.4e-12 HTH, Jorge.- On Mon, Jul 23, 2012 at 10:23 PM, FJ M wrote: I'm trying to provide different parameters to the integrate function for various probability functions. I'm using dnorm as the simplest

Re: [R] Integrate(dnorm) with different mean and standard deviation help

2012-07-23 Thread Peter Ehlers
On 2012-07-23 19:48, Pascal Oettli wrote: Hello, Maybe the following could help: f - function(x) dnorm(x, mean=2, sd=1) integrate(f, -1.96, 1.96) 0.4840091 with absolute error 1.4e-12 Or you could note the '...' argument indicated on the help page: integrate(dnorm, lower = -1.96,

Re: [R] Integrate(dnorm) with different mean and standard deviation help

2012-07-23 Thread Rolf Turner
integrate(dnorm, -1.96, 1.96, mean=2, sd=1) Read the help for integrate! It tells you that the integrate function has a ... argument which consists of additional arguments to be passed to f. cheers, Rolf Turner On 24/07/12 14:23, FJ M wrote: I'm trying to provide different

Re: [R] Integrate(dnorm) with different mean and standard deviation help

2012-07-23 Thread Pascal Oettli
Hello, Yes, I should learn to read. Regards Le 24/07/2012 11:54, Peter Ehlers a écrit : On 2012-07-23 19:48, Pascal Oettli wrote: Hello, Maybe the following could help: f - function(x) dnorm(x, mean=2, sd=1) integrate(f, -1.96, 1.96) 0.4840091 with absolute error 1.4e-12 Or you

Re: [R] Integrate(dnorm) with different mean and standard deviation help

2012-07-23 Thread arun
Hi, Check this link (https://stat.ethz.ch/pipermail/r-help/2010-February/227902.html). Hope it helps. A.K. - Original Message - From: FJ M chicagobrownb...@hotmail.com To: R r-help@r-project.org Cc: Sent: Monday, July 23, 2012 10:23 PM Subject: [R] Integrate(dnorm) with different

Re: [R] integrate function - error -integration not occurring with last few rows

2012-04-06 Thread Navin Goyal
Apologies for the lengthy code. I tried a simple (and shorter) piece of code (pasted below) and it still gives me the same error for last few rows. Is this a bug or am I doing something totally wrong? Could anyone please provide some help/pointers ? PS. beta0 was fixed to 0.001 in the previous

Re: [R] integrate function - error -integration not occurring with last few rows

2012-04-06 Thread Navin Goyal
Apologies for the lengthy code. I tried a simple (and shorter) piece of code (pasted below) and it still gives me the same error for last few rows. Is this a bug or am I doing something totally wrong? Could anyone please provide some help/pointers ? PS. beta0 was fixed to 0.001 in the previous

Re: [R] integrate function - error -integration not occurring with last few rows

2012-04-06 Thread Berend Hasselman
On 06-04-2012, at 13:14, Navin Goyal wrote: Apologies for the lengthy code. I tried a simple (and shorter) piece of code (pasted below) and it still gives me the same error for last few rows. Is this a bug or am I doing something totally wrong? Could anyone please provide some

Re: [R] integrate function - error -integration not occurring with last few rows

2012-04-06 Thread Navin Goyal
Thank you so much for your help Berend. I did not see that my code had a typo and it was thus wrongly written ( I overlooked the i that was supposed to be actually 1) instead of for (q in *1*:length(comb1$ID)) I had it as for (q in *i*:length(comb1$ID)) It works correctly as

Re: [R] integrate function - error -integration not occurring with last few rows

2012-04-06 Thread Peter Ehlers
On 2012-04-06 07:19, Navin Goyal wrote: Thank you so much for your help Berend. I did not see that my code had a typo and it was thus wrongly written ( I overlooked the i that was supposed to be actually 1) instead of for (q in *1*:length(comb1$ID)) I had it as for (q in

[R] integrate function - error -integration not occurring with last few rows

2012-04-05 Thread Navin Goyal
Hi, I am using the integrate function in some simulations in R (tried ver 2.12 and 2.15). The problem I have is that the last few rows do not integrate correctly. I have pasted the code I used. The column named integral shows the output from the integrate function. The last few rows have no

Re: [R] integrate function - error -integration not occurring with last few rows

2012-04-05 Thread Berend Hasselman
On 06-04-2012, at 00:55, Navin Goyal wrote: Hi, I am using the integrate function in some simulations in R (tried ver 2.12 and 2.15). The problem I have is that the last few rows do not integrate correctly. I have pasted the code I used. The column named integral shows the output from the

Re: [R] Integrate inside function

2012-03-17 Thread Mauro Rossi
Dear David and Micheal, thanks for your suggestion. Vectorize does what I need. David you suggest me that I didn't built the function in a manner that would vectorize. Could you please explain me what's wrong? Thanks, Mauro On Mar 15, 2012, at 6:08 AM, Mauro Rossi wrote: Dear R users,

Re: [R] Integrate inside function

2012-03-17 Thread R. Michael Weylandt
I don't believe you did anything wrong here, just that integrate() itself isn't (can't?) be vectorized. E.g., x - integrate(function(x) x^2, 0, 2) y - integrate(function(x) x^2, 0, c(2,3)) identical(x, y) # FALSE -- so there's a difference. # Take a look str(x) str(y) # It's just in the call

[R] Integrate inside function

2012-03-15 Thread Mauro Rossi
Dear R users, first I take this opportunity to greet all the R community for your continuous efforts. I wrote a function to calculate the pdf and cdf of a custom distribution (mixed gamma model). The function is the following: pmixedgamma3 - function(y, shape1, rate1, shape2, rate2, prev)

Re: [R] Integrate inside function

2012-03-15 Thread R. Michael Weylandt
I believe the difficulty is that the integrate function isn't vectorized: add this line and you should be good pmixedgamma3 - Vectorize(pmixedgamma3) Read ? Vectorize for details if you only need to vectorize certain arguments. Michael On Thu, Mar 15, 2012 at 6:08 AM, Mauro Rossi

Re: [R] Integrate inside function

2012-03-15 Thread David Winsemius
On Mar 15, 2012, at 6:08 AM, Mauro Rossi wrote: Dear R users, first I take this opportunity to greet all the R community for your continuous efforts. I wrote a function to calculate the pdf and cdf of a custom distribution (mixed gamma model). The function is the following:

[R] integrate (error: evaluation of function gave a result of wrong length)

2012-02-15 Thread Dimitris.Kapetanakis
Dear all, I am trying to use the integrate function in R but it seems that it does not work in my example and I cannot figure out why. I create a function Mu1 (which works fine) and try to integrate by the code: n - 100 Ctrl- as.matrix(cbind(runif(n, -30, 30))) W

Re: [R] integrate (error: evaluation of function gave a result of wrong length)

2012-02-15 Thread R. Michael Weylandt
Integrate works on functions that are vectorized (i.e., the algorithm puts in N inputs and expects N outputs) -- your function is not vectorized (and I'm not sure what integrating it means, but I'm not looking too closely) but you can make it look vectorized with the Vectorize() HOF. Note that

Re: [R] integrate (error: evaluation of function gave a result of wrong length)

2012-02-15 Thread Uwe Ligges
On 15.02.2012 17:33, Dimitris.Kapetanakis wrote: Dear all, I am trying to use the integrate function in R but it seems that it does not work in my example and I cannot figure out why. I create a function Mu1 (which works fine) and try to integrate by the code: n - 100 Ctrl-

[R] integrate two lines to one

2011-09-30 Thread Alaios
Dear all, I would like to put these two lines together logictoReduce-((Overloads-1)%%FreqN)==(SpanIndex-1) #0...3 refer to sub spans 1 to 4 Overloads-Overloads[logictoReduce==TRUE] and do it like this Overloads-Overloads[((Overloads-1)%%FreqN)==(SpanIndex-1)] which does not seem to work.

Re: [R] integrate two lines to one

2011-09-30 Thread R. Michael Weylandt
On first glance it seems like it should work, perhaps a minimal working example would help. Also, if logictoReduce is a boolean vector, you probably don't need to test for equality with TRUE; if that test seems necessary (i.e., if Overloads - Overloads[logictoReduce] doesn't work) that may be

Re: [R] integrate

2011-05-16 Thread Jonathan Daily
What exactly is the problem? Please read the posting guide and follow it. Your message is hard to interpret as is (in no small part because it looks like markup), contains no R code, and has no mention of an error at all. 2011/5/15 meltem gölgeli megolg...@gmail.com: Dear R-users, I'am really

[R] integrate

2011-05-15 Thread meltem gölgeli
Dear R-users, I'am really new at R. That's why I probably have a basic quastion. I have a function like f(x,y)=\int^{0}_{y}(2*x)*exp(y-t)dt or f(x,y)=\int^{0}_{y}((2*x)*exp(\int^{0}_{t}(x*k)dk)dt and I can also define some basic loops for xy like x in 1:3 and y in 1:2. Could anybody please help

Re: [R] integrate

2011-05-15 Thread David Winsemius
On May 15, 2011, at 6:51 AM, meltem gölgeli wrote: Dear R-users, I'am really new at R. That's why I probably have a basic quastion. I have a function like f(x,y)=\int^{0}_{y}(2*x)*exp(y-t)dt or f(x,y)=\int^{0}_{y}((2*x)*exp(\int^{0}_{t}(x*k)dk)dt and I can also define some basic loops for

[R] Integrate na.rm in own defined functions

2011-04-20 Thread Mauro
It`s probably an easy question, but couldn`t figure it out. I`ve defined a function like: rmse-function (x){ dquared-x^2 sum1-sum(x^2) rmse-sqrt((1/length(x))*sum1) rmse} My problem is, that I have NA Values in x and the above function returns NA. I`m looking for a way to use na.rm=TRUE like

Re: [R] Integrate na.rm in own defined functions

2011-04-20 Thread vioravis
This should work!! rmse-function (x){ dquared-x^2 sum1-sum(x^2,na.rm=TRUE) rmse-sqrt((1/length(x))*sum1) rmse} -- View this message in context: http://r.789695.n4.nabble.com/Integrate-na-rm-in-own-defined-functions-tp3462492p3462615.html Sent from the R help mailing list archive at

Re: [R] Integrate na.rm in own defined functions

2011-04-20 Thread Alexander Engelhardt
Am 20.04.2011 10:59, schrieb Mauro: It`s probably an easy question, but couldn`t figure it out. I`ve defined a function like: rmse-function (x){ dquared-x^2 sum1-sum(x^2) rmse-sqrt((1/length(x))*sum1) rmse} My problem is, that I have NA Values in x and the above function returns NA. I`m

Re: [R] Integrate na.rm in own defined functions

2011-04-20 Thread Rolf Turner
On 20/04/11 22:25, vioravis wrote: This should work!! rmse-function (x){ dquared-x^2 sum1-sum(x^2,na.rm=TRUE) rmse-sqrt((1/length(x))*sum1) rmse} Shouldn't the divisor be the number of non-missing values in x? Rather than the length of x? (Like, e.g. sum(!is.na(x)) ?) cheers,

Re: [R] integrate one single variable functions with constant parameters

2011-03-05 Thread santiagorf
If f is a two-parameter function, how can I integrate it with respect to p? -- View this message in context: http://r.789695.n4.nabble.com/integrate-one-single-variable-functions-with-constant-parameters-tp3336066p3336693.html Sent from the R help mailing list archive at Nabble.com.

Re: [R] integrate one single variable functions with constant parameters

2011-03-05 Thread santiagorf
I received the solution... Hi: This is what David means: f - function(x, p) x^p integrate(f, lower = -1, upper = 1, p = 2) 0.667 with absolute error 7.4e-15 integrate(f, lower = -1, upper = 1, p = 3) 0 with absolute error 5.6e-15 # this is correct -- View this message in

[R] integrate a fuction

2011-03-04 Thread santiagorf
I'm having a function of the form 1 f-function(x){ 1+ 1+return(x^p) 1+ 1+ } ,and I would like to integrate it with respect to x, where p should be any constant. One way would be to set a value for p globally and then call integrate function: p=2 integrate(f, lower = -1, upper = 1)

Re: [R] integrate a fuction

2011-03-04 Thread David Winsemius
On Mar 4, 2011, at 6:01 PM, santiagorf wrote: I'm having a function of the form 1 f-function(x){ 1+ 1+return(x^p) 1+ 1+ } ,and I would like to integrate it with respect to x, where p should be any constant. One way would be to set a value for p globally and then call integrate

[R] Integrate with an indicator function

2011-02-17 Thread li li
Hi all, I have some some problem with regard to finding the integral of a function containing an indicator function. please see the code below: func1 - function(x, mu){ (mu^2)*dnorm(x, mean = mu, sd = 1)*dgamma(x, shape=2)} m1star - function(x){ integrate(func1, lower = 0, upper =

Re: [R] Integrate with an indicator function

2011-02-17 Thread Dennis Murphy
Hi Hannah: You have a few things going on, but the bottom line is that numer and denom are both double integrals. On Thu, Feb 17, 2011 at 1:06 PM, li li hannah@gmail.com wrote: Hi all, I have some some problem with regard to finding the integral of a function containing an indicator

Re: [R] Integrate with an indicator function

2011-02-17 Thread li li
Hi Dennis, Thank you for your kind reply. Yes, essentially, we take integration twice. However, I still have a few questions: First, if we consider doing a double integration at the end, since the first integration in within the indicator function, it seems to be difficult. Second, m1star

[R] Integrate and subdivisions limit

2011-01-12 Thread Alaios
Dear all, I have some issues with integrate in R thus I would like to request your help. I am trying to calculate the integral of f(x)*g(x). The f(x) is a step function while g(x) is a polynomial. If f(x) (step function) changes its value only few times (5 or 6 'steps') everything is calulated

Re: [R] Integrate and subdivisions limit

2011-01-12 Thread Hans W Borchers
Dear all, I have some issues with integrate in R thus I would like to request your help. I am trying to calculate the integral of f(x)*g(x). The f(x) is a step function while g(x) is a polynomial. If f(x) (step function) changes its value only few times (5 or 6 'steps') everything is

[R] Integrate two function in R

2010-12-16 Thread Alaios
Hello I have two function in R like g(x)=2x-3 and s(x)=5x^2+2 and I want to find the integrafl of the g(x)*s(x) inside the interval of [a,b] Could you please help me find the proper function? I would like to thank you in advance for your help Regards Alex [[alternative HTML

Re: [R] Integrate two function in R

2010-12-16 Thread Ben Bolker
Alaios alaios at yahoo.com writes: Hello I have two function in R like g(x)=2x-3 and s(x)=5x^2+2 and I want to find the integrafl of the g(x)*s(x) inside the interval of [a,b] Analytically or numerically? It sounds like you want the answer analytically, in which case R can't do

Re: [R] Integrate two function in R

2010-12-16 Thread Ben Bolker
Ben Bolker bbolker at gmail.com writes: Analytically or numerically? It sounds like you want the answer analytically, in which case R can't do it, but it is an easy integral g(x)*s(x) = 10*x^3-15*x^2+4*x-6 indefinite integral = 10/3*x^4 -15/3*x^3 + 4/2*x^2 - 6*x + C oops, the

Re: [R] Integrate two function in R

2010-12-16 Thread David Winsemius
On Dec 16, 2010, at 7:27 AM, Alaios wrote: Hello I have two function in R like g(x)=2x-3 and s(x)=5x^2+2 and I want to find the integrafl of the g(x)*s(x) inside the interval of [a,b] Could you please help me find the proper function? It depends on what you are doing: None of what

Re: [R] Integrate two function in R

2010-12-16 Thread Eduardo de Oliveira Horta
I guess what you have is g - function(x){ 2*x-3 } s - function(x){ 5*x^2+2 } and what you want is f-function(x){ g(x)*s(x) } integrate(f,a,b) Try that and see if it works. If not (that is, if your actual g and s are not as in the example), maybe you'll have to do this:

Re: [R] Integrate two function in R

2010-12-16 Thread Kjetil Halvorsen
see inline. On Thu, Dec 16, 2010 at 10:11 AM, Ben Bolker bbol...@gmail.com wrote: Alaios alaios at yahoo.com writes: Hello I have two function in R like g(x)=2x-3 and s(x)=5x^2+2 and I want to find the integrafl of the g(x)*s(x) inside the interval of [a,b]  Analytically or

Re: [R] Integrate two function in R

2010-12-16 Thread Jonathan P Daily
a room when its empty? Does the room, the thing itself have purpose? Or do we, what's the word... imbue it. - Jubal Early, Firefly r-help-boun...@r-project.org wrote on 12/16/2010 09:11:33 AM: [image removed] Re: [R] Integrate two function in R Kjetil Halvorsen to: Ben Bolker

Re: [R] Integrate to 1? (gauss.quad)

2010-11-16 Thread Enrico Schumann
: Montag, 15. November 2010 18:11 An: Douglas Bates Cc: r-help@r-project.org Betreff: Re: [R] Integrate to 1? (gauss.quad) Thank you, Doug. I am still missing something here. Should this simply be sum(f(x_i) * w_i) where x_i is node i and w_i is the weight at node i? So, my function f(x) = (1

Re: [R] Integrate to 1? (gauss.quad)

2010-11-15 Thread Doran, Harold
Subject: Re: [R] Integrate to 1? (gauss.quad) I don't know about the statmod package and the gauss.quad function but generally the definition of Gauss-Hermite quadrature is with respect to the function that is multiplied by exp(-x^2) in the integrand. So your example would reduce to summing

[R] Integrate to 1? (gauss.quad)

2010-11-14 Thread Doran, Harold
Does anyone see why my code does not integrate to 1? library(statmod) mu - 0 s - 1 Q - 5 qq - gauss.quad(Q, kind='hermite') sum((1/(s*sqrt(2*pi))) * exp(-((qq$nodes-mu)^2/(2*s^2))) * qq$weights) ### This does what's it is supposed to myNorm - function(theta) (1/(s*sqrt(2*pi))) *

Re: [R] Integrate to 1? (gauss.quad)

2010-11-14 Thread Douglas Bates
I don't know about the statmod package and the gauss.quad function but generally the definition of Gauss-Hermite quadrature is with respect to the function that is multiplied by exp(-x^2) in the integrand. So your example would reduce to summing the weights. On Sun, Nov 14, 2010 at 11:18 AM,

[R] Integrate and mapply

2010-11-07 Thread Vaiva P
Hi, I need some help on integrating a function that is a vector. I have a function - vector which each element is different. And, naturally, function integrate() does not work I checked the article of U. Ligges and J. Fox (2008) about code optimization How Can I Avoid This Loop or Make It Faster?

Re: [R] Integrate and mapply

2010-11-07 Thread Uwe Ligges
So undint(u) is a 15 dimensional vector. What do the different dimensions mean? How would you define the integral of a 15 dimensional vector? It would help if you could provide some background on what your code is supposed to do. Uwe Ligges On 07.11.2010 17:01, Vaiva P wrote: Hi, I

Re: [R] Integrate and mapply

2010-11-07 Thread Joshua Wiley
Hi, Have you tried just your function (undint) on its own (i.e., without trying to feed it to integrate)? If you did, you would notice that it does not return anything (hence, I could not get any result). See inline comments for some additional thoughts. On Sun, Nov 7, 2010 at 8:01 AM, Vaiva P

Re: [R] Integrate and mapply

2010-11-07 Thread Joshua Wiley
Hi, I still do not really understand, but I have a couple ideas: On Sun, Nov 7, 2010 at 11:09 AM, Vaiva P asva...@gmail.com wrote: Thank you guys for  a quick reaction. I decided it to write a common letter to you both at once. I tried to calculate the value of a a function without

[R] integrate of function f(x,y,z) respect to x only

2010-07-20 Thread Xin Shi
Dear: Anyone has experience to use R integrate a function with more than two dimensions, but you only need to integrate the function respect to one variable, say x. Because I also want to maximise the log-likelihood after integration of function respect to x. Thanks! Xin --- Dr.Xin Shi

Re: [R] integrate dmvtnorm

2010-06-24 Thread Christos Argyropoulos
evaluations at the set of nodes). This can be achieved either explicitly or implicitly (by calling the sapply inside the function). Christos  Date: Wed, 23 Jun 2010 20:22:15 -0400 Subject: Re: [R] integrate dmvtnorm From: carrieands...@gmail.com To: argch...@hotmail.com CC: r-help@r

[R] integrate dmvtnorm

2010-06-23 Thread Carrie Li
Hello, everyone, I have a question about integration of product of two densities. Here is the sample code; however the mean of first density is a function of another random variable, which is to be integrated. ## f=function(x) {dmvnorm(c(0.6, 0.8), mean=c(0.75, 0.75/x))*dnorm(x, mean=0.6,

Re: [R] integrate dmvtnorm

2010-06-23 Thread Ravi Varadhan
this helps, Ravi. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Carrie Li Sent: Wednesday, June 23, 2010 7:06 PM To: r-help Subject: [R] integrate dmvtnorm Hello, everyone, I have a question about integration of product of two

Re: [R] integrate dmvtnorm

2010-06-23 Thread Carrie Li
) 0.1314427 with absolute error 4e-05 Christos Date: Wed, 23 Jun 2010 19:05:53 -0400 From: carrieands...@gmail.com To: R-help@r-project.org Subject: [R] integrate dmvtnorm Hello, everyone, I have a question about integration of product of two densities. Here

Re: [R] integrate dmvtnorm

2010-06-23 Thread Christos Argyropoulos
@r-project.org Subject: [R] integrate dmvtnorm Hello, everyone, I have a question about integration of product of two densities. Here is the sample code; however the mean of first density is a function of another random variable, which is to be integrated. ## f=function(x) {dmvnorm(c

Re: [R] integrate dmvtnorm

2010-06-23 Thread Ravi Varadhan
8:23 pm Subject: Re: [R] integrate dmvtnorm To: Christos Argyropoulos argch...@hotmail.com Cc: r-help@r-project.org Thanks! Both suggestions are very helpful. One more question: Can I use Vectorize to solve double integration question ? Now that f=function(x, y) {dnorm(y, mean= 0.75

[R] integrate function

2009-12-05 Thread li li
Hello, I have some trouble in terms of using integrate function in R. f1 is a function of p and x where x is supposed to be a vector. (See the code). Then I want to write function f2 which is a function of the vector x after I integrate out p. Can some one give me some help? Many thanks!

Re: [R] integrate function

2009-12-05 Thread David Winsemius
On Dec 5, 2009, at 4:59 PM, li li wrote: Hello, I have some trouble in terms of using integrate function in R. f1 is a function of p and x where x is supposed to be a vector. (See the code). Then I want to write function f2 which is a function of the vector x after I integrate out p.

Re: [R] integrate function

2009-12-05 Thread li li
Thank you very much for your reply! It is not an assignment. What I want to do is what we often do. If we have a bivariate function of x and p, I first fix x and integrate out p. Then the resultant function is only in terms of x. Here f1 is a bivariate function of x and p. f1 - function (p,x)

Re: [R] integrate function

2009-12-05 Thread Ravi Varadhan
@gmail.com Date: Saturday, December 5, 2009 7:13 pm Subject: Re: [R] integrate function To: David Winsemius dwinsem...@comcast.net Cc: r-help@r-project.org Thank you very much for your reply! It is not an assignment. What I want to do is what we often do. If we have a bivariate function of x

Re: [R] integrate function

2009-12-05 Thread li li
Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: li li hannah@gmail.com Date: Saturday, December 5, 2009 7:13 pm Subject: Re: [R] integrate function To: David Winsemius dwinsem

Re: [R] integrate function

2009-12-05 Thread David Winsemius
. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: li li hannah@gmail.com Date: Saturday, December 5, 2009 7:13 pm Subject: Re: [R] integrate function To: David Winsemius dwinsem...@comcast.net Cc: r-help@r-project.org Thank you very much for your reply

Re: [R] integrate function

2009-12-05 Thread Berend Hasselman
li li-13 wrote: Yes, f2 is the function I wanted to write. I tried to do use Vectorize function to f1, it did not work. f2 - function(x) + { + integrate(Vectorize(f1,vectorize.args =p), lower=0,upper=1, x) + } f2(c(2,3)) Error in Vectorize(f1, vectorize.args = p) :

[R] integrate() function error

2009-10-22 Thread fuzuo xie
This is my code , when i run it ,error happed . can you tell me what's the reason and modify it ?thank you very much !! the error is evaluation of function gave a result of wrong length e2-function(a) integrate(function(x) x,lower=0,upper=a)$value integrate(e2,lower=0, upper=0.5)$value

Re: [R] integrate() function error

2009-10-22 Thread andrew
Change e2 to the following and it works e2 - function(a) a^2/2 The reason it doesn't is that e2 must be able to handle vector inputs correctly. Your original function does not do this. from ?integrate f - an R function taking a numeric first argument and returning a numeric vector of the

Re: [R] Integrate function in R

2009-06-11 Thread Paul Hiemstra
?integrate, it is in the documentation Bhargab Chattopadhyay wrote: Hi! Can anyone please let me know what numerical integration procedure does the integrate function in package stats follow? Thank you in advance Shant [[alternative HTML version deleted]]

[R] Integrate function in R

2009-06-10 Thread Bhargab Chattopadhyay
Hi! Can anyone please let me know what numerical integration procedure does the integrate function in package stats follow? Thank you in advance Shant [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

[R] integrate with large parameters

2009-05-01 Thread Andreas Wittmann
Dear R-users, i have to integrate the following function `fun1` - function (a, l1, l2) { exp(log(l1) * (a - 1) - l2 * lgamma(a)) } but if l1 is large, i get the non-finite function value error, so my idea is to rescale with exp(-l1) `fun2` - function (a, l1, l2) { exp(log(l1) * (a - 1) -

Re: [R] integrate with large parameters

2009-05-01 Thread Duncan Murdoch
On 01/05/2009 5:46 AM, Andreas Wittmann wrote: Dear R-users, i have to integrate the following function `fun1` - function (a, l1, l2) { exp(log(l1) * (a - 1) - l2 * lgamma(a)) } but if l1 is large, i get the non-finite function value error, so my idea is to rescale with exp(-l1) `fun2` -

  1   2   >