I intend to calculate the variance of a method however the expression is quite a mess.
In order to calculate this, I used the most inefficient way. I defined a function "a" which is
a<-function(x){
(x/2*exp(-x^2/4)/(1/(sqrt(2*pi)*sqrt(2))*exp(-(x-4)^2/(2*2)))-0.01831564)^2*(1/(sqrt(2*pi)*sqrt(2))*exp(-(x-4)^2/(2*2)))
}
and use the command
integrate(a,lower=0,upper=Inf)
however it cannot show the result.what's wrong with my usage and is there any easy way to do this?Thanks!
the error message is
integrate(a, lower = 0, upper = Inf) : non-finite function value