Monday, March 18, 2013

Partial Map


Whilst travelling in to work this morning and thinking about the day ahead, I was struck by a connection between the two things. The London tube map is designed to represent the order of stations on a line but dispenses of the geographical distance in order to present the ordering information in the clearest way.

Cox regression using proportional hazards is calculated using what is known as a partial likelihood. Partial because only the information about the order of the events is used in the likelihood calculation and not the actual times of the events.

So, a partial likelihood is a bit like the London underground map. I suppose the map is an extension of this since there are multiple lines that cross one another but meet at the correct stations; a 2D partial likelihood perhaps?

Tuesday, March 12, 2013

Melt and join

Following my last post on rearranging and managing arrays, I've started to make use of the reshape package in R. The key functions are melt() and cast(). The melt() function rearranges an array into a long format where ids are duplicated for different covariate values. That means that all of the entries for a given patient are repeated with all of the information that was spread across multiple columns, one for each variable, put into only two; a variable and value column. Once the data is in this form you can then go ahead and cast the data in what ever `shape' you want. In the example below, I wanted to flag patients according to a group membership determined by if they had certain codes in one of their diagnosis fields. I used melt to collapse down the multiple diagnosis columns into a variable (what diagnosis field) and value (code) column pairing. In this case, the diagnosis number is not important. Then, I matched the codes to groups using a look-up table (like in Excel) and the join() function. I gather join() and merge() are similar but that's just the one I happened to use. I finally reconstructed the original array but now with the patient groupings.