Determine gradient from past samples Again this question may be simple for you, but it is an important aspect for my classification problem. Let`s say I have 5 attributes, which are:
- previous_value_1
- previous_value_2
- previous_value_3
- previous_value_4
- previous_value_5

These attributes are generated with independent events, but I want to combine them for my classifiers therefore I need a way or statistical method to reach that goal. 
These, values are actually samples that if a process is improving or getting worse. Therefore, taking average of them is meaningless, I need them to generate a function and take its derivative. But, I do not know statistical counterpart for that operation or may be simpler way to do this. To sum up, I need a way to combine these attribute values as one, and that new attribute should indicate whether it is going up or down. 
I hope I managed to make some details clear to get an answer. 
Also, many thanks in advance.
 A: I don't know whether this does answer your question, but here goes. I use linear regression.
(The example is in R)
As an example, I use these values
t=1:5;
x=c(-10, 15, 20, -5, 4);

for you 5 previous values sampled at time t. From your description, I assume that each value is the difference to the preceding one (indicating, whether the process increased or decreased for each sample). So to fit the line, I take the cumulative sum
z=cumsum(x);

and fit a linear regression model
mod=lm( z~t);

The result can be plotted with
plot(z,type="b")
lines(x,type="b",col="red")
abline(mod, col="green")


which gives you this plot.
The red points are the original data, the red the cumulative sum and the green line is the regression line. You can use the slope of the regression line as an indicator for the degree of in/decrease of your data-points which you get by
mod$coefficients[2]

A: You're looking for "Numerical Differentiation".   Here's the Wiki version:
http://en.wikipedia.org/wiki/Numerical_differentiation
Notice under the "Higher Order Methods" section, there's a five point formula.  In your case, assuming pv_1 happens first, pv_2 happens next, .... pv_5 happens last, and the time between each step is a constant "h", the formula is:
slope = ((-1*pv_5) + (8*pv_4) + (-8*pv_2) + (1*pv_1)) / (12*h)

Also, notice that this is the derivative at the midpoint (pv_3).
Edit 10/06/2011 ============================================================
@thias: From the original question, he's using the 5 previous data values to determine if things are "going up" or "going down".  Any "outlier" will have a consistent effect on the 5 sequential calculations that use that "outlier".
The numerical derivative calculation is already noisy and noise in the data makes it worse.    My point is, most of the time, noise is "the" issue, not the method of the calculation.
The 5 point method above uses a higher order scheme to calculate the result.   It will produce more noise than my (pv_5 - pv_1)/h method in the comment section below.   It is because of this added noise that most people would choose the (pv_5 - pv_1)/h method over the 5 point method.
Comparing the (pv_5 - pv_1)/h method to your moving-window-least-squares method, the added trouble of the calculation typically provides small advantages with some additional noise.   In other words, it provides a better answer, but a lot of people go the "quick-and-easy-route" 
Below is some code:
#Set up the parameters
set.seed(101)
n <- 100 #Number of data points
h <- 1 #Step change in time sequence
t <- 1:n #time sequence
a <- 3 #Scale for the sine wave
w <- pi/20 #Frequency for the sine wave

noi <- 2 #Multiplier for noise level

#Build the data series, then add noise
dat <- a*sin(w*t)
datn <- dat + (noi*rnorm(n))

#Calculate the actual derivative
derdat <- a*w*cos(w*t)

#Calculate the derivative using the 5 point scheme
derdat5p <- rep(NA, n)
for (i in 3:(n-2)) {
  derdat5p[i] <- ((-1*datn[i+2]) + (8*datn[i+1]) + (-8*datn[i-1]) + (1*datn[i-2])) / (12*h)
}

#Calculate the derivative using the 2 point scheme
derdat2p <- rep(NA, n)
for (i in 3:(n-2)) {
  derdat2p[i] <- (datn[i+2] - datn[i-2]) / (5*h)
}

#Fit a moving-window line to the data and extract the derivative
derdatlin <- rep(NA, n)
for (i in 3:(n-2)) {
  mod <- lm(datn[(i-2):(i+2)] ~ t[(i-2):(i+2)])
  derdatlin[i] <- as.numeric(mod$coefficients[2])
}

#Set up the plot area
par(pty="m", plt=c(0.1, 1, 0, 1), omd=c(0.1,0.9,0.1,0.9))
par(mfrow = c(2, 1))

#Plot the series
plot(datn, type="n", xaxt="n", xlab="", ylim=range(datn, dat, na.rm =TRUE), las=2)
mtext(side=3, paste("Noise Level = ", noi, sep=""), line=1, cex=2)
mtext(side=2, "f(t)", line=3)
atx <- seq(par("xaxp")[1], par("xaxp")[2], (par("xaxp")[2]-par("xaxp")[1])/par("xaxp")[3])
abline(v=atx, col="lightgray")
lines(datn, col="darkgray")
lines(dat, lwd=2, col="red")
legend("bottomright", legend=c("datn", "dat"), bg="white", lwd=c(1, 2), col=c("darkgray", "red"), cex=0.9)

#Plot the derivative of the series
plot(derdat, type="n", xaxt="n", xlab="", ylim=range(derdat, derdat5p, derdat2p, na.rm =TRUE), las=2)
mtext(side=2, "Derivative of f(t)", line=3)
atx <- seq(par("xaxp")[1], par("xaxp")[2], (par("xaxp")[2]-par("xaxp")[1])/par("xaxp")[3])
abline(v=atx, col="lightgray")
lines(derdat5p, col="darkgray")
lines(derdat2p, col="green")
lines(derdatlin, col="blue")
lines(derdat, lwd=2, col="red")
legend("bottomright", legend=c("derdat5p", "derdat2p", "derdatlin", "derdat"), bg="white", lwd=c(1, 1, 1, 2), col=c("darkgray", "green", "blue", "red"), cex=0.9)

#Place the time axis
axis(side = 1)
mtext(side=1, "t", line=1.9, cex=0.8)

Below is the output of the above code with the noise value noi set to 2.   The top graph shows the original data (in red) with noise (in gray).
The bottom graph is the calculation of the derivative.  The red line is the actual derivative.   The noisy gray line is 5-point method shown above.   The green line is the 2-point method.   And, the blue line is your moving-window-least-squares method.
Notice that there's not much difference in the 2-point method and the moving-window-least-squares method.  It depends on how you measure the noise level as to which method has "more noise".   As I stated in the comment section below, it's typically not the method that's the issue, it's the noise.

Below is another run with the noise value noi set to 0.2.   Your moving-window-least-squares method does a better job in the peaks/valleys than the 2-point method, but again, it depends on how you measure the noise as to which method has "more noise".
So, back to the original issue of measuring if things are "going up" or "going down", both methods are typically close enough that it doesn't matter which one is used.   The main issue is typically the level of noise.

