How would I compare these means correctly? I have a data set where I want to compare the number of events that occurred in two geographic areas over a period of six years. Altogether, there are 407 districts that comprise the geographic areas.
In area $p$, there are 220 districts, while in area $q$, there are 187 districts.
In area $p$, 130 events happened while in area $q$, 70 events happened.
The target of comparison is $p$ against $q$, but I am not sure the right way to compare their means, owing to the imbalance of districts across the two.
In pseudo-Python code, I envisioned two ways to do it.
years = 6
p_areas = 220
# find the average number of events over time within p space only normalized by p's districts
df.loc[df['geographic_area'] == 'p']['event'].sum() / (years * p_areas)

q_areas = 187
# find the average number of events over time within q space only normalized by q's districts
df.loc[df['geographic_area'] == 'q']['event'].sum() / (years * q_areas)

or
total_area = 407
# group by p or q, sum up the events, then normalize by 407 total possible districts over 6 years
df.groupby('geographic_area')['event'].apply(lambda x: x.sum()) / (total_area * years)


Both give very different answers and I guess it comes down to what should the denominator be when comparing the two? The same (e.g., 407 districts), or districts unique to them (220 and 187)?
The event can only occur once in each district, once per year, and there are no other predictors
 A: Since there are no other predictors, it comes down to "coin toss experiment".
You toss coin $P$ a total of $220\cdot6=1320$ times, and you see $130$ times "heads". You toss coin $Q$ a total of $187\cdot6=1122$ times, and you see $70$ times "heads". So, the relative frequency of observing heads is $\hat{p}=187/1320=14.2\%$ for coin $P$ and $\hat{q}=70/1122=6.2\%$.
This assumes that the occurence of the events ("heads") is independent between districts and years ("coin tosses") and areas ("coins")!
Is there a test for the hypothesis that coins $P$ and $Q$ are different? Yes, there is, or actually two, you can find them in the answers to the question here :-)
Using Fisher's exact test in R with signficance level $\alpha=0.05$, the answer is:
> fisher.test(rbind(c(130, 1320-130), c(70, 1122-70)), alternative = "two.sided")

    Fisher's Exact Test for Count Data

data:  rbind(c(130, 1320 - 130), c(70, 1122 - 70))
p-value = 0.001402
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
 1.20303 2.25472
sample estimates:
odds ratio 
  1.641444 

The p value is smaller than $\alpha$, so you reject the null hypothesis that the coins ahem areas have the same probability of seeing heads ahem the event.
