I have a data set where there is a lot of missing values; they are labelled Missing["Non-mesuré"]. When I append this data to another list of same length which has no missing data, and try to fit a line to those two lists with LinearModelFit[], I get the following error message:

LinearModelFit::notdata: The first argument is not a vector, matrix, or a list containing a design matrix and response vector.

I get that Missing["Non-mesuré"] is not data, but isn't the point of Missing[] to allow for missing values?

Here is a sample of the data:


And here is the code I first tried:


I also tried to remove the data points that contained missing values, without success:


So either it is possible to make the fit work with the missing data, or there is a way to exclude it when doing the fit. Either solution would brighten my day.

  • 2
    $\begingroup$ Missing sometimes work with functions but a fit is not one of those cases. You couold interpolate these points but this undermines the task of Fitting. So we just want to delete them. You can Easily do it with patternmatching with DeleteCases: DeleteCases[data,{_Missing,_}|{_,_Missing}] $\endgroup$ – Julien Kluge Dec 12 '16 at 16:40
  • $\begingroup$ Thanks a lot. What kind of functions, then, is Missing[ ] compatible with? $\endgroup$ – EBassal Dec 12 '16 at 16:44
  • 2
    $\begingroup$ Missing seems to be mostly for use in Associations, for returning missing values from Wolfram's curated data like CountryData or ElementData. It seems to be compatible with visualization tools like ListLinePlot. Otherwise, I suspect it's not useful. It's certainly unlikely to be useful for numerical functions and calculations. $\endgroup$ – march Dec 12 '16 at 16:51
  • 2
    $\begingroup$ Or something like LinearModelFit[Select[data, #[[2]] != "Missing[Non-mesuré]" &], x, x]. $\endgroup$ – JimB Dec 12 '16 at 18:10
  • 3
    $\begingroup$ another approach a bit more general: Cases[data, {_?NumericQ ..}]. This will also strip Indeterminate , undefined symbols and so on. $\endgroup$ – george2079 Dec 12 '16 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.