|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
determining a rising\falling trendgive and array of 5 values, what's a fool proof way to determine wether the overall trend of values it contains is rising or falling, assuming that some of the values may equal each other? for example 1.08 1.13 1.14 1.10 1.10 i wrote the function below, but it doesn't take into account the equal value possibility. i was curious to know if you folks knew of a better method. increase the array being sampled's size and recall it? Private Function Trend(sngReading() As Single) As String 'Rising or Falling? Dim HigherTally As Integer Dim LowerTally As Integer Dim X As Integer For X = 1 To iSampleSize '5 If X <> 1 Then 'Don't compare entry against itself If sngReading(X) > sngReading(1) Then HigherTally = HigherTally + 1 If sngReading(X) < sngReading(1) Then LowerTally = LowerTally + 1 End If Next If HigherTally > LowerTally Then Trend = "F" ElseIf HigherTally < LowerTally Then Trend = "R" End If End Function lance Lance wrote:
> hello all, [SNIP]> > give and array of 5 values, what's a fool proof way to determine > wether the overall trend of values it contains is rising or falling, > assuming that some of the values may equal each other? for example > > 1.08 > 1.13 > 1.14 > 1.10 > 1.10 Trend analysis is not a simple thing, and is an entire branch of Statistics in itself. Simply saying that more are going up than going down does not give a trend - rates of change need to be taken into account, and variations smoothed. Assuming that you are referring to a simple linear trend, then you are talking about plotting the data and drawing a line of best fit. The easiest method to calculate this is via the least-squares method. In brief, we have: - Slope = ( Sum( (Value - (Average Value)) x (Item Number - (Average Item Number)) ) divided by the Sum((Value - (Average Value) squared) (It looks much more elegant in statistical notation.) If the result is positive, the values are increasing, if negative, decreasing. I'll leave it to you to develop the code. If you have further questions, post back. -- Regards, Michael Cole thanks mike. i'll take that into account.
lance Show quoteHide quote "Michael Cole" <no***@hansen.com> wrote in message news:u0H5E2MZFHA.3620@TK2MSFTNGP09.phx.gbl... > Lance wrote: >> hello all, >> >> give and array of 5 values, what's a fool proof way to determine >> wether the overall trend of values it contains is rising or falling, >> assuming that some of the values may equal each other? for example >> >> 1.08 >> 1.13 >> 1.14 >> 1.10 >> 1.10 > > [SNIP] > > Trend analysis is not a simple thing, and is an entire branch of > Statistics > in itself. Simply saying that more are going up than going down does not > give a trend - rates of change need to be taken into account, and > variations > smoothed. > > Assuming that you are referring to a simple linear trend, then you are > talking about plotting the data and drawing a line of best fit. The > easiest > method to calculate this is via the least-squares method. > > In brief, we have: - > > Slope = ( Sum( (Value - (Average Value)) x (Item Number - (Average Item > Number)) ) > divided by the Sum((Value - (Average Value) squared) > > (It looks much more elegant in statistical notation.) > > If the result is positive, the values are increasing, if negative, > decreasing. > > I'll leave it to you to develop the code. If you have further questions, > post back. > > > > -- > Regards, > > Michael Cole > > "Lance" <chuckyboy81070-at-onehotpotatoimeanhotmail.com> wrote For these type of problems, I often apply a slew rate algorithm.> hello all, > > give and array of 5 values, what's a fool proof way to determine wether the > overall trend of values it contains is rising or falling, assuming that some > of the values may equal each other? for example Ex: Private Sub Form_Load() Debug.Print Trend(Array(8, 13, 14, 10, 10)) End Sub Private Function Trend(Values) As String Dim i, slew slew = Values(LBound(Values)) For i = LBound(Values) To UBound(Values) slew = slew + (Values(i) - slew) * 0.7071 ' 1 / Sqr(2) Next If slew > Values(LBound(Values)) Then Trend = "Rising" Else Trend = "Falling" End If End Function thanks larry. i'll plug that in and see how it works out. it should be
adequate. lance Show quoteHide quote "Larry Serflaten" <serfla***@usinternet.com> wrote in message news:OPhboDOZFHA.4088@TK2MSFTNGP15.phx.gbl... > > "Lance" <chuckyboy81070-at-onehotpotatoimeanhotmail.com> wrote >> hello all, >> >> give and array of 5 values, what's a fool proof way to determine wether >> the >> overall trend of values it contains is rising or falling, assuming that >> some >> of the values may equal each other? for example > > For these type of problems, I often apply a slew rate algorithm. > > Ex: > > Private Sub Form_Load() > Debug.Print Trend(Array(8, 13, 14, 10, 10)) > End Sub > > > Private Function Trend(Values) As String > Dim i, slew > > slew = Values(LBound(Values)) > > For i = LBound(Values) To UBound(Values) > slew = slew + (Values(i) - slew) * 0.7071 ' 1 / Sqr(2) > Next > > If slew > Values(LBound(Values)) Then > Trend = "Rising" > Else > Trend = "Falling" > End If > > End Function > > > Lance wrote:
> Depends on the definition of both "foolproof" and "overall" trend...> hello all, > > give and array of 5 values, what's a fool proof way to determine wether the > overall trend of values it contains is rising or falling, assuming that some > of the values may equal each other? for example > ..... As Michael C notes, tests for <linear> trend involve computing the slope of a regression line and testing whether it is nonzero. Of course, that is only the test of <linear> trend...the data could easily have a quadratic shape and the slope be identically zero--is that a rising or falling (or neither) trend for your application? There are also rank-order methods... To answer further would need to know more about what is needed... |
|||||||||||||||||||||||