I have a group of individuals for which I would like to report a mean and a weighted error. The data that I observe on a daily basis are two independent $iid$ random variables with unknown distributions that can be quantified as 'number of individuals per day' which i call $W$ and some measure of 'revenue' called $R$ that represents the sum of the revenue brought by all the individuals of that specific day.
Each day, those two variables are updated as they are observed. Using this data, I can compute the thing that I am intereseted in reporting which is the 'revenue per individual per day' called $X$ by computing $x_i = r_i/w_i$ on each day ($i.e.$ for each day $i$, I divide the sum of revenue for all the individuals by the number of individuals). This leaves me with the following dataframe:
W | R | X |
---|---|---|
12 | 100 | 8.33 |
15 | 110 | 7.33 |
65 | 740 | 11.38 |
Using this data, I would like to finally report my KPI which is the mean revenue per individual per day over this data collection period. Since not all days are equally represented with the same number of individuals bringing revenue ($e.g.$ day $3$ in the data above has a much higher individual count of $65$ compared to day $1$ which contains only $12$), I would like to represent my KPI as a weighted mean where the individual weights are the number of individuals $w_i$ such that days with higher individual count are better represented in the final mean I report like so:
$$ \bar{x}_w = \frac{\sum_i w_i \times x_i}{\sum_i w_i} $$
Then, I can calculate the weighted sample standard deviation like so (according to this note):
$$ s_w = \sqrt{\frac{ \sum_iw_i (x_i - \bar{x}_w)^2}{ \sum_i w_i -1}} $$
Finally, I can compute the standard error of the weighted mean which is defined as $se = s_w/ \sqrt{n}$.
First question
What is $n$ in the standard error calculation in my case? Is it the number of observations which is $3$ in the example dataframe that I have outlined above? Or is it the sum of the weights used to compute the weighted standard deviation $\sum_i w_i$ which is equal to $92$? In case we use the sum of the weights, the error may get quite small which is something I do not typically observe since my data has high variability. In case it is the number of observations, the error will systematically decrease when I gather more data which also seems unusual. So how may i correctly estimate this empirically with the data I have? Is there any documentation anyone can point me to for reference?
Second question
My second question is somewhat trickier. In a production environment, when I report the KPI alongside its standard error, I do not have access to the full dataframe. I only have access to the first two data points to start the calculation procedure of the weighted mean and weighted standard error deviation (and the standard error).
Given that the current observation count is $n$, I would like to iteratively calculate the weighted mean and weighted standard deviation and the standard error of the weighted mean in computer code knowing only the previous weighted mean $\bar{x}_{w,n}$, previous weighted standard deviation $s_{w,n}$, the cumulative sum of previous weights $\sum_i^n w_i$, and of course the new row of data points that contains the new observation $x_{n+1}$ and its new weight $w_{n+1}$ where $n+1$ indicates the new row.
Thank you for the help!