Calculating Integral using R

Asked

Viewed 1,228 times

5

I need to calculate this simple integral below:

inserir a descrição da imagem aqui It is the quantile function of the standard normal, where before hand we know that, q_0.5(z) = 0, for example.

That is, for each theta (percentile) it gives me a number in the standard normal density. The theta goes from 0 to 1.

I managed this function in R and organized in a matrix:

thau=1:99/100
qnorm(thau,0,1)

matrix=matrix(0,99,2)
matrix[,1]=thau
matrix[,2]=qnorm(thau,0,1)

colnames(mattrix)=c("theta","q(z)")

How do I calculate this interaction in R, since I already have the function q??

I thought of calculating the two integrals using the basic integral rules. Can I do this for this function? I think I can

inserir a descrição da imagem aqui

Would that be correct? To me it did -1.170456.

I’d love your help.

Thank you.

1 answer

2


According to what I understood about your problem, I believe it cannot be solved. Note that

eq1

Thus, the integral is undefined between 0 and 0.5. It diverges in this interval. It would be like integrating 1/x between 0 and 1, for example.

Your account comes in a result because it is not correct. Generalizing your result, it is equivalent to

eq2

If we assume that f(x)=1, according to your formula, we have

eq3

But this is an indeterminate, because we have 0/0. Therefore, there would be no solution to this problem. But just see that, if f(x)=1, we have

eq4

which is a clearly defined integral in the range in which we are interested. Therefore, the derivation of your result is not true and your answer is not -1.170456. Even your integral is divergent and your problem has no solution.

It would be interesting to go back to the original problem and see where this integral came from to understand why to calculate it.

  • Thanks, @Marcusnunes. I edited the equation, I made a mistake. I think it’s a little confusing my question, I’ll get better. But basically the function q_theta(z), the numerator, is this function: Plot(qnorm(Thau,0,1)) . I want to compute the integral of the numerator from 0 to 0.5. The integral of the denominator is that I cannot calculate.

  • 1

    Right. You can’t calculate the integral of the denominator. Run the command x <- seq(0, 0.5, 0.0001); plot(x, qnorm(x)/(qnorm(x)^2), type="l") and see how the value of this function diverges. How qnorm(0.5)=0, (qnorm(0.5))^2=0. Therefore, the denominator is 0 in 0.5. Therefore, the function qnorm(x)/(qnorm(x)^2) is not set at 0.5, preventing its integral from being calculated.

  • I have a question. I will take advantage of the topic. What function can I use to calculate the integral of this function that I plotted Plot(qnorm(Thau,0,1)), or any other, without creating a Function? I found the AUC function: auc(Thau[1:50],Matrix[,2][1:50]). It is the most indicated?

  • 1

    I don’t know this auc function, so I can’t say exactly what it’s for. If I had to solve your problem, I would create a trivial function in R and calculate the integral from it, like this: funcao <- function(x) return(qnorm(x)); integrate(funcao, lower=0, upper=0.5) (if any of my answers help you, don’t forget to vote and accept as final)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.