Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

covariance calculation

Status
Not open for further replies.

ersatz

Programmer
Oct 29, 2002
114
US
Hi,
I have a function for calculate the covariance.
I use 50 values for mean calculation.
My problem is that my function doesn’t go to EOF. It’s stop to EOF-counter (50).
Normally, in my 3 calculated fields I must have data from counter to EOF
Can somebody help me, please?
Thanks in advance

For j = 1 To rst1.RecordCount
Counter=50
left = left + 1
right = left + counter - 1
If right <= rst1.RecordCount - counter Then
For i = 1 To counter

sum = sum + rst1(&quot;field1&quot;)
sum1 = rst1(&quot;field2&quot;)
last = rst1(&quot;field1&quot;)
rt = rst1(&quot;field2&quot;)
rst1.MoveNext
Next i

mean = sum / counter
mean1 = sum1 / counter
cov = (last - mean) * (rt - mean1)

rst1.AbsolutePosition = right - 1
If right <= rst1.RecordCount Then

rst1.Edit
rst1(&quot;AVG1&quot;) = mean
rst1(&quot;AVG2&quot;) = mean1
rst1(&quot;COVAR&quot;) = cov, &quot;#0.000&quot;
rst1.Update
sum = 0
sum1 = 0

rst1.MoveNext
End If
End If
Next j
 
I don't understand your problem description. What do you want to happen, and what happens?
Rob
[flowerface]
 
I want to calculate cov(field1,field2)for every 50 values in my columns.
exp:I take the first 50 values, I calculate mean and cov and I put that in field3,row 50.
Next, I take data from 1 to 51,I make mean and cov and put that in field3, row 51.
All it's ok but my program stop to rs.recordcount-icount(icount=50)
I don't have the last 50 values
thanks again, Rob
 
right = left + counter - 1
If right <= rst1.RecordCount - counter Then

It would seem that the problem is in the two lines above. Rearranging algebraically, you'll find that the condition becomes:

if left <= rst1.recordcount - 2*counter +1 then

in other words, you're deducting the counter twice.
Rob
[flowerface]
 
I tested that. Don’t work.
It’s very stupid. I use a similar function and that works fine.
Thanks anyway
 
You tested what? My post above wasn't a suggestion - it was an explanation why your code is likely to be flawed.
Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top