Calculate a trendline when the x-axis uses dates

不羁岁月 提交于 2019-12-04 17:40:19

You'll have to do a sort of linear interpolation. You need to convert the dates and times to a linear scale. The good news is that you get to pick this scale. So calculate how many minutes, or seconds, or hours... have passed since the start of your plot. You can then use this as the "run" portion.

In your example, we can go off of days:

Jan 1: 0 days, 100 subscribers Jan 2: 1 day, 105 subscribers Jan 5: 4 days, 120 subscribers jan 10: 9 days, 117 subscribers

you can always convert the date to an integer

the web gives this example:

DateTime given = new DateTime(2008, 7, 31, 10, 0, 0);
TimeSpan t = given.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0));
long unixTime = (long) t.TotalSeconds;

Even though your samples are not evenly spaced, your trendline can still have a constant "run".

For example, you could choose 1 week intervals. In that case take the average number of subscribers for Jan 1,2, & 5 and plot a point on Jan 7. Next take the average for Jan 10 & 13, and plot a point on Jan 14. etc..

If you have a lot of historical data, use 1 month intervals, or maybe quarterly would better suit your data.

Specifiy an origin date and consider it x = 1. Chose hours or 8 hour periods if you want to be more specific.

The first day:
jan 1, 2006 -> x = 1
45 days later
February 13th?? -> x = 45
2 years later:
jan 1, 2008 -> x = 730
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!