That was an internal error code, when input data has too few points, and in the case of FitLR, if input less then 2 data points.
#define STATS_ERROR_TOO_FEW_DATA_PTS -165
Did you put your script in an ogs file so we can avoid any issue on how the script is executed? I suspect this has something to do with the context of the script execution. You can add some debugging code to check the dataset.
CP