4
I’m trying to integrate, under the whole line, the function:
integrand_1<-function(x){
exp(-x/phi-y*exp(-x)/(phi*2)-(x+sigma2/2)^2/(2*sigma2))}
Using the following data:
df <- readRDS(url("https://rawcdn.githack.com/fsbmat/StackOverflow/db2ff43778b047eab9761cdedb16f70a08ec2f89/df.rds"))
phi <- 0.02216155
rho <- 0.6003019
sigma2 <- 0.02652626
y <- df$y
mu <- df$mu
To do this, use the function Integrate, as below:
integrate(Vectorize(integrand_1), -Inf, Inf)$value
However, I receive the following message:
Error in integrate(Vectorize(integrand_1), -Inf, Inf) :
evaluation of function gave a result of wrong length
I tried to visualize the function to see if there was something wrong, using that code:
x <- seq(-10,10, length=300)
integrand_1(x)
is.numeric(integrand_1(x))
plot(x,integrand_1(x), xlim = c(2.3,2.6), type = "l")
The generated graph was:
That is, it was not to generate the above error. Or at least do not understand the reason for the mistake. Someone, could help me?
Hi Prof. Marcus Nunes, in fact you are right, the y is a vector. I was believing that this should not be a problem for the calculation. I’ll see what I can do! Thank you
– fsbmat