In R, I am trying to integrate the following function and verify that it is a pdf, as well as get the expected value and variance.... though I'm not entirely sure how to do this.
The function that needs to be verified is: f(x) = (x/4)*e^((-x^2)/8), x >= 0.
So far, I only have:
fun = expression((x/4)*e^((-x^2)/8))
integrate(fun,0,Inf)
It states error with the code above...
I know to get the expected value would be:
mean(x)
and the variance would be:
vcov(x)
You need to pass a function into integrate
fun = function(x) {(x/4)*exp((-x^2)/8)}
integrate(fun,0,10)
# Mean
fun2 = function(x) {x*fun(x)}
integrate(fun2,0,Inf)
# Variance
fun3 = function(x){(x-2.506628)^2 * fun(x)}
integrate(fun3,0,Inf)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.