How to calculate a time estimate and plot it? I recently made a website for a game's community. The game basically has an online dragon which people can fight. Each fight chips off a little bit health. On the next encounter with the dragon, people will then report his health status. This is a number from $11$ down to $0$. If the dragon reaches zero, a so-called grace-period will occur where everyone can jump into the game and kill him very easily for some nice rewards.
This site has been going for a small week now and I have gathered about a thousand reports by now, so I felt its time to calculate some stats! The most requested stat is an estimation on when the grace-period will occur.
The idea I have with this is that I want plot a graph on the site, on the $y$-axis a range of $0$ to $11$, on the $x$-axis a range of time. And basically plot all the reports I have with $3$ different lines:


*

*The health estimation I generate based on all reports

*The health based on the highest reported value

*The health based on the lowest reported value


Doing this is not really a problem, just plot the numbers I have on the graph, where it becomes interesting is doing an estimation beyond these numbers. I could do something like calculate the drop in health between two points, and use that for the downward slope, but it'll be linear and not very accurate (as it wouldn't consider all the previous reports).
I'm therefor looking for some pointers how I can approach this? I tried googling this, but I have a very hard time finding what I need. Probably because I simply lack the knowledge of terms I have to look for. Is there some general use formula for this? How would you approach this yourself? Anything would help me at this point really!
@Moderators: Feel free to add extra tags as I really have no idea.
 A: The task you are attempting is called extrapolation and is notoriously dangerous compared to interpolation between the points. I would suggest three approaches:


*

*Linear extrapolation using the last two points. As you point out, this is of limited use as you go much further than the spacing between points.
$$y = y_{n-1} + (y_n - y_{n-1}) \frac{x - x_{n-1}}{ x_n - x_{n-1}}$$

*Go to higher order with quadratic and cubic using the last three or four points. This will capture some of the higher order variation at the end of the curve. Caution though, higher order interpolation can become quite unstable.

*To do better, you need a model for your data - some idea of the shape of the overall trend. This combined with the least squares method of interpolation that may be used to predict beyond your data.
I'd suggest trying #3. You don't tell us about the nature of the data but assuming the dragon's health is primarily decreasing, you could fit it do an exponential function with a polynomial argument, such as
$$\exp( - |p(t)| ) $$
where |p(t)| is the absolute value of a low order (<4) polynomial. This function will tends to decrease but can capture some variation. Alternatively you can fit the $\log$ of your data to a polynomial and plot the exponential of the fit. Either approach assures health stays positive in the fitted function but can still decrease. Then you can estimate the dragon's demise at time $t_{dead}$ when the fitted function drops below the minimum health unit (eg 1).
The example data from Lennard's comment are fairly linear (correlation of 0.99) so I'm just using a low order polynomial. The actual data may be more fine grain and it sounds like the concern is the detailed behavior at the end of the distribution. If this is the case a a global fit for plotting with a local fit over the last few hours to determine the zero crossing might be the most accurate. For the data provided:
time=[0,8,16,24,36,38]
health=[11,9,6,4,1,0]  

I found a simple quadratic fit worked best (adding a cubic term actually prevented a zero crossing). Making the fit excluding the last data point gives a predicted death at 40 hrs vs 38 in the actual data. As noted above, more samples with a fit over the last hour using a low order polynomial would likely improve this. 
The code in R is:
require(stats)
require(graphics)
a=1
b=1
c=10
d=1
thefit=nls(health ~ (a*time*time+b*time+c),start=list(a=a,b=b,c=c))
plot(time,health)
new = data.frame(xdata = time)
p=coef(thefit)
curve(p["a"]*x^2+p["b"]*x+p["c"],col='red',add=TRUE)
p


       a            b            c 
0.001173024 -0.325246497 11.149887563 


Obviously fairly linear.
For PHP, google turns up a polynomial regression class that may be useful for the question.
A: Based on your comment about the respawning dragons and lengthening lifespans, one thing to model would be the lifespan itself rather than the interim health values. If you look at lifespan as a function of generation number or start time, you may find a model that fits. You've observed the lifespans getting longer, and modeling can help you assess whether increase is linear, quadratic or something else.
For within-lifespan predictions, the best case would be if all lifespans followed a similar curve, at least loosely. Then you can normalize things by looking at percent of lifespan passed as a function of current health. For past dragon lives, you can retroactively determine the percent of lifespan passed at each point. For the current lifespan, that's what you want to predict. Based on your other comment, the curve would not have a nice formula, but if they do follow similar patterns even something like a spline fit could be useful in making the prediction.
