javastandard-deviationvariancedeviation

Standard deviation calculation - Am I following the right approach? How do we find SD percentage?


I have a query which gives me below data.

item_name, total_purchase_count_per_week, previous_day_purchase_count.

For ex,

iPhone , 4800, 200 
Samsung, 3000, 470
Moto, 1700, 80

Now, I'm interested in knowing how much percentage yesterday's purchase deviated from previous week purchase of every item.

For Example:

This is what I tried:

I wrote a java method, which takes avg(total_purchase_count_per_week) and previous_day_purchase_count as input to SummaryStatistics and computes SD and variance.

 SummaryStatistics txnCountSummary = new SummaryStatistics();

 txnCountSummary.addValue(totalCount);
 txnCountSummary.addValue(avgCountPWeek);

 Double sd = txnCountSummary.getStandardDeviation();

This case, SummaryStatistics takes 685 (i.e 4800/7 - average count from previous week) and 200 (yesterday count) gave me SD as 342.94.

  1. Am I calculating SD with correct inputs? just taking the average of previous week and calculating SD with yesterday's count is enough?
  2. If yes, How do we calculate the deviation in percentage? like yesterday's purchase is deviated by 5% or -2% compare to previous week average as mentioned in the above example.
  3. If no, please advice me the right approach to come up with correct deviation percentage. I can change the query to pull additional details if required.

Thanks in advance.


Solution

  • I think what you want is to find the deviation of yesterday's count to the average of last week. This is basically, (yesterdayCount - (sumOfLastWeekCount/numberOfDaysLastWeek))/(sumOfLastWeekCount/numberOfDaysLastWeek)

    This is different from Standard Deviation which basically measures the degree of spread among a series of data points relative to their average value.(Standard Deviation definition)