# Confidence intervals for two proportions.

Let's say there are 2 towns, each with different public transport networks. I want to know which modes of transport people over the age of 30 tend to use more than the average for the population, and I want to test whether it's the same in both towns or different. I go and collect some data and it looks like this:

Variable | Area1 Total | Area1, 30+ | Area2 Total | Area2, 30+
Car      | 1098        | 100        | 1024        | 50
Train    | 1024        | 9          | 326         | 5
Bike     | 900         | 56         | 134         | 90
Unicycle | 10          | 2          | 51          | 10
Llama    | 2           | 2          | 1           | 0
Carpet   | 50          | 2          | 100         | 10


I would like to know, for each mode of transport, whether more or fewer people take, for example, the train, in town A, than might be expected by chance. Let's say 50% of town A are over 30, and yet 70% of people who take the train are over 30. If age had nothing to do with transport preference, we would expect 50%, so this deviates significantly from our expectations.

So, in my line of work, we use 95% confidence as a (admittedly arbitrary) cutoff to quote statistics at. So, what is the difference between expectation and observation, and what are the confidence intervals on that difference.

Next up, what is the difference between the two towns? Are any modes of transport preferred by the over 30s in one town more than they are in the other, and again, what is the difference, and what are the confidence intervals on that difference?

I'm fairly sure it's quite simple, but I'm stuck, and any help would be greatly appreciated! The data can't be re-gathered, but I'm open to any ideas on how to run the stats on it.

EDIT:

I think I've found the answer to the overall problem. Fisher's Exact Test can test, for example:

Train:
| Town A | Town B
30+       | 100    | 200
30-       | 200    | 400


This will determine whether there is a significant difference between train use in town A and town B, and whether there is a difference in the age groups.

I'll write it up as an answer when I'm vaguely coherent. I need sleep now.

(For anyone who's interested, this is actually part of a study into genome evolution in plants. The people are individual genes, the towns are two different genomes, and the "over 30s" is whether they appear to be part of a set of duplicate genes. Modes of transport are in fact chemical reactions which the gene affects. I'm interested in whether plants gain and lose copies of genes randomly, or because they are involved in specific processes, and whether plants which have differing ecologies gain or lose duplicates of genes in response to this. I'm a bit lost myself, so I thought I'd work out an analogy which didn't require detailed knowledge of plant genomics to answer the question.)

-
Could you explain how the question "if mode of transport is more influenced by age in area 1 or area 2" is addressed by those pairwise comparisons? In this part "difference between observed and expected (108% < X < 120%)" what does that inequality represent? What is $X$? It can't be a difference in percentages like the text suggests. When you talk about 'expected' - expected under what model? Further, I would think answering the question as phrased in your first sentence would involve a different analysis, since it seems to relate to an interaction. (& that's a lot of comparisons -- why 95%?) – Glen_b Dec 19 '12 at 22:20
Thanks for having a look - in this case, 95% is just an arbitrary confidence level which is used as convention in my field. a<X<b is the way we usually express upper(b) and lower(a) confidence intervals on any parameter estimate. For the study I'm doing, I would like to know, for each individual row in that table, firstly whether that group uses that mode of transport more or less than average for the population, and secondly whether the two groups differ in a significant way. – TDN169 Dec 19 '12 at 22:29
It occurs to me that I might be better off looking at it flipped 90 degrees. Not sure yet – TDN169 Dec 19 '12 at 22:31
So what parameter is this an interval for: "108% < X < 120%"? What is X there? Why is it expressed as a percentage? Why is that percentage greater than 100? It seems like you're asking about a ratio, not a difference. Could you explain what you intend by "whether the two groups differ in a significant way"? Are you asking for general difference in distribution of proportions in each transport category across a variable? Which comparison is intended (Age (below 30 vs 30+)? Area1 vs area 2? Both? Or the interaction suggested by your original 1st sentence?) – Glen_b Dec 19 '12 at 22:50
So if, 30% of people in town A are over 30, I would expect 30% of a random selection of people from town A to be over 30. If 60% of train users from town A are over 30, this would be a significant deviation from that expectation. I would like to be able to quantify that deviation, with confidence intervals. – TDN169 Dec 19 '12 at 23:38

There are a variety of ways of tackling a problem of this kind/size. The problem with looking for differences on one variable (say in area) is that there are other important variables (like age). If you ignore the such variables you invite a host of problems (not being able to pick up important differences, or finding differences that are illusory or even reversed from the true direction of difference; this is also familiar in regression and ancova where an effect can change direction from a univariate analysis once you take into account another important covariate; the simple analysis may be misleading).

For count data, there are generalized linear models. For contingency tables, an analysis using loglinear models (a subset of GLMs) would be fairly common.

The advantages of using GLMs is that you get the ability to use models for count data like you would use ANOVA, ANCOVA and regression for continuous variables (with assumptions of normality) - you can build suitable, interpretable models that will let you make conclusions about (say) relative odds of taking one mode of transport rather than another in the two towns, for a given age group.

[It's probably better to work with your actual problem, avoiding jargon where convenient, explaining jargon where necessary, though. Incidentally, if you're going to explain the actual problem you have, stats.stackexchange.com is likely to have a greater concentration of people used to working on exactly this kind of problem; I'm a statistician myself (and there are statisticians here, certainly), but over there, that's pretty much everyone, and some of them will very likely have familiarity with problems like your actual one.]

If you'd like (here or there), I could try to help come up with models that would answer the kind of questions you're talking about.

Incidentally, in regard to your 'age' variable, it would be more typical to give the data as "Age <30" vs "Age 30+" rather than as "total" vs "subgroup". You can't compare the total with the subgroup - you'd just have to split the 'total' group up to make the comparison anyway.

Do you have suitable software - something that will fit glms / loglinear models?

Is this something you're looking to publish? Is it for a thesis? Some coursework?

-
I've made a new question over at stats, which hopefully answers your questions and is a bit clearer stats.stackexchange.com/questions/46349/… – TDN169 Dec 20 '12 at 23:37
Thanks - I will look for it but you'll likely have a bunch of answers in short order. But likely more (seemingly) silly questions to begin with. – Glen_b Dec 20 '12 at 23:39