Understanding and implementing numerical integration with a quantile function in R

后端 未结 1 875
后悔当初
后悔当初 2021-01-25 00:38

I need to calculate this integral below, using R:

The q_theta(x) function I managed to do in R with quantile regression (package: quantreg).

<
相关标签:
1条回答
  • 2021-01-25 01:18

    Recall your previous post Building a function by defining X and Y and then Integrating in R, we build a linear interpolation function

    ## note `rule = 2` to enable "extrapolation";
    ## otherwise `rule = 1` gives `NA` outside [0.01, 0.5]
    integrand <- approxfun(mat[, 1], y, rule = 2)
    

    Then we can perform numeric integration on [0, 0.5]:

    integrate(integrand, lower = 0, upper = 0.5)
    # -5.594405 with absolute error < 4e-04
    

    Now for a>, let's have a proof first.

    Note, your quantile function is not for normal distribution, so this result does not hold. You can actually verify this

    quant <- approxfun(mat[, 1], mat[, 2], rule = 2)
    integrate(quant, lower = 0, upper = 0.5)
    # -3.737973 with absolute error < 0.00029
    

    Compared with previous integration result -5.594405, the difference is not a factor of 2.

    0 讨论(0)
提交回复
热议问题