code: def get_R_corr2(x_avg, y_avg, x_segment, y_segment): #
      
      xd = x_segment - x_avg # detrend x_segment
      yd = y_segment - y_avg # detrend y_segment
      if sum(xd**2) * sum(yd**2) == 0: # prevent divide by zero error
          return float('nan')
      rcorr = old_div(sum((xd * yd))**2, (sum(xd**2) * sum(yd**2)))
      return rcorr
docs: input: x_avg, y_avg, x_segment, y_segment
      output: R_corr2