# [R] Numerical integration

nany23 anna.botto at gmail.com
Fri Jul 1 14:47:40 CEST 2011

```thanks for the Italian!
I apologize for my previuos explanation which was not clear
actually there are two "k" parameters, so I change one  them; let's put it
this way

/# these are the 3 parameters
a<- 414.566
b<- 345.5445
g<- -0.9695679
xstar<- 1397.923
*m<-100*
#I create a vector
pars <-expand.grid(xstar = xstar, a= a, b= b , g= g)
fun <- function(xstar, a,b,g,*m*) {
f <- function(x, xstar, a, b,g,m) f.lognorm(x) * *m* * x * (x >= xstar)
integrate(f, -Inf, Inf, xstar = xstar, a = a, b =b, g=g, *m=m*)\$value
}
# Method 1: (outputs a data frame)
library(plyr)
out <- mdply(pars, fun)

at this stage a warning message comes out: Errore in k > -1e-07 : 'k' is
missing/

The "k" the errore refers to is one of the three parameters of the pdf
distribution whose formula is the following

/function (x, xi, alfa, k)
{
if ((*k > -1e-07*) & (k < 1e-07)) {
y <- (x - xi)/alfa
}
else {
y <- -k^(-1) * log(1 - k * (x - xi)/alfa)
}
f <- exp(k * y - (y^2)/2)/(alfa * sqrt(2 * pi))
return(f)
}/

So the xi,alfa, k of the function are those which I call a,b,g[the
parameters]
I'm afraid I'm making some very silly mistakes in the syntax but don't know
where and how correct them...

I tried different ways but they don' work...

--
View this message in context: http://r.789695.n4.nabble.com/Numerical-integration-tp3634365p3638104.html
Sent from the R help mailing list archive at Nabble.com.

```