I am generating a function of $x$: $m(x)=0.5-6x^2+3x^3$, where $x$ is taken from a uniform distribution: $x\sim U(-1,1)$.
Now, I would like to center the function $m(x)$, so that the expectation of the function $m(x)$ is zero: $Em(x)=0$.
So, since the density of $x$, $f(x)=\frac{1}{2}$ by definition of uniform distribution, $Em(x)=\int_{-1}^{1}\frac{1}{2}(0.5-6x^2+3x^3)dx=-1.5$.
Questions: I expect that when I generate this function in R and calculate its sample average of the function value, the sample mean of this function, $\frac{1}{n}\sum_{j=1}^{n}m(x_j)$, will converge to its expectation, which is -1.5. But this is not the case:
n<-200000
x<-runif(n,-1,1)
m<-0.5-0.6*x^2+3*x^3
mean(m1)
> 0.2996
and this is quite far from -1.5 as its expected value.
I must miss something important here. Am I using a wrong weight to calculate the sample mean of the function $m(x)$?
m<-0.5-6*x^2+3*x^3
$\endgroup$