I need some help to create an R script that will solve the following problem:
- I have a list of products: A, B, C and D.
- I need to create baskets that contains several products.
- Each basket contains a total of 6 units of products and can contain between 2 & 4 unique products.
- Each basket must contains between 2 & 5 units of A, and between 0 & 1 unit of product B, C & D.
- The customer opens a basket. The probability to obtain a specific basket is determined by some weights.
- Therefore, baskets can be something like:
enter image description here
What I need
- I need to determine the weights of each single basket…
enter image description here - …so the probabilities to obtain a specific product are the following:
enter image description here
In other words: the customer always receives some units of product A; the probability to obtain a product B tends to 40%; the probability to obtain a product C tends to 5%…
I already have listed the possible combinations, but I am failing to:
- determine the minimum amount of baskets so the algorithm has enough degrees of freedom to calculate optimum weights for each basket.
- find a mathematical formula and R code (probably something related to matrix resolution, MASS package…) to calculate the weights (I need a mathematical approach since in real life I am working with more products, so an approach with a loop going through all the possibilities implies too many combinations).
New contributor
MOOKERAIZER is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.