Let $(x_i,y_i)_{1\leq i\leq n}$ some dataset. I want to estimate the conditional expectation $E[Y\mid X=x]$ and the conditional variance $V[Y\mid X=x]$.
I used Nadaraya-Watson's estimator to estimate the conditional expectation:
$$\hat{E}[Y\mid X=x]=\frac{\sum_{i=1}^ny_iK\left(\frac{x-x_i}{h}\right)}{\sum_{i=1}^nK\left(\frac{x-x_i}{h}\right)}$$
In fact I just use the ksmooth
function in R.
Now let $z_i$ the squared residual: $z_i = \left(y_i - \hat{E}[Y\mid X=x_i]\right)^2$. Then I use Nadaraya-Watson's estimator once again to get an estimation of the conditional variance: $$\hat{V}[Y\mid X=x]=\frac{\sum_{i=1}^nz_iK\left(\frac{x-x_i}{h}\right)}{\sum_{i=1}^nK\left(\frac{x-x_i}{h}\right)}$$
So this is some kind of two-step estimation, which bothers me a little. Is this a good way to estimate the conditional variance? If not, how to do this properly (and not paramatrically)?