Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Issue with AvgSpa, StdDevSpa and CovSpa not behaving as expected when using a pointer to an element in the array


NNN Nov 12, 2020 09:32 AM

I am trying to write a subroutine that performs a linear regression using the AvgSpa, StdDevSpa and CovSpa functions. However it looks like the AvgSpa, StdDevSpa and CovSpa functions do not behave as expected when dereferencing a pointer to an element in the array. Any suggestions?

Sub LinearRegression(x As Float!, y As Float!, number_of_points As Long, slope As Float, intercept As Float)
  ' Calculate slope and intercept 
  ' 
  ' Args:
  '   x, pointer to array containing independent data
  '   y, pointer to array containing dependent data
  '   number_of_points, the number of regression points
  '   slope, the fitted slope
  '   intercept, the fitted intercept with the y-axis

  Dim cov_x_y As Float
  Dim std_x As Float
  Dim avg_x As Float
  Dim avg_y As Float
  Dim index As Long

  CovSpa(cov_x_y, 1, number_of_points, !x(1), !y(1))
  StdDevSpa(std_x, number_of_points, !x(1))
  AvgSpa(avg_x, number_of_points, !x(1))
  AvgSpa(avg_y, number_of_points, !y(1))  

  slope = cov_x_y / (std_x^2)
  intercept = avg_y - slope * avg_x
  
EndSub

 

Log in or register to post/reply in the forum.