10
$\begingroup$

I'm currently doing analysis on a website which requires that I create a decision tree diagram showing the likely route that people take whenever they arrive on the website. I am dealing with a data.frame which shows the paths of all customers to the site, starting from the homepage. For example, a customer could take the following path:

Homepage - pg 1
Kitchen Items page - pg 2
Pots and Pans page - pg 3

so this customer would have a 3 page journey. What I want to try to do in R is combine all customers paths and thereby assign a probability to a customer following a certain path on the site. For example, if I were to examine all paths I could find that 34% of people who arrive on the Homepage go onto the 'Kitchen items page'. Does R have this facility?

I have looked up different methods through the rpart and partykit packages but they didn't seem to be of any help.

Any steer in the right direction for this is very much appreciated!

$\endgroup$
3
  • 1
    $\begingroup$ i don't know much about this area, but the igraph package appears to be quite comprehensive. $\endgroup$ – richiemorrisroe Jan 28 '13 at 19:17
  • 3
    $\begingroup$ yup, igraph is the way to go for visualization. You have to compute the transition probabilities beforehand on your own. In general, I recommed to take a look at Markov Chains $\endgroup$ – steffen Jan 29 '13 at 12:40
  • 1
    $\begingroup$ Can you post some sample data? It'd help us understand the situation better. $\endgroup$ – curious_cat Mar 3 '13 at 6:23
1
$\begingroup$

Isn't one way to start, is to have a $n \times n$ matrix (say $M_{n \times n}$) where $n$ is the number of pages. Then based on your raw data increment matrix element $M_{rc}$ by one whenever you have a user hop from page $r$ to page $c$. That gets you the transition probabilities.

Your first question is already answered by this: "What percent of users on homepage (say page 1) travel next to, say, Kitchen Items (say page 2)?"

$\frac{M_{12}}{ \sum_c M_{1c}}$

Or is this too simplistic?

$\endgroup$
4
  • 1
    $\begingroup$ No this is right. From here though - is there a way to graph each of this dynamically into a tree in R? If not, is there another tool I could use? $\endgroup$ – nellington Mar 11 '13 at 12:43
  • $\begingroup$ @nellington: What sort of tree do you have in mind? $\endgroup$ – curious_cat Mar 11 '13 at 13:22
  • 1
    $\begingroup$ Preferably a probability tree, with the root node being the homepage (but if I can change the root node, to another page on the site - that would be a great feature), each branch from the root node would represent the next page visited after the root node. Ideally, each branch would have a % probability attached. It would be dynamic in the sense that I should be able to expand and contract on each sub-node. Do you know of any visualisation software which could handle this? $\endgroup$ – nellington Mar 11 '13 at 13:38
  • $\begingroup$ @nellington: For visualising purely, you could try graphviz. That tree will be a directed graph and there's plenty of graphviz-oriented tools to handle that. $\endgroup$ – curious_cat Apr 2 '13 at 7:00
0
$\begingroup$

It looks like you are trying to recreate the PageRank algorithm of Google. Most of the PageRank algorithm was developed using Markov Chains. You can find a lot of mentions of developing PageRank methods in R.

igraph.sourceforge.net/doc/R/page.rank.htm

$\endgroup$
4
  • 1
    $\begingroup$ As far as I see, this is not about pagerank. IMHO, the only overlap is that user paths will most likely correlate to site design (links), but that's it. Aside, the provided link is not working. $\endgroup$ – steffen Jan 31 '13 at 12:01
  • 1
    $\begingroup$ I think I found the link, it probably was on igraph's webpage at some point because it appears to use igraph heavily. stat.berkeley.edu/users/vigre/undergrad/reports/… $\endgroup$ – geneorama Jan 31 '13 at 19:51
  • $\begingroup$ Oh, I see... and page.rank is a function in igraph. Some documentation: link1 link2 link3 $\endgroup$ – geneorama Jan 31 '13 at 19:58
  • $\begingroup$ After briefly skimming the first report, I actually think this is a pretty good answer, and I up-voted it (although it could have used some elaboration!). The page rank functionality seems to be the answer. $\endgroup$ – geneorama Jan 31 '13 at 20:02
0
$\begingroup$

From what I see here, I agree that igraphs / Markov Chains is probably the way to go, however you could definitely use rpart and/or the partykit.

It's hard for me to give a simple answer with your limited example, but I can explain generally how you would do it.

You want look at where all your users had been, and summarize that into a string for example

"Home / product4 / product3 / product4 / buynow"
"Home / product3 / buynow"
"Home / product3 / product4"

You could then segment your users into categories, say ones who ended up in the "buy now" page, and ones who didn't. Then you could simply start predicting on that terminal result. In this example, maybe you would find out that people who did the most comparison shop did / didn't buy something.

You could also make more variables, like "what was the page before the buynow page" "how many pages did they visit before buying something" or "when did they create their first account", and you could add those metrics to your analysis.

There are a lot of different ways you could go, and this begins to answer different questions, but my point is that you could use the trees and for some problems it might be a faster and simpler route to insight.

By the way, you would need to make non-numeric variables factors by using factor or as.factor, if you're going to use party. Party has some nice vignettes to get you started.

$\endgroup$
7
  • 1
    $\begingroup$ To be honest, I want to optimise the homepage, so predicting where people go from the homepage to page 2 and then page 2 to the third page is the most important section of data I would like. Terminal page isn't of much interest. I have page urls and page numbers in the journey so transition probabilites seems like a way to do it. Despite this, it seems a bit manual and I though R might be able to provide a more iterative solution... $\endgroup$ – nellington Feb 13 '13 at 10:22
  • $\begingroup$ After rereading your question and last comment, I think that you simply want a table of what people do from the home page. (to start) $\endgroup$ – geneorama Feb 13 '13 at 14:50
  • $\begingroup$ What people do from the homepage and the page after the homepage is most important, but being able to concatenate all users data in r and assign probabilities is where it's most tricky. Maybe excel is the way to go? I'm going down the vertices/edges route in igraph but it seems to be causing more harm than help. $\endgroup$ – nellington Feb 13 '13 at 16:01
  • $\begingroup$ I added some contact info to my profile. Maybe we could talk offline? $\endgroup$ – geneorama Feb 13 '13 at 16:15
  • $\begingroup$ that would be very helpful thanks - mail sent $\endgroup$ – nellington Feb 13 '13 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.