Weighted average of averages or average of weighted samples?

I have to estimate the average amount of goods that will be produced by machines per resource unit.

Each machine will be working in one of two modes (A or B) and I know their proportions ($$p_A$$ and $$p_B$$, $$p_A+p_B=1$$). The distributions of goods produced and resource used will depend on the mode.

I have two series of data points (goods produced and resource used) from test environments:

• $$N_A$$ points $$(g_i^A,r_i^A)$$ from machines working in mode A
• $$N_B$$ points $$(g_j^B,r_j^B)$$ from machines working in mode B

My first thought was to calculate the average production per resource unit for each mode and then calculate their weighted average:

$$\mu_A=\frac{\sum_{i=1}^{N_A} g_i^A}{\sum_{i=1}^{N_A}r_i^A}\\ \mu_B=\frac{\sum_{j=1}^{N_B} g_j^B}{\sum_{j=1}^{N_B}r_j^B}\\ \mu = p_A\mu_A+p_B\mu_B$$

But then it occurred to me that maybe I should weigh each data point and then calculate their average: $$\mu = \frac{\left(\sum_{i=1}^{N_A} p_A g_i^A\right)+\left(\sum_{j=1}^{N_B}p_Bg_j^B\right)}{\left(\sum_{i=1}^{N_A}p_Ar_i^A\right)+\left(\sum_{j=1}^{N_B}p_Br_j^B\right)}$$

I'm aware that the first method will disregard the differences in the test population sizes, but still I'm not sure if it's good or bad in this scenario.

Which of those two approaches is better and why? Or should I use another method?

EDIT: As noted by @gunes, I could also average the ratios. As far as I can see, this leads to at least one more method:

$$\mu=p_A\frac{1}{N_A}\left(\sum_{i=1}^{N_A}\frac{g_i^A}{r_i^A}\right)+p_B\frac{1}{N_B}\left(\sum_{j=1}^{N_B}\frac{g_j^B}{r_j^B}\right)$$

• One question (not related to what you ask for) that comes to my mind is that why don't you sum/average the ratios, i.e. $g/r$? – gunes Apr 5 at 13:38
• @gunes To be honest, it did not occur to me. I edited the question to include a ratio-based alternative. – tearvisus Apr 5 at 15:42
• – kjetil b halvorsen Apr 5 at 17:33