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:
5%
, which means yesterday's purchases were higher then previous week's, with a deviation of 5%-11%
, which means yesterday's purchases were lower then previous week's, with a deviation of -11%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
.
Thanks in advance.
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)