Search code examples
rstatisticsregressionsimulationmontecarlo

Create Bi-variate probability density to sample from in R


I have some data that has two variables: spend and outcomes and they are given at a weekly frequency. I would like to model the relationship between the two at a yearly level, but do not have enough years worth of data to build a model. I do have about 3 years worth of weekly data, however, and would like to simulate several more weeks of data points (spend and outcomes) based on a bi-variate probability density between spend and outcomes which I could then use to roll up to a yearly frequency.

Is there a package in R that can take take two variables and find an estimate for the density function which I could then use to simulate many more data points?

Thanks so much!


Solution

  • The simulate_kde function in the package simukde will internally make a kernel density estimation and create samples from it.

    Alternatively, the MASS package has the kde2d function to obtain a bivariate kernel density.

    You could then sample from that, as for instance described in this post.