简体   繁体   中英

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!

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 .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM