I want to integrate let's say $f(x)=\sin(x)$ over the interval $(0,2\pi)$ using Monte Carlo Integration. I did so by using R.
I generated a random set of uniform numbers $(x)$ and took the mean of $f(x)$ then multiplied it by the interval length (2pi). Now I don't understand why we have to multiply the mean by the interval length to get the area.
If I want to create a confidence interval of this area obtained, I would need to find the standard deviation, do I just get the standard deviation of $f(x)$ and multiply it by $2\pi$, or multiply $f(x)$ by $2 \pi $ then get the standard deviation of that or what? I really don't understand why am multiplying by $2\pi$ to begin with so if you can explain that to me and let me know how to obtain a CI, that would be great!!!
For Monte Carlo integration you need to generate random points $(x,y)$, and then check if the random point $y\leq f(x)$.
The steps need to be like the following:
$y_{min} =f(x_{min}) = \sin(x_{min})$
In your case you know that the $\max(\sin(x))=1$, but if you didn't know, you would do the following:
When you have both $y_{min}$ and $y_{max}$ then you have a limiting rectangle to fit your function in (geometrically).
Finally,
Generate random $(x,y)$ points that are within the domains you fixed above. At every step, check if $y \leq f(x)$ and count the number of occurrences, let's call it ct_pts_in.
After all your Monte-Carlo steps are done, the area under the curve is:
$ A = A_{rectangle} \cdot \frac{\text{ct_pts_in}}{\text{total_random_points}} $