I am currently working with data involving three continuous variables in R, and I want to calculate the expected value of the joint probability distribution.
I attempted to use the kde() from the ks library to estimate the probability density and then integrate it to find the expected value.
However, I encountered an issue: to perform the integration, I need an expression involving the variables, but the kde estimates the probability at specific points as constants.
this is my code:
kde_estimate <- kde(data, eval.points = data[1:nrow(data)])
library(pracma)
func <- (kde_estimate$estimate) * (data$V1 * data$V2 * data$V3)
integral2(func, xmin=0, xmax=3, ymin=1, ymax=2)
Could someone guide me on how to derive the joint PDF function that includes the variables as unknowns?
Additionally, is it absolutely necessary to construct the joint PDF to calculate the expected value, or can I handle this similarly to discrete data by calculating the probability at each point, multiplying by the corresponding xyz values, and then summing these products?
In other words, is the following approach valid for continuous data:
- Calculate the probability at each point using kde.
- Multiply each point’s probability by its corresponding xyz values.
- Sum these products over all points.
I would appreciate any advice or alternative methods for calculating the expected value in this scenario.
Thank you in advance for your help!
$endgroup$
2