probability of purchasing an item based on past purchases












1














I have some data on individual purchases.



In this data PANID is a person who bought a product on a particular week. In the sample I provide, there are 6 unique PANID's; so 6 people in total. I am trying to calculate the conditional probability that a PANID will repurchase a product a second time.



For example:



PANID 3104497 bought ITEM 7028 in WEEK 2010-01-11 and then again the same PANID bought the same ITEM in WEEK 2010-01-25. I am trying to figure out how to find the probability that they will buy that same item again (at any point in the data).



    PANID       WEEK ITEM
1 3104497 2010-01-11 526
2 3104497 2010-01-11 526
3 3104497 2010-01-11 526
4 3104497 2010-01-11 526
5 3104497 2010-01-11 526
6 3104497 2010-01-11 2890
...
705 3146217 2010-04-05 97
706 3146217 2010-04-05 132
707 3146217 2010-04-05 132
708 3146217 2010-04-05 132
709 3146217 2010-04-05 132
710 3146217 2010-04-05 132


Data:



df <- structure(list(PANID = c(3104497L, 3104497L, 3104497L, 3104497L, 
3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
3138990L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
3104497L, 3104497L, 3104497L, 3104497L, 3146217L, 3146217L, 3146217L,
3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
3138990L, 3138990L, 3138990L, 3138990L, 3104497L, 3104497L, 3104497L,
3104497L, 3104497L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
3138990L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3138990L,
3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
3138990L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
3104497L, 3104497L, 3104497L, 3104497L, 3146217L, 3146217L, 3146217L,
3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3138990L,
3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
3138990L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
3322156L, 3322156L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
3369710L, 3369710L, 3369710L, 3369710L, 3146217L, 3146217L, 3146217L,
3146217L, 3146217L, 3322156L, 3322156L, 3322156L, 3322156L, 3138990L,
3138990L, 3138990L, 3138990L, 3369710L, 3369710L, 3369710L, 3369710L,
3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
3146217L, 3146217L, 3146217L, 3138990L, 3138990L, 3138990L, 3138990L,
3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
3138990L, 3369710L, 3369710L, 3369710L, 3369710L, 3369710L, 3369710L,
3369710L, 3369710L, 3322156L, 3322156L, 3322156L, 3322156L, 3146217L,
3146217L, 3146217L, 3146217L, 3146217L, 3322156L, 3322156L, 3322156L,
3322156L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3138990L,
3138990L, 3138990L, 3138990L, 3104497L, 3104497L, 3104497L, 3104497L,
3104497L, 3322156L, 3322156L, 3322156L, 3322156L, 3138990L, 3138990L,
3138990L, 3138990L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
3322156L, 3322156L, 3322156L, 3322156L, 3369710L, 3369710L, 3369710L,
3369710L, 3369710L, 3369710L, 3369710L, 3369710L, 3138990L, 3138990L,
3138990L, 3138990L, 3369710L, 3369710L, 3369710L, 3369710L, 3104497L,
3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
3104497L, 3104497L, 3138990L, 3138990L, 3138990L, 3138990L, 3322156L,
3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
3322156L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
3104497L, 3104497L, 3104497L, 3104497L, 3146217L, 3146217L, 3146217L,
3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
3146217L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3138990L,
3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
3138990L, 3138990L, 3138990L, 3138990L, 3146217L, 3146217L, 3146217L,
3146217L, 3146217L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
3138990L, 3138990L, 3138990L, 3369710L, 3369710L, 3369710L, 3369710L,
3369710L, 3369710L, 3369710L, 3369710L, 3138990L, 3138990L, 3138990L,
3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
3138990L, 3138990L, 3138990L, 3138990L, 3104497L, 3104497L, 3104497L,
3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
3369710L, 3369710L, 3369710L, 3369710L, 3369710L, 3369710L, 3369710L,
3369710L, 3138990L, 3138990L, 3138990L, 3138990L, 3104497L, 3104497L,
3104497L, 3104497L, 3104497L, 3816413L, 3816413L, 3816413L, 3816413L,
3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
3816413L, 3816413L, 3816413L, 3322156L, 3322156L, 3322156L, 3322156L,
3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3146217L, 3146217L,
3146217L, 3146217L, 3146217L, 3322156L, 3322156L, 3322156L, 3322156L,
3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3138990L, 3138990L,
3138990L, 3138990L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
3322156L, 3322156L, 3322156L, 3322156L, 3146217L, 3146217L, 3146217L,
3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3322156L,
3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
3322156L, 3322156L, 3322156L, 3322156L, 3104497L, 3104497L, 3104497L,
3104497L, 3104497L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
3322156L, 3322156L, 3322156L, 3322156L, 3104497L, 3104497L, 3104497L,
3104497L, 3104497L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
3816413L, 3816413L, 3816413L, 3146217L, 3146217L, 3146217L, 3146217L,
3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3322156L,
3322156L, 3322156L, 3322156L, 3816413L, 3816413L, 3816413L, 3816413L,
3816413L, 3322156L, 3322156L, 3322156L, 3322156L, 3816413L, 3816413L,
3816413L, 3816413L, 3816413L, 3146217L, 3146217L, 3146217L, 3146217L,
3146217L, 3322156L, 3322156L, 3322156L, 3322156L, 3146217L, 3146217L,
3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
3146217L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L),
WEEK = structure(c(14620, 14620, 14620, 14620, 14620, 14620,
14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
14620, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
14627, 14627, 14627, 14627, 14627, 14634, 14634, 14634, 14634,
14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641,
14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641,
14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641,
14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641,
14641, 14641, 14641, 14641, 14648, 14648, 14648, 14648, 14648,
14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648,
14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648,
14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648,
14648, 14648, 14648, 14648, 14648, 14669, 14669, 14669, 14669,
14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669,
14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669,
14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669,
14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669,
14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669,
14669, 14669, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
14676, 14676, 14676, 14676, 14676, 14676, 14683, 14683, 14683,
14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683,
14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683,
14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683,
14683, 14683, 14683, 14683, 14690, 14690, 14690, 14690, 14690,
14690, 14690, 14690, 14690, 14690, 14690, 14690, 14690, 14690,
14690, 14690, 14690, 14690, 14690, 14690, 14690, 14690, 14690,
14690, 14690, 14690, 14690, 14690, 14690, 14690, 14690, 14697,
14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697,
14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697,
14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697,
14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697,
14697, 14697, 14697, 14697, 14697, 14697, 14704, 14704, 14704,
14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
14704, 14704), class = "Date"), ITEM = c(526L, 526L, 526L,
526L, 526L, 2890L, 2890L, 2890L, 2890L, 2890L, 2933L, 2933L,
2933L, 2933L, 2933L, 548L, 548L, 548L, 548L, 548L, 106L,
106L, 106L, 106L, 106L, 6320L, 6320L, 6320L, 6320L, 6610L,
6610L, 6610L, 6610L, 7028L, 7028L, 7028L, 7028L, 7028L, 7414L,
7414L, 7414L, 7414L, 7414L, 1279L, 1279L, 1279L, 1279L, 1279L,
1425L, 1425L, 1425L, 1425L, 1425L, 6080L, 6080L, 6080L, 6080L,
1937L, 1937L, 1937L, 1937L, 1937L, 1L, 1L, 1L, 1L, 11321L,
11321L, 11321L, 11321L, 12064L, 12064L, 12064L, 12064L, 3L,
3L, 3L, 3L, 3448L, 3448L, 3448L, 3448L, 900L, 900L, 900L,
900L, 900L, 2202L, 2202L, 2202L, 2202L, 7363L, 7363L, 7363L,
7363L, 7362L, 7362L, 7362L, 7362L, 5995L, 5995L, 5995L, 5995L,
1251L, 1251L, 1251L, 1251L, 1251L, 76243L, 76243L, 76243L,
76243L, 76243L, 620L, 620L, 620L, 620L, 620L, 625L, 625L,
625L, 625L, 625L, 668L, 668L, 668L, 668L, 668L, 626L, 626L,
626L, 626L, 626L, 14772L, 14772L, 14772L, 14772L, 14772L,
27526L, 27526L, 27526L, 27526L, 27526L, 6320L, 6320L, 6320L,
6320L, 6500L, 6500L, 6500L, 6500L, 6560L, 6560L, 6560L, 6560L,
6610L, 6610L, 6610L, 6610L, 600L, 600L, 600L, 600L, 13902L,
13902L, 13902L, 13902L, 822L, 822L, 822L, 822L, 822L, 2178L,
2178L, 2178L, 2178L, 900L, 900L, 900L, 900L, 900L, 900L,
900L, 900L, 900L, 2202L, 2202L, 2202L, 2202L, 35202L, 35202L,
35202L, 35202L, 540L, 540L, 540L, 540L, 540L, 540L, 540L,
540L, 540L, 540L, 7363L, 7363L, 7363L, 7363L, 8312L, 8312L,
8312L, 8312L, 7362L, 7362L, 7362L, 7362L, 11L, 11L, 11L,
11L, 1251L, 1251L, 1251L, 1251L, 40268L, 40268L, 40268L,
40268L, 26037L, 26037L, 26037L, 26037L, 26037L, 26037L, 26037L,
26037L, 26037L, 4116L, 4116L, 4116L, 4116L, 4116L, 7789L,
7789L, 7789L, 7789L, 7028L, 7028L, 7028L, 7028L, 7028L, 1302L,
1302L, 1302L, 1302L, 13301L, 13301L, 13301L, 13301L, 240L,
240L, 240L, 240L, 240L, 24444L, 24444L, 24444L, 24444L, 900L,
900L, 900L, 900L, 960L, 960L, 960L, 960L, 2202L, 2202L, 2202L,
2202L, 38249L, 38249L, 38249L, 38249L, 28350L, 28350L, 28350L,
28350L, 28350L, 8358L, 8358L, 8358L, 8358L, 8358L, 5995L,
5995L, 5995L, 5995L, 40224L, 40224L, 40224L, 40224L, 40230L,
40230L, 40230L, 40230L, 40267L, 40267L, 40267L, 40267L, 40268L,
40268L, 40268L, 40268L, 42238L, 42238L, 42238L, 42238L, 42238L,
42274L, 42274L, 42274L, 42274L, 42274L, 42274L, 42274L, 42274L,
42274L, 42274L, 94L, 94L, 94L, 94L, 94L, 95L, 95L, 95L, 95L,
95L, 97L, 97L, 97L, 97L, 97L, 98L, 98L, 98L, 98L, 98L, 1278L,
1278L, 1278L, 1278L, 1278L, 1278L, 1278L, 1278L, 1278L, 1278L,
6346L, 6346L, 6346L, 6346L, 6346L, 6346L, 6346L, 6346L, 6346L,
6346L, 81014L, 81014L, 81014L, 81014L, 81014L, 15990L, 15990L,
15990L, 15990L, 15990L, 8321L, 8321L, 8321L, 8321L, 8321L,
8321L, 8321L, 8321L, 8321L, 8321L, 27509L, 27509L, 27509L,
27509L, 27512L, 27512L, 27512L, 27512L, 27551L, 27551L, 27551L,
27551L, 900L, 900L, 900L, 900L, 900L, 960L, 960L, 960L, 960L,
2202L, 2202L, 2202L, 2202L, 1111L, 1111L, 1111L, 1111L, 1081L,
1081L, 1081L, 1081L, 29422L, 29422L, 29422L, 29422L, 13830L,
13830L, 13830L, 13830L, 6080L, 6080L, 6080L, 6080L, 6L, 6L,
6L, 6L, 126L, 126L, 126L, 126L, 3637L, 3637L, 3637L, 3637L,
2202L, 2202L, 2202L, 2202L, 7357L, 7357L, 7357L, 7357L, 7357L,
7363L, 7363L, 7363L, 7363L, 7363L, 85121L, 85121L, 85121L,
85121L, 40268L, 40268L, 40268L, 40268L, 42238L, 42238L, 42238L,
42238L, 96166L, 96166L, 96166L, 96166L, 96166L, 80997L, 80997L,
80997L, 80997L, 80997L, 2891L, 2891L, 2891L, 2891L, 2891L,
5169L, 5169L, 5169L, 5169L, 5169L, 27536L, 27536L, 27536L,
27536L, 27536L, 6150L, 6150L, 6150L, 6150L, 6150L, 31846L,
31846L, 31846L, 31846L, 31846L, 42753L, 42753L, 42753L, 42753L,
42753L, 1302L, 1302L, 1302L, 1302L, 2663L, 2663L, 2663L,
2663L, 2663L, 900L, 900L, 900L, 900L, 900L, 900L, 900L, 900L,
900L, 2202L, 2202L, 2202L, 2202L, 2202L, 18285L, 18285L,
18285L, 18285L, 52531L, 52531L, 52531L, 52531L, 52531L, 7152L,
7152L, 7152L, 7152L, 1279L, 1279L, 1279L, 1279L, 1279L, 1425L,
1425L, 1425L, 1425L, 1425L, 13830L, 13830L, 13830L, 13830L,
6080L, 6080L, 6080L, 6080L, 3637L, 3637L, 3637L, 3637L, 2202L,
2202L, 2202L, 2202L, 26134L, 26134L, 26134L, 26134L, 600L,
600L, 600L, 600L, 1302L, 1302L, 1302L, 1302L, 1327L, 1327L,
1327L, 1327L, 900L, 900L, 900L, 900L, 900L, 900L, 900L, 900L,
900L, 900L, 900L, 900L, 900L, 900L, 96166L, 96166L, 96166L,
96166L, 96166L, 2395L, 2395L, 2395L, 2395L, 2395L, 2890L,
2890L, 2890L, 2890L, 2890L, 2891L, 2891L, 2891L, 2891L, 2891L,
75L, 75L, 75L, 75L, 75L, 5346L, 5346L, 5346L, 5346L, 5346L,
600L, 600L, 600L, 600L, 65020L, 65020L, 65020L, 65020L, 65020L,
1261L, 1261L, 1261L, 1261L, 668L, 668L, 668L, 668L, 668L,
1425L, 1425L, 1425L, 1425L, 1425L, 600L, 600L, 600L, 600L,
900L, 900L, 900L, 900L, 900L, 900L, 900L, 900L, 900L, 900L,
900L, 900L, 900L, 900L, 362L, 362L, 362L, 362L, 40258L, 40258L,
40258L, 40258L, 40268L, 40268L, 40268L, 40268L, 2549L, 2549L,
2549L, 2549L, 94L, 94L, 94L, 94L, 94L, 96L, 96L, 96L, 96L,
96L, 97L, 97L, 97L, 97L, 97L, 132L, 132L, 132L, 132L, 132L
)), class = "data.frame", row.names = c(NA, -710L))









