1

I am using multiple linear regression by ee.Reducer.linearRegression reducer fuction. I have 3 independents ('x1', 'x2', 'x3' ) and 1 dependent ('y'). When I using any combination of 2 independents from 3 independents, it would return a perfect solution. But when I using the 3 independents, It would return the results with many gaps (nulls). I see in the documentation around the linear regression reducer that "Both outputs are null if the system is underdetermined, e.g. the number of inputs is less than or equal to numX.". I believe that I am passing the correct number of inputs in.

var ndvi_lst_anomalies = ee.List.sequence(0,34,1).map(function(i){
  var ndvi_n = ee.Image(all_desens_N.get(i)).select('b1').subtract(all_desens_N_mean).rename('ndvi');
  var ndvi_s = ee.Image(all_desens_S.get(i)).select('b2').subtract(all_desens_S_mean).rename('ndvi');
  var y = ndvi_n.subtract(ndvi_s).rename('y');
  
  var lst_n = ee.Image(LST_N.get(i)).subtract(LST_mean_N).rename('lst');
  var lst_s = ee.Image(LST_S.get(i)).subtract(LST_mean_S).rename('lst');
  var n_s_lst_ano = lst_n.subtract(lst_s);
  var lst_ano_mean = ee.ImageCollection([lst_n,lst_s]).mean();
  
  var x1 = n_s_lst_ano.multiply(lst_ndvi_mean).rename('x1');
  var x2 = lst_ano_mean.multiply(p_e_lst_ndvi).rename('x2');
  var x3 = n_s_lst_ano.multiply(p_e_lst_ndvi).rename('x3');
  
  return x1.addBands(x2).addBands(x3).addBands(y).copyProperties(ndvi_n,['system:time_start'])

})
Map.addLayer(ee.ImageCollection(ndvi_lst_anomalies))
ndvi_lst_anomalies = ee.ImageCollection(ndvi_lst_anomalies).reduce(ee.Reducer.linearRegression(3,1));
//print(n_AT_PR)
//Map.addLayer(n_AT)
var bandNames = [['x1','x2','x3'], // 0-axis variation.
                 ['y']]; // 1-axis variation.

// Flatten the array images to get multi-band images according to the labels.
var lrImage = ndvi_lst_anomalies.select(['coefficients']).arrayFlatten(bandNames);

Map.addLayer(lrImage)

The link is https://code.earthengine.google.com/3e53a1724de27149175d71bb1f53b960?noload=1

1 Answer 1

0

This is interesting, and I don't quite understand why this happens. If you convert your values to int64 by multiplying with 1e8, this works. I'm guessing that the linear regression uses float, not double and that somehow remove enough resolution that the linear regression doesn't pick up the variations. With this tweak, it seems like the only missing pixels are where there isn't enough observations.

var ndvi_lst_anomalies = ee.List.sequence(0,34,1).map(function(i){
  ...
  return x1.addBands(x2).addBands(x3).addBands(y)
    .multiply(1e8)
    .int64()
    .copyProperties(ndvi_n,['system:time_start'])
})

Map.addLayer(ee.ImageCollection(ndvi_lst_anomalies), null, 'collection')
var count = ee.ImageCollection(ndvi_lst_anomalies).select(0).reduce(ee.Reducer.count()) //
ndvi_lst_anomalies = ee.ImageCollection(ndvi_lst_anomalies).reduce(ee.Reducer.linearRegression(3,1));
var missing = count.mask().and(ndvi_lst_anomalies.select(0).mask().not())
Map.addLayer(count, {min: 0, max: 35}, 'count')
Map.addLayer(missing, null, 'missing')

https://code.earthengine.google.com/ab6015d50ba6bc8c8e8cd1bb83fde2c7

I would very much like someone else to chip in and explain this behavior.

1
  • Thanks a lot for your suggestion, it worked!
    – guoyan
    Apr 19, 2023 at 11:31

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.