my=function(x){
len=1
for(i in 1:len){
y[i]=x[i]
}
g=1
w=NULL
t=NULL
for(i in 1:len)w[i]=x[i+len]
for(i in 1:len)t[i]=x[i+2*len]
for(i in 1:len)g=g*dnorm(y[i])*dnorm(w[i])*dnorm(z[i])
return(g)
}
cuhre(6,1,my,rep(-100,6),rep(100,6))
Error in crff(match.call(), integrand, "cuhre", libargs, ...) :
Additional argument not expected in the integrand function
function change to my=function(x,g,i,j)
result is not right. it should be 1, but it turns out to be 0.039...
How can I make this work?
Thank you!
--
View this message in context: http://r.789695.n4.nabble.com/cuhre-usage-multidimensional-integration-tp3873478p3873478.html
Sent from the R help mailing list archive at Nabble.com.
cuhre usage ?? multidimensional integration
6 messages · sevenfrost, R. Michael Weylandt
Perhaps you should start by writing vectorized code; as it stands, your code suggests you don't understand what simple operations like y <- x actually do. More to your question: what are cuhre & crff ? They are not in base R nor in any packages I have current loaded. Michael
On Wed, Oct 5, 2011 at 1:26 AM, sevenfrost <linshuang11 at gmail.com> wrote:
my=function(x){
len=1
for(i in 1:len){
y[i]=x[i]
}
g=1
w=NULL
t=NULL
for(i in 1:len)w[i]=x[i+len]
for(i in 1:len)t[i]=x[i+2*len]
for(i in 1:len)g=g*dnorm(y[i])*dnorm(w[i])*dnorm(z[i])
return(g)
}
cuhre(6,1,my,rep(-100,6),rep(100,6))
Error in crff(match.call(), integrand, "cuhre", libargs, ...) :
?Additional argument ?not expected in the integrand function
function change to my=function(x,g,i,j)
result is not right. it should be 1, but it turns out to be 0.039...
How can I make this work?
Thank you!
--
View this message in context: http://r.789695.n4.nabble.com/cuhre-usage-multidimensional-integration-tp3873478p3873478.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
cuhre is a function in package R2Cuba for multidimensional integration. There are three kind of variables to integrate. I just use y,w,t to distinguish them from each other. Is there any problem ? -- View this message in context: http://r.789695.n4.nabble.com/cuhre-usage-multidimensional-integration-tp3873478p3876182.html Sent from the R help mailing list archive at Nabble.com.
2 days later
I'd heartily suggest you read some basic R references before trying to engage this question: a cursory glance over your code suggests it can (and should) be entirely rewritten without for loops using vectorization and possibly a product function like this one that I'll provide you with: product <- function(x) exp(sum(log(x))) I'd do it myself, but to be honest, I don't really understand how its supposed to work. What is the point of "looping" from 1 to 1 so many times? As to your question, your first error comes from trying to apply multivariate integration techniques to a function of a single variable. Specifically, you give R secondary and (possibly) tertiary arguments and tell it to hand them to a univariate function -- hence the error. Your second error is probably caused by the fact that you now have a function of four variables -- x,g, i, j -- where i is never used other than the iterator (and you can't trick R so don't even go down that path), g is overwritten before being accessed, and j just doesn't appear at all. Michael
On Wed, Oct 5, 2011 at 5:07 PM, sevenfrost <linshuang11 at gmail.com> wrote:
cuhre is a function in package R2Cuba for multidimensional integration. There are three kind of variables to integrate. I just use y,w,t to distinguish them from each other. Is there any problem ? -- View this message in context: http://r.789695.n4.nabble.com/cuhre-usage-multidimensional-integration-tp3873478p3876182.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
I'm not quite familiar with R. Could you recommend some relative material. Actually, I'm not intend to loop from 1 to 1. I'm just trying to see if it works. It's supposed to be some len>1. I'm trying to solve the following example: there are 3 types of variables(x,w,t), they are not independent and have different distribution. Within each type, there are more than 1 variables. I need to integrate all the variable. joint pdf is like f(x,w,t)=?_i??f1(wi)f2(ti)?(?_j??f3(xj) ?_j??f4(xj*wi-ti?)?) -- View this message in context: http://r.789695.n4.nabble.com/cuhre-usage-multidimensional-integration-tp3873478p3886287.html Sent from the R help mailing list archive at Nabble.com.
Have you taken a look at the provided introductory materials? type help.start() to get "An Introduction to R" which I believe is provided as a part of every pre-packaged version of R so it's most likely already on your machine. Read that and then we can sort through how to correctly implement your function. Michael
On Sat, Oct 8, 2011 at 7:28 PM, sevenfrost <linshuang11 at gmail.com> wrote:
I'm not quite familiar with R. Could you recommend some relative material. Actually, I'm not intend to loop from 1 to 1. I'm just trying to see if it works. It's supposed to be some len>1. I'm trying to solve the following example: there are 3 types of variables(x,w,t), they are not independent and have different distribution. Within each type, there are more than 1 variables. I need to integrate all the variable. joint pdf is like f(x,w,t)=?_i??f1(wi)f2(ti)?(?_j??f3(xj) ?_j??f4(xj*wi-ti?)?) -- View this message in context: http://r.789695.n4.nabble.com/cuhre-usage-multidimensional-integration-tp3873478p3886287.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.