0

I am trying to use the linear regression function ee.Reducer.linearFit() in GEE.

But this function does not provide a mean to force the y-intercept to be equal to 0.

Is there functions I can use to force the y-intercept equal 0 in GEE?

Below is the code example without fixing y-intercept(GEE website, https://code.earthengine.google.com/74570c9f13022e5ee6e058d9fc132087):

// Define a list of lists, where columns represent variables. The first column
    // is the independent variable and the second is the dependent variable.
    var listenter code heresVarColumns = ee.List([
      [1, 1],
      [2, 2],
      [3, 3],
      [4, 4],
      [5, 5]
    ]);
    
    // Compute the least squares estimate of a linear function. Note that an
    // object is returned; cast it as an ee.Dictionary to make accessing the
    // coefficients easier.
    var linearFit = ee.Dictionary(listsVarColumns.reduce(ee.Reducer.linearFit()));
    
    // Inspect the result.
    print(linearFit);
    print('y-intercept:', linearFit.get('offset'));
    print('Slope:', linearFit.get('scale'));

1 Answer 1

0

Compute your own linear regression with whatever variables you want. To force intercept to 0, omit the offset term (

var linearFit = ee.Dictionary(listsVarColumns.reduce(ee.Reducer.linearRegression(1, 1)));
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.