0

Imagine I have a table like this :

month-year varchar
nbr integer

values :

[01-2014,5],[02-2014,110],[03-2014,154],[04-2014,110]

Imagine we are the 15th of april. This datas are displayed on a linear graph. If I display the real value for the month of april the line will be down. What I would like is to display the trend rather than the real value for the current month.

I tought about doing something like this :

(5+110+154+110) / (3 + (15/30.5)) = 108

Where "3" is the number of month passed, "30.5" is the average number of days by month, and "15" is the number of days passed for the current month. This is wrong because it's lower than the real value.

I'm pretty sure there is a more formal way to do this, but as you can see I don't know a lot about statistics and trends. I tought about other ways but they are not very convincing.

Can you help me ?

NB: in reality I can get the count number by day, even by hours or minutes. I just count in mysql the number of entries and I have a date-time column. I described the table with month and year in order to make myself clear for the purpose of this example.

1 Answer 1

1

What you are trying to calculate is called a moving average.

You have a slight bug in your calculation. The formula should be:

(5+110+154+110) / (3 + (15/30.5))
                        ^^^^^^^

You need to decide how many months back to include in your moving average.

4
  • Thank you, -I edited my ask ^^- It's true if I take only one or two month back the result is more what I expect. But is it correct to do this like that ?
    – Su4p
    Apr 17, 2014 at 10:19
  • 1
    The less time back you use , the more "true" the value will be. However, if there are natural variations of the day-to-day values then extrapolating a whole month from just a few days can giva a large error. I suggest that you use the last 30 days to estimate the current month. It should work well unless there are big seasonal variations. What it will do is replace the remaining days of the month with days from last month. Apr 17, 2014 at 10:26
  • if I take two months back the result will be 149.6 but it's kind of lower than what I expected cause last month at the same day the number of entries was 154 /2 = 77.
    – Su4p
    Apr 17, 2014 at 10:26
  • 1
    If you follow my advise and take the last 30 days, you will get (154*15/30)+110 = 187 for april. Apr 17, 2014 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.