Friday, August 31, 2012

Conditional survival times

Using this paper explaining how to generate conditional survival times and the survival library in R I created some example.

Here's an example for the Weibull distribution an a conditional T>2 event time against the non-conditional case.

The survival function is given by
$$ 1-F(t) = S(t) = \exp(-H(t))$$
So, by inverting the formulae we can generate event times using the cumulative hazard function
$$ T = H^{-1}(-\log U)$$
Now, substituting in the conditional hazard function

$$ S(t|t>T_k) = \exp(-a(H(t) - H(T_k)))$$
And rearranging as before gives
$$ T = H^{-1}(-{\log U}/{a} + H(T_k)) - T_k.$$

The code looks like this

library(survival)

n <- 10000
nbreak <- 100
lamb <- 2
r <- 1    # hazard adjustment
tmin <- 1    # conditional minimum event time e.g. intervention time
nu <- 2


# Weibull
invH_Wei <- function(t){
(1/lamb * t)^(1/nu)
}

T <- invH_Wei(-log(rv_unif)/r)


H_Wei <- function(t){
lamb * (t^nu)
}

T2 <- invH_Wei(-log(rv_unif)/r + H_Wei(tmin)) - tmin

Tcond <- T2 + tmin

plot(survfit(Surv(Tcond)~1))
lines(survfit(Surv(T)~1))

Sunday, August 26, 2012

Population distribution in Manchester



I was just playing with the Census 2011 data on the ONS site and saw an interesting pattern. It seems that the population in Manchester has a proportionately large number of 20-30 years olds compared with the rest of the country. I imagine this is due to students who decide to stay after their studies and people being less inclined to head to the country to have kids, at an earlier age at least.

I'm going to call these distributions the CHRISTMAS TREE and the GHERKIN.

Friday, August 10, 2012

Equations in Google Blogger

I'm using something called jqMath  that uses MathML semantics, which seem a lot like LaTeX but different. Here's some examples:
Einstein's most famous equation is $E=mc^2$. Blah blah blah
Newton derived the equation $s=ut+\frac{1}{2}at^2$
$$x={-b±√{b^2-4ac}}/{2a}$$