share|improve this question





























    1














    I have some data on individual purchases.



    In this data PANID is a person who bought a product on a particular week. In the sample I provide, there are 6 unique PANID's; so 6 people in total. I am trying to calculate the conditional probability that a PANID will repurchase a product a second time.



    For example:



    PANID 3104497 bought ITEM 7028 in WEEK 2010-01-11 and then again the same PANID bought the same ITEM in WEEK 2010-01-25. I am trying to figure out how to find the probability that they will buy that same item again (at any point in the data).



        PANID       WEEK ITEM
    1 3104497 2010-01-11 526
    2 3104497 2010-01-11 526
    3 3104497 2010-01-11 526
    4 3104497 2010-01-11 526
    5 3104497 2010-01-11 526
    6 3104497 2010-01-11 2890
    ...
    705 3146217 2010-04-05 97
    706 3146217 2010-04-05 132
    707 3146217 2010-04-05 132
    708 3146217 2010-04-05 132
    709 3146217 2010-04-05 132
    710 3146217 2010-04-05 132


    Data:



    df <- structure(list(PANID = c(3104497L, 3104497L, 3104497L, 3104497L, 
    3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
    3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
    3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
    3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
    3138990L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
    3104497L, 3104497L, 3104497L, 3104497L, 3146217L, 3146217L, 3146217L,
    3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
    3138990L, 3138990L, 3138990L, 3138990L, 3104497L, 3104497L, 3104497L,
    3104497L, 3104497L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
    3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
    3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
    3138990L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3138990L,
    3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
    3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
    3138990L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
    3104497L, 3104497L, 3104497L, 3104497L, 3146217L, 3146217L, 3146217L,
    3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
    3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
    3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
    3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3138990L,
    3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
    3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
    3138990L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
    3322156L, 3322156L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
    3369710L, 3369710L, 3369710L, 3369710L, 3146217L, 3146217L, 3146217L,
    3146217L, 3146217L, 3322156L, 3322156L, 3322156L, 3322156L, 3138990L,
    3138990L, 3138990L, 3138990L, 3369710L, 3369710L, 3369710L, 3369710L,
    3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
    3146217L, 3146217L, 3146217L, 3138990L, 3138990L, 3138990L, 3138990L,
    3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
    3138990L, 3369710L, 3369710L, 3369710L, 3369710L, 3369710L, 3369710L,
    3369710L, 3369710L, 3322156L, 3322156L, 3322156L, 3322156L, 3146217L,
    3146217L, 3146217L, 3146217L, 3146217L, 3322156L, 3322156L, 3322156L,
    3322156L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3138990L,
    3138990L, 3138990L, 3138990L, 3104497L, 3104497L, 3104497L, 3104497L,
    3104497L, 3322156L, 3322156L, 3322156L, 3322156L, 3138990L, 3138990L,
    3138990L, 3138990L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
    3322156L, 3322156L, 3322156L, 3322156L, 3369710L, 3369710L, 3369710L,
    3369710L, 3369710L, 3369710L, 3369710L, 3369710L, 3138990L, 3138990L,
    3138990L, 3138990L, 3369710L, 3369710L, 3369710L, 3369710L, 3104497L,
    3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
    3104497L, 3104497L, 3138990L, 3138990L, 3138990L, 3138990L, 3322156L,
    3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
    3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
    3322156L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
    3104497L, 3104497L, 3104497L, 3104497L, 3146217L, 3146217L, 3146217L,
    3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
    3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
    3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
    3146217L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
    3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
    3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
    3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
    3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
    3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3138990L,
    3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
    3138990L, 3138990L, 3138990L, 3138990L, 3146217L, 3146217L, 3146217L,
    3146217L, 3146217L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
    3138990L, 3138990L, 3138990L, 3369710L, 3369710L, 3369710L, 3369710L,
    3369710L, 3369710L, 3369710L, 3369710L, 3138990L, 3138990L, 3138990L,
    3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
    3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
    3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
    3138990L, 3138990L, 3138990L, 3138990L, 3104497L, 3104497L, 3104497L,
    3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
    3369710L, 3369710L, 3369710L, 3369710L, 3369710L, 3369710L, 3369710L,
    3369710L, 3138990L, 3138990L, 3138990L, 3138990L, 3104497L, 3104497L,
    3104497L, 3104497L, 3104497L, 3816413L, 3816413L, 3816413L, 3816413L,
    3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
    3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
    3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
    3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
    3816413L, 3816413L, 3816413L, 3322156L, 3322156L, 3322156L, 3322156L,
    3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3146217L, 3146217L,
    3146217L, 3146217L, 3146217L, 3322156L, 3322156L, 3322156L, 3322156L,
    3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3138990L, 3138990L,
    3138990L, 3138990L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
    3322156L, 3322156L, 3322156L, 3322156L, 3146217L, 3146217L, 3146217L,
    3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
    3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
    3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
    3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3322156L,
    3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
    3322156L, 3322156L, 3322156L, 3322156L, 3104497L, 3104497L, 3104497L,
    3104497L, 3104497L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
    3322156L, 3322156L, 3322156L, 3322156L, 3104497L, 3104497L, 3104497L,
    3104497L, 3104497L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
    3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
    3816413L, 3816413L, 3816413L, 3146217L, 3146217L, 3146217L, 3146217L,
    3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3322156L,
    3322156L, 3322156L, 3322156L, 3816413L, 3816413L, 3816413L, 3816413L,
    3816413L, 3322156L, 3322156L, 3322156L, 3322156L, 3816413L, 3816413L,
    3816413L, 3816413L, 3816413L, 3146217L, 3146217L, 3146217L, 3146217L,
    3146217L, 3322156L, 3322156L, 3322156L, 3322156L, 3146217L, 3146217L,
    3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
    3146217L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
    3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
    3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
    3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
    3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
    3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L),
    WEEK = structure(c(14620, 14620, 14620, 14620, 14620, 14620,
    14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
    14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
    14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
    14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
    14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
    14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
    14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
    14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
    14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
    14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
    14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
    14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
    14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
    14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
    14620, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
    14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
    14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
    14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
    14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
    14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
    14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
    14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
    14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
    14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
    14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
    14627, 14627, 14627, 14627, 14627, 14634, 14634, 14634, 14634,
    14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
    14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
    14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
    14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
    14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
    14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
    14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
    14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
    14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
    14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
    14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
    14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
    14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641,
    14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641,
    14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641,
    14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641,
    14641, 14641, 14641, 14641, 14648, 14648, 14648, 14648, 14648,
    14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648,
    14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648,
    14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648,
    14648, 14648, 14648, 14648, 14648, 14669, 14669, 14669, 14669,
    14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669,
    14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669,
    14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669,
    14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669,
    14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669,
    14669, 14669, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
    14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
    14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
    14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
    14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
    14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
    14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
    14676, 14676, 14676, 14676, 14676, 14676, 14683, 14683, 14683,
    14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683,
    14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683,
    14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683,
    14683, 14683, 14683, 14683, 14690, 14690, 14690, 14690, 14690,
    14690, 14690, 14690, 14690, 14690, 14690, 14690, 14690, 14690,
    14690, 14690, 14690, 14690, 14690, 14690, 14690, 14690, 14690,
    14690, 14690, 14690, 14690, 14690, 14690, 14690, 14690, 14697,
    14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697,
    14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697,
    14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697,
    14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697,
    14697, 14697, 14697, 14697, 14697, 14697, 14704, 14704, 14704,
    14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
    14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
    14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
    14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
    14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
    14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
    14704, 14704), class = "Date"), ITEM = c(526L, 526L, 526L,
    526L, 526L, 2890L, 2890L, 2890L, 2890L, 2890L, 2933L, 2933L,
    2933L, 2933L, 2933L, 548L, 548L, 548L, 548L, 548L, 106L,
    106L, 106L, 106L, 106L, 6320L, 6320L, 6320L, 6320L, 6610L,
    6610L, 6610L, 6610L, 7028L, 7028L, 7028L, 7028L, 7028L, 7414L,
    7414L, 7414L, 7414L, 7414L, 1279L, 1279L, 1279L, 1279L, 1279L,
    1425L, 1425L, 1425L, 1425L, 1425L, 6080L, 6080L, 6080L, 6080L,
    1937L, 1937L, 1937L, 1937L, 1937L, 1L, 1L, 1L, 1L, 11321L,
    11321L, 11321L, 11321L, 12064L, 12064L, 12064L, 12064L, 3L,
    3L, 3L, 3L, 3448L, 3448L, 3448L, 3448L, 900L, 900L, 900L,
    900L, 900L, 2202L, 2202L, 2202L, 2202L, 7363L, 7363L, 7363L,
    7363L, 7362L, 7362L, 7362L, 7362L, 5995L, 5995L, 5995L, 5995L,
    1251L, 1251L, 1251L, 1251L, 1251L, 76243L, 76243L, 76243L,
    76243L, 76243L, 620L, 620L, 620L, 620L, 620L, 625L, 625L,
    625L, 625L, 625L, 668L, 668L, 668L, 668L, 668L, 626L, 626L,
    626L, 626L, 626L, 14772L, 14772L, 14772L, 14772L, 14772L,
    27526L, 27526L, 27526L, 27526L, 27526L, 6320L, 6320L, 6320L,
    6320L, 6500L, 6500L, 6500L, 6500L, 6560L, 6560L, 6560L, 6560L,
    6610L, 6610L, 6610L, 6610L, 600L, 600L, 600L, 600L, 13902L,
    13902L, 13902L, 13902L, 822L, 822L, 822L, 822L, 822L, 2178L,
    2178L, 2178L, 2178L, 900L, 900L, 900L, 900L, 900L, 900L,
    900L, 900L, 900L, 2202L, 2202L, 2202L, 2202L, 35202L, 35202L,
    35202L, 35202L, 540L, 540L, 540L, 540L, 540L, 540L, 540L,
    540L, 540L, 540L, 7363L, 7363L, 7363L, 7363L, 8312L, 8312L,
    8312L, 8312L, 7362L, 7362L, 7362L, 7362L, 11L, 11L, 11L,
    11L, 1251L, 1251L, 1251L, 1251L, 40268L, 40268L, 40268L,
    40268L, 26037L, 26037L, 26037L, 26037L, 26037L, 26037L, 26037L,
    26037L, 26037L, 4116L, 4116L, 4116L, 4116L, 4116L, 7789L,
    7789L, 7789L, 7789L, 7028L, 7028L, 7028L, 7028L, 7028L, 1302L,
    1302L, 1302L, 1302L, 13301L, 13301L, 13301L, 13301L, 240L,
    240L, 240L, 240L, 240L, 24444L, 24444L, 24444L, 24444L, 900L,
    900L, 900L, 900L, 960L, 960L, 960L, 960L, 2202L, 2202L, 2202L,
    2202L, 38249L, 38249L, 38249L, 38249L, 28350L, 28350L, 28350L,
    28350L, 28350L, 8358L, 8358L, 8358L, 8358L, 8358L, 5995L,
    5995L, 5995L, 5995L, 40224L, 40224L, 40224L, 40224L, 40230L,
    40230L, 40230L, 40230L, 40267L, 40267L, 40267L, 40267L, 40268L,
    40268L, 40268L, 40268L, 42238L, 42238L, 42238L, 42238L, 42238L,
    42274L, 42274L, 42274L, 42274L, 42274L, 42274L, 42274L, 42274L,
    42274L, 42274L, 94L, 94L, 94L, 94L, 94L, 95L, 95L, 95L, 95L,
    95L, 97L, 97L, 97L, 97L, 97L, 98L, 98L, 98L, 98L, 98L, 1278L,
    1278L, 1278L, 1278L, 1278L, 1278L, 1278L, 1278L, 1278L, 1278L,
    6346L, 6346L, 6346L, 6346L, 6346L, 6346L, 6346L, 6346L, 6346L,
    6346L, 81014L, 81014L, 81014L, 81014L, 81014L, 15990L, 15990L,
    15990L, 15990L, 15990L, 8321L, 8321L, 8321L, 8321L, 8321L,
    8321L, 8321L, 8321L, 8321L, 8321L, 27509L, 27509L, 27509L,
    27509L, 27512L, 27512L, 27512L, 27512L, 27551L, 27551L, 27551L,
    27551L, 900L, 900L, 900L, 900L, 900L, 960L, 960L, 960L, 960L,
    2202L, 2202L, 2202L, 2202L, 1111L, 1111L, 1111L, 1111L, 1081L,
    1081L, 1081L, 1081L, 29422L, 29422L, 29422L, 29422L, 13830L,
    13830L, 13830L, 13830L, 6080L, 6080L, 6080L, 6080L, 6L, 6L,
    6L, 6L, 126L, 126L, 126L, 126L, 3637L, 3637L, 3637L, 3637L,
    2202L, 2202L, 2202L, 2202L, 7357L, 7357L, 7357L, 7357L, 7357L,
    7363L, 7363L, 7363L, 7363L, 7363L, 85121L, 85121L, 85121L,
    85121L, 40268L, 40268L, 40268L, 40268L, 42238L, 42238L, 42238L,
    42238L, 96166L, 96166L, 96166L, 96166L, 96166L, 80997L, 80997L,
    80997L, 80997L, 80997L, 2891L, 2891L, 2891L, 2891L, 2891L,
    5169L, 5169L, 5169L, 5169L, 5169L, 27536L, 27536L, 27536L,
    27536L, 27536L, 6150L, 6150L, 6150L, 6150L, 6150L, 31846L,
    31846L, 31846L, 31846L, 31846L, 42753L, 42753L, 42753L, 42753L,
    42753L, 1302L, 1302L, 1302L, 1302L, 2663L, 2663L, 2663L,
    2663L, 2663L, 900L, 900L, 900L, 900L, 900L, 900L, 900L, 900L,
    900L, 2202L, 2202L, 2202L, 2202L, 2202L, 18285L, 18285L,
    18285L, 18285L, 52531L, 52531L, 52531L, 52531L, 52531L, 7152L,
    7152L, 7152L, 7152L, 1279L, 1279L, 1279L, 1279L, 1279L, 1425L,
    1425L, 1425L, 1425L, 1425L, 13830L, 13830L, 13830L, 13830L,
    6080L, 6080L, 6080L, 6080L, 3637L, 3637L, 3637L, 3637L, 2202L,
    2202L, 2202L, 2202L, 26134L, 26134L, 26134L, 26134L, 600L,
    600L, 600L, 600L, 1302L, 1302L, 1302L, 1302L, 1327L, 1327L,
    1327L, 1327L, 900L, 900L, 900L, 900L, 900L, 900L, 900L, 900L,
    900L, 900L, 900L, 900L, 900L, 900L, 96166L, 96166L, 96166L,
    96166L, 96166L, 2395L, 2395L, 2395L, 2395L, 2395L, 2890L,
    2890L, 2890L, 2890L, 2890L, 2891L, 2891L, 2891L, 2891L, 2891L,
    75L, 75L, 75L, 75L, 75L, 5346L, 5346L, 5346L, 5346L, 5346L,
    600L, 600L, 600L, 600L, 65020L, 65020L, 65020L, 65020L, 65020L,
    1261L, 1261L, 1261L, 1261L, 668L, 668L, 668L, 668L, 668L,
    1425L, 1425L, 1425L, 1425L, 1425L, 600L, 600L, 600L, 600L,
    900L, 900L, 900L, 900L, 900L, 900L, 900L, 900L, 900L, 900L,
    900L, 900L, 900L, 900L, 362L, 362L, 362L, 362L, 40258L, 40258L,
    40258L, 40258L, 40268L, 40268L, 40268L, 40268L, 2549L, 2549L,
    2549L, 2549L, 94L, 94L, 94L, 94L, 94L, 96L, 96L, 96L, 96L,
    96L, 97L, 97L, 97L, 97L, 97L, 132L, 132L, 132L, 132L, 132L
    )), class = "data.frame", row.names = c(NA, -710L))









    share|improve this question



























      1












      1








      1


      1





      I have some data on individual purchases.



      In this data PANID is a person who bought a product on a particular week. In the sample I provide, there are 6 unique PANID's; so 6 people in total. I am trying to calculate the conditional probability that a PANID will repurchase a product a second time.



      For example:



      PANID 3104497 bought ITEM 7028 in WEEK 2010-01-11 and then again the same PANID bought the same ITEM in WEEK 2010-01-25. I am trying to figure out how to find the probability that they will buy that same item again (at any point in the data).



          PANID       WEEK ITEM
      1 3104497 2010-01-11 526
      2 3104497 2010-01-11 526
      3 3104497 2010-01-11 526
      4 3104497 2010-01-11 526
      5 3104497 2010-01-11 526
      6 3104497 2010-01-11 2890
      ...
      705 3146217 2010-04-05 97
      706 3146217 2010-04-05 132
      707 3146217 2010-04-05 132
      708 3146217 2010-04-05 132
      709 3146217 2010-04-05 132
      710 3146217 2010-04-05 132


      Data:



      df <- structure(list(PANID = c(3104497L, 3104497L, 3104497L, 3104497L, 
      3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3138990L, 3138990L, 3138990L, 3138990L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
      3322156L, 3322156L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3369710L, 3369710L, 3369710L, 3369710L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3322156L, 3322156L, 3322156L, 3322156L, 3138990L,
      3138990L, 3138990L, 3138990L, 3369710L, 3369710L, 3369710L, 3369710L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3369710L, 3369710L, 3369710L, 3369710L, 3369710L, 3369710L,
      3369710L, 3369710L, 3322156L, 3322156L, 3322156L, 3322156L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3322156L, 3322156L, 3322156L,
      3322156L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3138990L,
      3138990L, 3138990L, 3138990L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3322156L, 3322156L, 3322156L, 3322156L, 3138990L, 3138990L,
      3138990L, 3138990L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3322156L, 3322156L, 3322156L, 3322156L, 3369710L, 3369710L, 3369710L,
      3369710L, 3369710L, 3369710L, 3369710L, 3369710L, 3138990L, 3138990L,
      3138990L, 3138990L, 3369710L, 3369710L, 3369710L, 3369710L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3138990L, 3138990L, 3138990L, 3138990L, 3322156L,
      3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
      3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
      3322156L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3369710L, 3369710L, 3369710L, 3369710L,
      3369710L, 3369710L, 3369710L, 3369710L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3369710L, 3369710L, 3369710L, 3369710L, 3369710L, 3369710L, 3369710L,
      3369710L, 3138990L, 3138990L, 3138990L, 3138990L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3816413L, 3816413L, 3816413L, 3816413L,
      3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
      3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
      3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
      3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
      3816413L, 3816413L, 3816413L, 3322156L, 3322156L, 3322156L, 3322156L,
      3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3322156L, 3322156L, 3322156L, 3322156L,
      3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3138990L, 3138990L,
      3138990L, 3138990L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3322156L, 3322156L, 3322156L, 3322156L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3322156L,
      3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
      3322156L, 3322156L, 3322156L, 3322156L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3322156L, 3322156L, 3322156L, 3322156L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
      3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
      3816413L, 3816413L, 3816413L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3322156L,
      3322156L, 3322156L, 3322156L, 3816413L, 3816413L, 3816413L, 3816413L,
      3816413L, 3322156L, 3322156L, 3322156L, 3322156L, 3816413L, 3816413L,
      3816413L, 3816413L, 3816413L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3322156L, 3322156L, 3322156L, 3322156L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
      3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
      3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L),
      WEEK = structure(c(14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641,
      14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641,
      14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641,
      14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641,
      14641, 14641, 14641, 14641, 14648, 14648, 14648, 14648, 14648,
      14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648,
      14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648,
      14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648,
      14648, 14648, 14648, 14648, 14648, 14669, 14669, 14669, 14669,
      14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669,
      14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669,
      14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669,
      14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669,
      14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669,
      14669, 14669, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
      14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
      14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
      14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
      14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
      14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
      14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
      14676, 14676, 14676, 14676, 14676, 14676, 14683, 14683, 14683,
      14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683,
      14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683,
      14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683,
      14683, 14683, 14683, 14683, 14690, 14690, 14690, 14690, 14690,
      14690, 14690, 14690, 14690, 14690, 14690, 14690, 14690, 14690,
      14690, 14690, 14690, 14690, 14690, 14690, 14690, 14690, 14690,
      14690, 14690, 14690, 14690, 14690, 14690, 14690, 14690, 14697,
      14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697,
      14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697,
      14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697,
      14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697,
      14697, 14697, 14697, 14697, 14697, 14697, 14704, 14704, 14704,
      14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
      14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
      14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
      14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
      14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
      14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
      14704, 14704), class = "Date"), ITEM = c(526L, 526L, 526L,
      526L, 526L, 2890L, 2890L, 2890L, 2890L, 2890L, 2933L, 2933L,
      2933L, 2933L, 2933L, 548L, 548L, 548L, 548L, 548L, 106L,
      106L, 106L, 106L, 106L, 6320L, 6320L, 6320L, 6320L, 6610L,
      6610L, 6610L, 6610L, 7028L, 7028L, 7028L, 7028L, 7028L, 7414L,
      7414L, 7414L, 7414L, 7414L, 1279L, 1279L, 1279L, 1279L, 1279L,
      1425L, 1425L, 1425L, 1425L, 1425L, 6080L, 6080L, 6080L, 6080L,
      1937L, 1937L, 1937L, 1937L, 1937L, 1L, 1L, 1L, 1L, 11321L,
      11321L, 11321L, 11321L, 12064L, 12064L, 12064L, 12064L, 3L,
      3L, 3L, 3L, 3448L, 3448L, 3448L, 3448L, 900L, 900L, 900L,
      900L, 900L, 2202L, 2202L, 2202L, 2202L, 7363L, 7363L, 7363L,
      7363L, 7362L, 7362L, 7362L, 7362L, 5995L, 5995L, 5995L, 5995L,
      1251L, 1251L, 1251L, 1251L, 1251L, 76243L, 76243L, 76243L,
      76243L, 76243L, 620L, 620L, 620L, 620L, 620L, 625L, 625L,
      625L, 625L, 625L, 668L, 668L, 668L, 668L, 668L, 626L, 626L,
      626L, 626L, 626L, 14772L, 14772L, 14772L, 14772L, 14772L,
      27526L, 27526L, 27526L, 27526L, 27526L, 6320L, 6320L, 6320L,
      6320L, 6500L, 6500L, 6500L, 6500L, 6560L, 6560L, 6560L, 6560L,
      6610L, 6610L, 6610L, 6610L, 600L, 600L, 600L, 600L, 13902L,
      13902L, 13902L, 13902L, 822L, 822L, 822L, 822L, 822L, 2178L,
      2178L, 2178L, 2178L, 900L, 900L, 900L, 900L, 900L, 900L,
      900L, 900L, 900L, 2202L, 2202L, 2202L, 2202L, 35202L, 35202L,
      35202L, 35202L, 540L, 540L, 540L, 540L, 540L, 540L, 540L,
      540L, 540L, 540L, 7363L, 7363L, 7363L, 7363L, 8312L, 8312L,
      8312L, 8312L, 7362L, 7362L, 7362L, 7362L, 11L, 11L, 11L,
      11L, 1251L, 1251L, 1251L, 1251L, 40268L, 40268L, 40268L,
      40268L, 26037L, 26037L, 26037L, 26037L, 26037L, 26037L, 26037L,
      26037L, 26037L, 4116L, 4116L, 4116L, 4116L, 4116L, 7789L,
      7789L, 7789L, 7789L, 7028L, 7028L, 7028L, 7028L, 7028L, 1302L,
      1302L, 1302L, 1302L, 13301L, 13301L, 13301L, 13301L, 240L,
      240L, 240L, 240L, 240L, 24444L, 24444L, 24444L, 24444L, 900L,
      900L, 900L, 900L, 960L, 960L, 960L, 960L, 2202L, 2202L, 2202L,
      2202L, 38249L, 38249L, 38249L, 38249L, 28350L, 28350L, 28350L,
      28350L, 28350L, 8358L, 8358L, 8358L, 8358L, 8358L, 5995L,
      5995L, 5995L, 5995L, 40224L, 40224L, 40224L, 40224L, 40230L,
      40230L, 40230L, 40230L, 40267L, 40267L, 40267L, 40267L, 40268L,
      40268L, 40268L, 40268L, 42238L, 42238L, 42238L, 42238L, 42238L,
      42274L, 42274L, 42274L, 42274L, 42274L, 42274L, 42274L, 42274L,
      42274L, 42274L, 94L, 94L, 94L, 94L, 94L, 95L, 95L, 95L, 95L,
      95L, 97L, 97L, 97L, 97L, 97L, 98L, 98L, 98L, 98L, 98L, 1278L,
      1278L, 1278L, 1278L, 1278L, 1278L, 1278L, 1278L, 1278L, 1278L,
      6346L, 6346L, 6346L, 6346L, 6346L, 6346L, 6346L, 6346L, 6346L,
      6346L, 81014L, 81014L, 81014L, 81014L, 81014L, 15990L, 15990L,
      15990L, 15990L, 15990L, 8321L, 8321L, 8321L, 8321L, 8321L,
      8321L, 8321L, 8321L, 8321L, 8321L, 27509L, 27509L, 27509L,
      27509L, 27512L, 27512L, 27512L, 27512L, 27551L, 27551L, 27551L,
      27551L, 900L, 900L, 900L, 900L, 900L, 960L, 960L, 960L, 960L,
      2202L, 2202L, 2202L, 2202L, 1111L, 1111L, 1111L, 1111L, 1081L,
      1081L, 1081L, 1081L, 29422L, 29422L, 29422L, 29422L, 13830L,
      13830L, 13830L, 13830L, 6080L, 6080L, 6080L, 6080L, 6L, 6L,
      6L, 6L, 126L, 126L, 126L, 126L, 3637L, 3637L, 3637L, 3637L,
      2202L, 2202L, 2202L, 2202L, 7357L, 7357L, 7357L, 7357L, 7357L,
      7363L, 7363L, 7363L, 7363L, 7363L, 85121L, 85121L, 85121L,
      85121L, 40268L, 40268L, 40268L, 40268L, 42238L, 42238L, 42238L,
      42238L, 96166L, 96166L, 96166L, 96166L, 96166L, 80997L, 80997L,
      80997L, 80997L, 80997L, 2891L, 2891L, 2891L, 2891L, 2891L,
      5169L, 5169L, 5169L, 5169L, 5169L, 27536L, 27536L, 27536L,
      27536L, 27536L, 6150L, 6150L, 6150L, 6150L, 6150L, 31846L,
      31846L, 31846L, 31846L, 31846L, 42753L, 42753L, 42753L, 42753L,
      42753L, 1302L, 1302L, 1302L, 1302L, 2663L, 2663L, 2663L,
      2663L, 2663L, 900L, 900L, 900L, 900L, 900L, 900L, 900L, 900L,
      900L, 2202L, 2202L, 2202L, 2202L, 2202L, 18285L, 18285L,
      18285L, 18285L, 52531L, 52531L, 52531L, 52531L, 52531L, 7152L,
      7152L, 7152L, 7152L, 1279L, 1279L, 1279L, 1279L, 1279L, 1425L,
      1425L, 1425L, 1425L, 1425L, 13830L, 13830L, 13830L, 13830L,
      6080L, 6080L, 6080L, 6080L, 3637L, 3637L, 3637L, 3637L, 2202L,
      2202L, 2202L, 2202L, 26134L, 26134L, 26134L, 26134L, 600L,
      600L, 600L, 600L, 1302L, 1302L, 1302L, 1302L, 1327L, 1327L,
      1327L, 1327L, 900L, 900L, 900L, 900L, 900L, 900L, 900L, 900L,
      900L, 900L, 900L, 900L, 900L, 900L, 96166L, 96166L, 96166L,
      96166L, 96166L, 2395L, 2395L, 2395L, 2395L, 2395L, 2890L,
      2890L, 2890L, 2890L, 2890L, 2891L, 2891L, 2891L, 2891L, 2891L,
      75L, 75L, 75L, 75L, 75L, 5346L, 5346L, 5346L, 5346L, 5346L,
      600L, 600L, 600L, 600L, 65020L, 65020L, 65020L, 65020L, 65020L,
      1261L, 1261L, 1261L, 1261L, 668L, 668L, 668L, 668L, 668L,
      1425L, 1425L, 1425L, 1425L, 1425L, 600L, 600L, 600L, 600L,
      900L, 900L, 900L, 900L, 900L, 900L, 900L, 900L, 900L, 900L,
      900L, 900L, 900L, 900L, 362L, 362L, 362L, 362L, 40258L, 40258L,
      40258L, 40258L, 40268L, 40268L, 40268L, 40268L, 2549L, 2549L,
      2549L, 2549L, 94L, 94L, 94L, 94L, 94L, 96L, 96L, 96L, 96L,
      96L, 97L, 97L, 97L, 97L, 97L, 132L, 132L, 132L, 132L, 132L
      )), class = "data.frame", row.names = c(NA, -710L))









      share|improve this question















      I have some data on individual purchases.



      In this data PANID is a person who bought a product on a particular week. In the sample I provide, there are 6 unique PANID's; so 6 people in total. I am trying to calculate the conditional probability that a PANID will repurchase a product a second time.



      For example:



      PANID 3104497 bought ITEM 7028 in WEEK 2010-01-11 and then again the same PANID bought the same ITEM in WEEK 2010-01-25. I am trying to figure out how to find the probability that they will buy that same item again (at any point in the data).



          PANID       WEEK ITEM
      1 3104497 2010-01-11 526
      2 3104497 2010-01-11 526
      3 3104497 2010-01-11 526
      4 3104497 2010-01-11 526
      5 3104497 2010-01-11 526
      6 3104497 2010-01-11 2890
      ...
      705 3146217 2010-04-05 97
      706 3146217 2010-04-05 132
      707 3146217 2010-04-05 132
      708 3146217 2010-04-05 132
      709 3146217 2010-04-05 132
      710 3146217 2010-04-05 132


      Data:



      df <- structure(list(PANID = c(3104497L, 3104497L, 3104497L, 3104497L, 
      3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3138990L, 3138990L, 3138990L, 3138990L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
      3322156L, 3322156L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3369710L, 3369710L, 3369710L, 3369710L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3322156L, 3322156L, 3322156L, 3322156L, 3138990L,
      3138990L, 3138990L, 3138990L, 3369710L, 3369710L, 3369710L, 3369710L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3369710L, 3369710L, 3369710L, 3369710L, 3369710L, 3369710L,
      3369710L, 3369710L, 3322156L, 3322156L, 3322156L, 3322156L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3322156L, 3322156L, 3322156L,
      3322156L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3138990L,
      3138990L, 3138990L, 3138990L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3322156L, 3322156L, 3322156L, 3322156L, 3138990L, 3138990L,
      3138990L, 3138990L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3322156L, 3322156L, 3322156L, 3322156L, 3369710L, 3369710L, 3369710L,
      3369710L, 3369710L, 3369710L, 3369710L, 3369710L, 3138990L, 3138990L,
      3138990L, 3138990L, 3369710L, 3369710L, 3369710L, 3369710L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3138990L, 3138990L, 3138990L, 3138990L, 3322156L,
      3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
      3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
      3322156L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3369710L, 3369710L, 3369710L, 3369710L,
      3369710L, 3369710L, 3369710L, 3369710L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L, 3104497L,
      3369710L, 3369710L, 3369710L, 3369710L, 3369710L, 3369710L, 3369710L,
      3369710L, 3138990L, 3138990L, 3138990L, 3138990L, 3104497L, 3104497L,
      3104497L, 3104497L, 3104497L, 3816413L, 3816413L, 3816413L, 3816413L,
      3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
      3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
      3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
      3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
      3816413L, 3816413L, 3816413L, 3322156L, 3322156L, 3322156L, 3322156L,
      3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3322156L, 3322156L, 3322156L, 3322156L,
      3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3138990L, 3138990L,
      3138990L, 3138990L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3322156L, 3322156L, 3322156L, 3322156L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L,
      3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3138990L, 3322156L,
      3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
      3322156L, 3322156L, 3322156L, 3322156L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3322156L, 3322156L, 3322156L, 3322156L, 3104497L, 3104497L, 3104497L,
      3104497L, 3104497L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
      3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L, 3816413L,
      3816413L, 3816413L, 3816413L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3322156L,
      3322156L, 3322156L, 3322156L, 3816413L, 3816413L, 3816413L, 3816413L,
      3816413L, 3322156L, 3322156L, 3322156L, 3322156L, 3816413L, 3816413L,
      3816413L, 3816413L, 3816413L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3322156L, 3322156L, 3322156L, 3322156L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
      3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
      3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L, 3322156L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L,
      3146217L, 3146217L, 3146217L, 3146217L, 3146217L, 3146217L),
      WEEK = structure(c(14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620, 14620,
      14620, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627, 14627,
      14627, 14627, 14627, 14627, 14627, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634, 14634,
      14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641,
      14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641,
      14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641,
      14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641, 14641,
      14641, 14641, 14641, 14641, 14648, 14648, 14648, 14648, 14648,
      14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648,
      14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648,
      14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648, 14648,
      14648, 14648, 14648, 14648, 14648, 14669, 14669, 14669, 14669,
      14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669,
      14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669,
      14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669,
      14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669,
      14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669, 14669,
      14669, 14669, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
      14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
      14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
      14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
      14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
      14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
      14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676, 14676,
      14676, 14676, 14676, 14676, 14676, 14676, 14683, 14683, 14683,
      14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683,
      14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683,
      14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683, 14683,
      14683, 14683, 14683, 14683, 14690, 14690, 14690, 14690, 14690,
      14690, 14690, 14690, 14690, 14690, 14690, 14690, 14690, 14690,
      14690, 14690, 14690, 14690, 14690, 14690, 14690, 14690, 14690,
      14690, 14690, 14690, 14690, 14690, 14690, 14690, 14690, 14697,
      14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697,
      14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697,
      14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697,
      14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697, 14697,
      14697, 14697, 14697, 14697, 14697, 14697, 14704, 14704, 14704,
      14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
      14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
      14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
      14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
      14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
      14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704, 14704,
      14704, 14704), class = "Date"), ITEM = c(526L, 526L, 526L,
      526L, 526L, 2890L, 2890L, 2890L, 2890L, 2890L, 2933L, 2933L,
      2933L, 2933L, 2933L, 548L, 548L, 548L, 548L, 548L, 106L,
      106L, 106L, 106L, 106L, 6320L, 6320L, 6320L, 6320L, 6610L,
      6610L, 6610L, 6610L, 7028L, 7028L, 7028L, 7028L, 7028L, 7414L,
      7414L, 7414L, 7414L, 7414L, 1279L, 1279L, 1279L, 1279L, 1279L,
      1425L, 1425L, 1425L, 1425L, 1425L, 6080L, 6080L, 6080L, 6080L,
      1937L, 1937L, 1937L, 1937L, 1937L, 1L, 1L, 1L, 1L, 11321L,
      11321L, 11321L, 11321L, 12064L, 12064L, 12064L, 12064L, 3L,
      3L, 3L, 3L, 3448L, 3448L, 3448L, 3448L, 900L, 900L, 900L,
      900L, 900L, 2202L, 2202L, 2202L, 2202L, 7363L, 7363L, 7363L,
      7363L, 7362L, 7362L, 7362L, 7362L, 5995L, 5995L, 5995L, 5995L,
      1251L, 1251L, 1251L, 1251L, 1251L, 76243L, 76243L, 76243L,
      76243L, 76243L, 620L, 620L, 620L, 620L, 620L, 625L, 625L,
      625L, 625L, 625L, 668L, 668L, 668L, 668L, 668L, 626L, 626L,
      626L, 626L, 626L, 14772L, 14772L, 14772L, 14772L, 14772L,
      27526L, 27526L, 27526L, 27526L, 27526L, 6320L, 6320L, 6320L,
      6320L, 6500L, 6500L, 6500L, 6500L, 6560L, 6560L, 6560L, 6560L,
      6610L, 6610L, 6610L, 6610L, 600L, 600L, 600L, 600L, 13902L,
      13902L, 13902L, 13902L, 822L, 822L, 822L, 822L, 822L, 2178L,
      2178L, 2178L, 2178L, 900L, 900L, 900L, 900L, 900L, 900L,
      900L, 900L, 900L, 2202L, 2202L, 2202L, 2202L, 35202L, 35202L,
      35202L, 35202L, 540L, 540L, 540L, 540L, 540L, 540L, 540L,
      540L, 540L, 540L, 7363L, 7363L, 7363L, 7363L, 8312L, 8312L,
      8312L, 8312L, 7362L, 7362L, 7362L, 7362L, 11L, 11L, 11L,
      11L, 1251L, 1251L, 1251L, 1251L, 40268L, 40268L, 40268L,
      40268L, 26037L, 26037L, 26037L, 26037L, 26037L, 26037L, 26037L,
      26037L, 26037L, 4116L, 4116L, 4116L, 4116L, 4116L, 7789L,
      7789L, 7789L, 7789L, 7028L, 7028L, 7028L, 7028L, 7028L, 1302L,
      1302L, 1302L, 1302L, 13301L, 13301L, 13301L, 13301L, 240L,
      240L, 240L, 240L, 240L, 24444L, 24444L, 24444L, 24444L, 900L,
      900L, 900L, 900L, 960L, 960L, 960L, 960L, 2202L, 2202L, 2202L,
      2202L, 38249L, 38249L, 38249L, 38249L, 28350L, 28350L, 28350L,
      28350L, 28350L, 8358L, 8358L, 8358L, 8358L, 8358L, 5995L,
      5995L, 5995L, 5995L, 40224L, 40224L, 40224L, 40224L, 40230L,
      40230L, 40230L, 40230L, 40267L, 40267L, 40267L, 40267L, 40268L,
      40268L, 40268L, 40268L, 42238L, 42238L, 42238L, 42238L, 42238L,
      42274L, 42274L, 42274L, 42274L, 42274L, 42274L, 42274L, 42274L,
      42274L, 42274L, 94L, 94L, 94L, 94L, 94L, 95L, 95L, 95L, 95L,
      95L, 97L, 97L, 97L, 97L, 97L, 98L, 98L, 98L, 98L, 98L, 1278L,
      1278L, 1278L, 1278L, 1278L, 1278L, 1278L, 1278L, 1278L, 1278L,
      6346L, 6346L, 6346L, 6346L, 6346L, 6346L, 6346L, 6346L, 6346L,
      6346L, 81014L, 81014L, 81014L, 81014L, 81014L, 15990L, 15990L,
      15990L, 15990L, 15990L, 8321L, 8321L, 8321L, 8321L, 8321L,
      8321L, 8321L, 8321L, 8321L, 8321L, 27509L, 27509L, 27509L,
      27509L, 27512L, 27512L, 27512L, 27512L, 27551L, 27551L, 27551L,
      27551L, 900L, 900L, 900L, 900L, 900L, 960L, 960L, 960L, 960L,
      2202L, 2202L, 2202L, 2202L, 1111L, 1111L, 1111L, 1111L, 1081L,
      1081L, 1081L, 1081L, 29422L, 29422L, 29422L, 29422L, 13830L,
      13830L, 13830L, 13830L, 6080L, 6080L, 6080L, 6080L, 6L, 6L,
      6L, 6L, 126L, 126L, 126L, 126L, 3637L, 3637L, 3637L, 3637L,
      2202L, 2202L, 2202L, 2202L, 7357L, 7357L, 7357L, 7357L, 7357L,
      7363L, 7363L, 7363L, 7363L, 7363L, 85121L, 85121L, 85121L,
      85121L, 40268L, 40268L, 40268L, 40268L, 42238L, 42238L, 42238L,
      42238L, 96166L, 96166L, 96166L, 96166L, 96166L, 80997L, 80997L,
      80997L, 80997L, 80997L, 2891L, 2891L, 2891L, 2891L, 2891L,
      5169L, 5169L, 5169L, 5169L, 5169L, 27536L, 27536L, 27536L,
      27536L, 27536L, 6150L, 6150L, 6150L, 6150L, 6150L, 31846L,
      31846L, 31846L, 31846L, 31846L, 42753L, 42753L, 42753L, 42753L,
      42753L, 1302L, 1302L, 1302L, 1302L, 2663L, 2663L, 2663L,
      2663L, 2663L, 900L, 900L, 900L, 900L, 900L, 900L, 900L, 900L,
      900L, 2202L, 2202L, 2202L, 2202L, 2202L, 18285L, 18285L,
      18285L, 18285L, 52531L, 52531L, 52531L, 52531L, 52531L, 7152L,
      7152L, 7152L, 7152L, 1279L, 1279L, 1279L, 1279L, 1279L, 1425L,
      1425L, 1425L, 1425L, 1425L, 13830L, 13830L, 13830L, 13830L,
      6080L, 6080L, 6080L, 6080L, 3637L, 3637L, 3637L, 3637L, 2202L,
      2202L, 2202L, 2202L, 26134L, 26134L, 26134L, 26134L, 600L,
      600L, 600L, 600L, 1302L, 1302L, 1302L, 1302L, 1327L, 1327L,
      1327L, 1327L, 900L, 900L, 900L, 900L, 900L, 900L, 900L, 900L,
      900L, 900L, 900L, 900L, 900L, 900L, 96166L, 96166L, 96166L,
      96166L, 96166L, 2395L, 2395L, 2395L, 2395L, 2395L, 2890L,
      2890L, 2890L, 2890L, 2890L, 2891L, 2891L, 2891L, 2891L, 2891L,
      75L, 75L, 75L, 75L, 75L, 5346L, 5346L, 5346L, 5346L, 5346L,
      600L, 600L, 600L, 600L, 65020L, 65020L, 65020L, 65020L, 65020L,
      1261L, 1261L, 1261L, 1261L, 668L, 668L, 668L, 668L, 668L,
      1425L, 1425L, 1425L, 1425L, 1425L, 600L, 600L, 600L, 600L,
      900L, 900L, 900L, 900L, 900L, 900L, 900L, 900L, 900L, 900L,
      900L, 900L, 900L, 900L, 362L, 362L, 362L, 362L, 40258L, 40258L,
      40258L, 40258L, 40268L, 40268L, 40268L, 40268L, 2549L, 2549L,
      2549L, 2549L, 94L, 94L, 94L, 94L, 94L, 96L, 96L, 96L, 96L,
      96L, 97L, 97L, 97L, 97L, 97L, 132L, 132L, 132L, 132L, 132L
      )), class = "data.frame", row.names = c(NA, -710L))






      r probability






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 17:43

























      asked Nov 11 at 22:47









      user113156

      7911417




      7911417
























          1 Answer
          1






          active

          oldest

          votes


















          1














          In the most general case, you expect something to happen X times in a given timeframe if it, well, happened X times in a comparable timeframe in the past.



          output <- aggregate(df$PANID, by = list(df$ITEM, df$PANID), length)
          colnames(output) <- c('ITEM', 'PANID', 'COUNT')
          k <- as.integer(max(df$WEEK) - min(df$WEEK)) / 7 # number of weeks in the data
          output$EXPECTATION <- output$COUNT / k
          head(output)

          #ITEM PANID COUNT EXPECTATION
          #1 106 3104497 5 0.4166667
          #2 240 3104497 5 0.4166667
          #3 526 3104497 5 0.4166667
          #4 548 3104497 5 0.4166667
          #5 900 3104497 5 0.4166667
          #6 1251 3104497 5 0.4166667


          That said, it's a very back-of-the-envelope calculation. With more data (e.g. with longer timeframes and greater temporal resolution), you could look into seasonality (it's not very reasonable to expect the sales to remain constant from month to month, right). If you had actual features describing PANIDs and ITEMs, you could look into possible relationships between those features and purchase counts. Really, there's hardly a limit to how sophisticated one could get with such analysis.






          share|improve this answer





















          • Thanks for your comment! Yes I have more time frame data, I am looking into seasonality of the data also (I know there exists some for some products, such as beer etc. - think Christmas, superbowl, 4th July - all spikes). I have data on PANID's such as how many cats, dogs,TV's, sex, age, race etc. (Its a rich dataset). I also have product information also. I was just looking for a begining point. My plan was to apply a Naive Bayes and then get a little more complicated with NN or which ever ML method would be suitable.
            – user113156
            Nov 11 at 23:13






          • 1




            If you have more data, you can totally try building a model of sorts. Those are very vast topics though! Look into forecasting with ARIMA models, this may help with the seasonality. And by all means this problem sounds like one amenable to ML; there's tons of relevant tutorials online. And if you get stuck, post a specific request for help!
            – 12b345b6b78
            Nov 11 at 23:19










          • At this stage I just wanted to get a Y variable because at the moment I have this rich panel level dataset but do not know exactly how to find an outcome variable for it. I think its super interesting to find out which PANELIDs / People are more likely to buy certain products based on past purchases but I just could not think of a way to find this Y variable... if this makes sense.
            – user113156
            Nov 11 at 23:26








          • 1




            I think it makes perfect sense to define the outcome variable as precisely the thing that you are trying to find out: probability of purchase (y) given customer profile and item (x)
            – 12b345b6b78
            Nov 11 at 23:30











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254007%2fprobability-of-purchasing-an-item-based-on-past-purchases%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          In the most general case, you expect something to happen X times in a given timeframe if it, well, happened X times in a comparable timeframe in the past.



          output <- aggregate(df$PANID, by = list(df$ITEM, df$PANID), length)
          colnames(output) <- c('ITEM', 'PANID', 'COUNT')
          k <- as.integer(max(df$WEEK) - min(df$WEEK)) / 7 # number of weeks in the data
          output$EXPECTATION <- output$COUNT / k
          head(output)

          #ITEM PANID COUNT EXPECTATION
          #1 106 3104497 5 0.4166667
          #2 240 3104497 5 0.4166667
          #3 526 3104497 5 0.4166667
          #4 548 3104497 5 0.4166667
          #5 900 3104497 5 0.4166667
          #6 1251 3104497 5 0.4166667


          That said, it's a very back-of-the-envelope calculation. With more data (e.g. with longer timeframes and greater temporal resolution), you could look into seasonality (it's not very reasonable to expect the sales to remain constant from month to month, right). If you had actual features describing PANIDs and ITEMs, you could look into possible relationships between those features and purchase counts. Really, there's hardly a limit to how sophisticated one could get with such analysis.






          share|improve this answer





















          • Thanks for your comment! Yes I have more time frame data, I am looking into seasonality of the data also (I know there exists some for some products, such as beer etc. - think Christmas, superbowl, 4th July - all spikes). I have data on PANID's such as how many cats, dogs,TV's, sex, age, race etc. (Its a rich dataset). I also have product information also. I was just looking for a begining point. My plan was to apply a Naive Bayes and then get a little more complicated with NN or which ever ML method would be suitable.
            – user113156
            Nov 11 at 23:13






          • 1




            If you have more data, you can totally try building a model of sorts. Those are very vast topics though! Look into forecasting with ARIMA models, this may help with the seasonality. And by all means this problem sounds like one amenable to ML; there's tons of relevant tutorials online. And if you get stuck, post a specific request for help!
            – 12b345b6b78
            Nov 11 at 23:19










          • At this stage I just wanted to get a Y variable because at the moment I have this rich panel level dataset but do not know exactly how to find an outcome variable for it. I think its super interesting to find out which PANELIDs / People are more likely to buy certain products based on past purchases but I just could not think of a way to find this Y variable... if this makes sense.
            – user113156
            Nov 11 at 23:26








          • 1




            I think it makes perfect sense to define the outcome variable as precisely the thing that you are trying to find out: probability of purchase (y) given customer profile and item (x)
            – 12b345b6b78
            Nov 11 at 23:30
















          1














          In the most general case, you expect something to happen X times in a given timeframe if it, well, happened X times in a comparable timeframe in the past.



          output <- aggregate(df$PANID, by = list(df$ITEM, df$PANID), length)
          colnames(output) <- c('ITEM', 'PANID', 'COUNT')
          k <- as.integer(max(df$WEEK) - min(df$WEEK)) / 7 # number of weeks in the data
          output$EXPECTATION <- output$COUNT / k
          head(output)

          #ITEM PANID COUNT EXPECTATION
          #1 106 3104497 5 0.4166667
          #2 240 3104497 5 0.4166667
          #3 526 3104497 5 0.4166667
          #4 548 3104497 5 0.4166667
          #5 900 3104497 5 0.4166667
          #6 1251 3104497 5 0.4166667


          That said, it's a very back-of-the-envelope calculation. With more data (e.g. with longer timeframes and greater temporal resolution), you could look into seasonality (it's not very reasonable to expect the sales to remain constant from month to month, right). If you had actual features describing PANIDs and ITEMs, you could look into possible relationships between those features and purchase counts. Really, there's hardly a limit to how sophisticated one could get with such analysis.






          share|improve this answer





















          • Thanks for your comment! Yes I have more time frame data, I am looking into seasonality of the data also (I know there exists some for some products, such as beer etc. - think Christmas, superbowl, 4th July - all spikes). I have data on PANID's such as how many cats, dogs,TV's, sex, age, race etc. (Its a rich dataset). I also have product information also. I was just looking for a begining point. My plan was to apply a Naive Bayes and then get a little more complicated with NN or which ever ML method would be suitable.
            – user113156
            Nov 11 at 23:13






          • 1




            If you have more data, you can totally try building a model of sorts. Those are very vast topics though! Look into forecasting with ARIMA models, this may help with the seasonality. And by all means this problem sounds like one amenable to ML; there's tons of relevant tutorials online. And if you get stuck, post a specific request for help!
            – 12b345b6b78
            Nov 11 at 23:19










          • At this stage I just wanted to get a Y variable because at the moment I have this rich panel level dataset but do not know exactly how to find an outcome variable for it. I think its super interesting to find out which PANELIDs / People are more likely to buy certain products based on past purchases but I just could not think of a way to find this Y variable... if this makes sense.
            – user113156
            Nov 11 at 23:26








          • 1




            I think it makes perfect sense to define the outcome variable as precisely the thing that you are trying to find out: probability of purchase (y) given customer profile and item (x)
            – 12b345b6b78
            Nov 11 at 23:30














          1












          1








          1






          In the most general case, you expect something to happen X times in a given timeframe if it, well, happened X times in a comparable timeframe in the past.



          output <- aggregate(df$PANID, by = list(df$ITEM, df$PANID), length)
          colnames(output) <- c('ITEM', 'PANID', 'COUNT')
          k <- as.integer(max(df$WEEK) - min(df$WEEK)) / 7 # number of weeks in the data
          output$EXPECTATION <- output$COUNT / k
          head(output)

          #ITEM PANID COUNT EXPECTATION
          #1 106 3104497 5 0.4166667
          #2 240 3104497 5 0.4166667
          #3 526 3104497 5 0.4166667
          #4 548 3104497 5 0.4166667
          #5 900 3104497 5 0.4166667
          #6 1251 3104497 5 0.4166667


          That said, it's a very back-of-the-envelope calculation. With more data (e.g. with longer timeframes and greater temporal resolution), you could look into seasonality (it's not very reasonable to expect the sales to remain constant from month to month, right). If you had actual features describing PANIDs and ITEMs, you could look into possible relationships between those features and purchase counts. Really, there's hardly a limit to how sophisticated one could get with such analysis.






          share|improve this answer












          In the most general case, you expect something to happen X times in a given timeframe if it, well, happened X times in a comparable timeframe in the past.



          output <- aggregate(df$PANID, by = list(df$ITEM, df$PANID), length)
          colnames(output) <- c('ITEM', 'PANID', 'COUNT')
          k <- as.integer(max(df$WEEK) - min(df$WEEK)) / 7 # number of weeks in the data
          output$EXPECTATION <- output$COUNT / k
          head(output)

          #ITEM PANID COUNT EXPECTATION
          #1 106 3104497 5 0.4166667
          #2 240 3104497 5 0.4166667
          #3 526 3104497 5 0.4166667
          #4 548 3104497 5 0.4166667
          #5 900 3104497 5 0.4166667
          #6 1251 3104497 5 0.4166667


          That said, it's a very back-of-the-envelope calculation. With more data (e.g. with longer timeframes and greater temporal resolution), you could look into seasonality (it's not very reasonable to expect the sales to remain constant from month to month, right). If you had actual features describing PANIDs and ITEMs, you could look into possible relationships between those features and purchase counts. Really, there's hardly a limit to how sophisticated one could get with such analysis.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 at 23:08









          12b345b6b78

          767115




          767115












          • Thanks for your comment! Yes I have more time frame data, I am looking into seasonality of the data also (I know there exists some for some products, such as beer etc. - think Christmas, superbowl, 4th July - all spikes). I have data on PANID's such as how many cats, dogs,TV's, sex, age, race etc. (Its a rich dataset). I also have product information also. I was just looking for a begining point. My plan was to apply a Naive Bayes and then get a little more complicated with NN or which ever ML method would be suitable.
            – user113156
            Nov 11 at 23:13






          • 1




            If you have more data, you can totally try building a model of sorts. Those are very vast topics though! Look into forecasting with ARIMA models, this may help with the seasonality. And by all means this problem sounds like one amenable to ML; there's tons of relevant tutorials online. And if you get stuck, post a specific request for help!
            – 12b345b6b78
            Nov 11 at 23:19










          • At this stage I just wanted to get a Y variable because at the moment I have this rich panel level dataset but do not know exactly how to find an outcome variable for it. I think its super interesting to find out which PANELIDs / People are more likely to buy certain products based on past purchases but I just could not think of a way to find this Y variable... if this makes sense.
            – user113156
            Nov 11 at 23:26








          • 1




            I think it makes perfect sense to define the outcome variable as precisely the thing that you are trying to find out: probability of purchase (y) given customer profile and item (x)
            – 12b345b6b78
            Nov 11 at 23:30


















          • Thanks for your comment! Yes I have more time frame data, I am looking into seasonality of the data also (I know there exists some for some products, such as beer etc. - think Christmas, superbowl, 4th July - all spikes). I have data on PANID's such as how many cats, dogs,TV's, sex, age, race etc. (Its a rich dataset). I also have product information also. I was just looking for a begining point. My plan was to apply a Naive Bayes and then get a little more complicated with NN or which ever ML method would be suitable.
            – user113156
            Nov 11 at 23:13






          • 1




            If you have more data, you can totally try building a model of sorts. Those are very vast topics though! Look into forecasting with ARIMA models, this may help with the seasonality. And by all means this problem sounds like one amenable to ML; there's tons of relevant tutorials online. And if you get stuck, post a specific request for help!
            – 12b345b6b78
            Nov 11 at 23:19










          • At this stage I just wanted to get a Y variable because at the moment I have this rich panel level dataset but do not know exactly how to find an outcome variable for it. I think its super interesting to find out which PANELIDs / People are more likely to buy certain products based on past purchases but I just could not think of a way to find this Y variable... if this makes sense.
            – user113156
            Nov 11 at 23:26








          • 1




            I think it makes perfect sense to define the outcome variable as precisely the thing that you are trying to find out: probability of purchase (y) given customer profile and item (x)
            – 12b345b6b78
            Nov 11 at 23:30
















          Thanks for your comment! Yes I have more time frame data, I am looking into seasonality of the data also (I know there exists some for some products, such as beer etc. - think Christmas, superbowl, 4th July - all spikes). I have data on PANID's such as how many cats, dogs,TV's, sex, age, race etc. (Its a rich dataset). I also have product information also. I was just looking for a begining point. My plan was to apply a Naive Bayes and then get a little more complicated with NN or which ever ML method would be suitable.
          – user113156
          Nov 11 at 23:13




          Thanks for your comment! Yes I have more time frame data, I am looking into seasonality of the data also (I know there exists some for some products, such as beer etc. - think Christmas, superbowl, 4th July - all spikes). I have data on PANID's such as how many cats, dogs,TV's, sex, age, race etc. (Its a rich dataset). I also have product information also. I was just looking for a begining point. My plan was to apply a Naive Bayes and then get a little more complicated with NN or which ever ML method would be suitable.
          – user113156
          Nov 11 at 23:13




          1




          1




          If you have more data, you can totally try building a model of sorts. Those are very vast topics though! Look into forecasting with ARIMA models, this may help with the seasonality. And by all means this problem sounds like one amenable to ML; there's tons of relevant tutorials online. And if you get stuck, post a specific request for help!
          – 12b345b6b78
          Nov 11 at 23:19




          If you have more data, you can totally try building a model of sorts. Those are very vast topics though! Look into forecasting with ARIMA models, this may help with the seasonality. And by all means this problem sounds like one amenable to ML; there's tons of relevant tutorials online. And if you get stuck, post a specific request for help!
          – 12b345b6b78
          Nov 11 at 23:19












          At this stage I just wanted to get a Y variable because at the moment I have this rich panel level dataset but do not know exactly how to find an outcome variable for it. I think its super interesting to find out which PANELIDs / People are more likely to buy certain products based on past purchases but I just could not think of a way to find this Y variable... if this makes sense.
          – user113156
          Nov 11 at 23:26






          At this stage I just wanted to get a Y variable because at the moment I have this rich panel level dataset but do not know exactly how to find an outcome variable for it. I think its super interesting to find out which PANELIDs / People are more likely to buy certain products based on past purchases but I just could not think of a way to find this Y variable... if this makes sense.
          – user113156
          Nov 11 at 23:26






          1




          1




          I think it makes perfect sense to define the outcome variable as precisely the thing that you are trying to find out: probability of purchase (y) given customer profile and item (x)
          – 12b345b6b78
          Nov 11 at 23:30




          I think it makes perfect sense to define the outcome variable as precisely the thing that you are trying to find out: probability of purchase (y) given customer profile and item (x)
          – 12b345b6b78
          Nov 11 at 23:30


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254007%2fprobability-of-purchasing-an-item-based-on-past-purchases%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Full-time equivalent

          さくらももこ

          13 indicted, 8 arrested in Calif. drug cartel investigation