MoreScratch
MoreScratch

Reputation: 3083

How to compare averages with different sample sizes in JavaScript

I have a need to compare the average number of sales that are cash sales from one year to another. For example, in 2016 there were 198 sales, of which 5 were cash (avg. = 2%). This year so far there were 41 sales and 2 were cash sales (avg. = 5%). I am reluctant to report that average cash sales are up this year mostly because I don't know if the difference is statistically significant with the sample sizes being different. I think I need to do a t-test or something similar but I am not an expert.

Would it be sufficient to say that average cash sales are up? Something like:

var trend = ( ( avgCashSalesThisYear - avgCashSalesLastYear ) * 100 ).toFixed( 0 );

Upvotes: 1

Views: 589

Answers (1)

Mike Wodarczyk
Mike Wodarczyk

Reputation: 1273

You can take last years numbers as truth because you measured it already. Take the ratio of cash transactions to total and call this lambda. This year you would expect to see a number of cash transactions that would follow a Poisson distribution. The lambda for the current year to date would be last years lambda times the total to date this year. I'll call that lambda2.

The Poisson probability for seeing k cash events is

Prob(k) = Pow(Lambda2 , k)* pow(e, -k) / k!

K! Is 1*2*3*... *k

e is a constant 2.718.

So add prob(1)+prob(2)+... prob(nCashThisYear-1)

This sum is the probability of seeing a lower number of cash events based on last years data. Add in prob(nCashThisYear) to get the probability of having less than or equal to what was observed. Subtract that from 1 to get the probability of a higher number of cases.

Upvotes: 1

Related Questions