# Best value to store ratio data and compare it to time period average

I'm looking for a simple way to store ratios.

For a time component, I must store the average ratio between two behavior. For example the number of people that turn left compared to the number of people that turn right.

I have to detect unusual behavior (people that turn right abnormally).

How should I mathematically compare the average ratio against the analyzed ratio, and how should I display the difference on a graph ?

• Is this compositionnal data (i.e. do the lines sum to a constant)? en.wikipedia.org/wiki/Compositional_data Sep 20, 2010 at 17:01
• A typical ratio would be 1042:42. 1042 turn left, 42 turn right.
– Pierre 303
Sep 23, 2010 at 17:13

If these are exclusive behaviours - they must either turn left or right and can't go straight on, stop or anything else - then you have data that you might assume are binomially distributed: in the example you give there are then 1042 left turns (the 'ones') in 1084 'runs' which you are implicitly assuming to be independent observations.

Testing

You could either use a binomial distribution to test whether this is consistent with a particular true proportion of left turns, say 90%. In R, the test against 90% is

binom.test(1042, n=1084, p=.90)

and is rejected (and chisq.test agrees). You probably have covariates though and perhaps non-independent draws via clustering etc. For these, switch to a binomial logistic regression framework.

Plotting

For this data you should probably plot the empirical logits: here log(1042/42) = 3.211228, or their posterior means (see below). Visually this quantity represents a proportional increase and decrease in the counts as an equally sized increment up or down. A symmetrical representation in proportional rather than absolute terms is usually what you want for this sort of data.

You can get a quite a well-behaved confidence interval for the empirical logit via a Bayesian argument: the posterior distribution, assuming an invariant 'Jeffreys' Prior of $\text{Beta}(0.5,0.5)$, of the empirical logit is Normal with mean $\mu = \log{(\text{left}/\text{right})}$ and standard deviation $\sigma_\mu = (\text{left} + 0.5)^{-1} + (\text{right} + 0.5)^{-1}$.

• @CP I like your Bayesian approach. You also justify you name! Dec 22, 2010 at 14:27