set.seed(1)
n=100
s=1.5
xbar=18
ll=2.9307
ul=2.9768
fun = function(w) {
d=w^((n/2)-1)
e=(t-xbar-(((n-1)*s^2)/(2*w)))^2
g=n/((n-1)*s^2)
h=(e*g+1)*w
d*exp(-h/2)
}
Int_w = Vectorize(function(t) { integrate(fun, 0, Inf)$value })
integrate(Int_w , ll, ul)
#> Error in t - xbar : non-numeric argument to binary operator
I am trying to perform a double integral in R. fun is my function here. w and t are my variables. Integrations are done in the order: dw, dt. Why am I getting the error at the end (last line of the posted code above)?