Analysis code for my PhD work