Recipe/Theory/Statistics exploration

From Open Food Facts wiki
(Redirected from Recipe/Statistical theory)
Jump to navigation Jump to search

Finding the recipe of a product based on the list of ingredients and nutritional values, is a statistical problem of Linear regression for which a lot of theory exists. The recipe fitting problem is very specific and it is a bit difficult to find the right statistical approach in all the dense wikipedia pages.

Simple regression

We are not used to the terminology used in linear regression statistics, so some translation is needed:

  • dependent variables / observed values (y) - these comparable to a nutrient of the product. Usually there are many values y observed (n dimensions);
  • regressors / independent variable (x) - this is a nutrient in an ingredient. This independent variable kan have multiple dimensions p;
  • regression coefficients (β) - the recipe fraction. In a general situation β can have p values for each observation (making a matrix);
  • error term (ε) - the deviation from the fit for each observation;


This gives the relation:

(1) y = X β + ε

The recipe estimation is much simpler:

  • there is only one product, so only 1 observed value, so n = 1;
  • but also p = 1, as there is only one percentage per ingredient;

This simplifies the relation (1) to a simple multiplication for products with one nutrient. And in that case ε = 0.

Relation (1) could be extended with a term β0, which designates the intercept. In the recipe case this is 0, i.e. if there are no nutrients in the ingredient, then there are also nu nutrients in the product. In a mathematic approach it might be necessary to retain the β0 though.

Multivariate regression

Clearly we need a more complicated approach that supports multiple ingredients and multiple nutrients. The theory that corresponds to this is general multivariate regression. The corresponding formula is:

(2) Y = X B + U

In this formula

  • Y is a matrix observations yij, with i an observation and j an aspect like a nutrient;
  • X is the matrix of the nutrients for each ingredient;
  • B the matrix of the recipe fractions for each obervation;
  • U is a matrix containing the errors, which we will try to minimise;

As we have only one observation, (2) reverts to a simple matrix calculation. And now it corresponds to the formula we have originally. But the multivariate solutions should be used otherwise we cannot support multiple nutrients.

Latent variables

The data used for the recipe estimation is very strange from a statistical point of view: the nutrients of the product are only related to the nutrients of the ingredients through their name. In a linear regression approach we should measure the nutrients of the ingredients before we do the processing and then measure the nutrients of the product. Are there statistical models that support this?

This wikipedia page discusses the difference between latent and observable variables. This seems to fit the recipe problem very well. The observable variables are the nutrients of the product, whereas the latent variables are ingredients. The examples are mostly from social sciences, so it is hard to transpose the recipe problem onto a social science problem.

There are many models classes and methodologies to find and quantify the latent variables. Of all these theories Factor analysis seems most appropriate.

Factor analysis

It is unclear whether Factor analysis is appropriate enough for the recipe problem.

One of the assumptions in Factor analysis is that there is a linear combination between the observed variables and the potential factors. This holds for the recipe problem, as the nutrients are clearly related to the ingredients used.

Factor analysis uses a loading matrix, which relates the factors to the observations. In the recipe case this will be the supposed nutrients for each ingredient.

The statistical model for Factor analysis assumes that there are multiple observations, which is not the case for the recipe problem.

The formula used in factor analysis is:

(3) X - M = LF + ε

With:

  • X the observed values;
  • M the mean of the observed values;
  • L the loading matrix
  • F the factors
  • ε the errors

The use of M here is worrisome, as it implies that one looks only at variations from the mean. The problem thus looks mainly at the variances. This is not comparable to a physical quantity like a nutrient.

Errors-in-variables model

An errors-in-variables model might be a better approach. This approach seems to use the fact that the observed variables and the latent variables are actual physical quantities (not sure how these should be called).

However an errors-in-variables model treats the unobserved regressors differently. In a recipe we cannot measure the nutrients of the ingredients, so these become latent variables. These latent variables then have errors, which must be taken into account in any fitting procedure. We do not even have the nutrients of the ingredients, but we use the nutrients of proxy ingredients (Ciqual ingredient).

Which errors-in-variables model can to be used depends on the relation between the observed errors and the errors in the latent variables. We do not know this ratio, but we can assume that the ratio δ = 1.

Using the assumption that δ = 1, the recipe problem reverts to an orthogonal Deming regression. The equations that must be used should be extended to a multivariate model (not a multivariable model), similar to what has been discussed earlier. This converts the Deming regression to a Total least squares model.

Multivariate errors-in-variables model

The Errors-in-variables model sections suggest that we should look for a total least squares solution in a multivariate setting. The wikipedia page for Multivariate statistics list the multivariate versions for many univariate variants, but not for the Total least squares. The total least square solution is an estimation procedure and not a statistical model. Searching the literature, the name Multivariate errors-in-variables model seems a better fit (1).

The multivariate formula presented earlier only needs to be adapted slightly:

(4) Y + EY =(A + EA) X

with:

  • Y the observation matrix (m x n);
  • EY the error matrix of the observations (m x n);
  • A the coefficient matrix (m x r);
  • EA the error matrix corresponding to A (m x r);
  • X the unknown parameters (r x n);
  • n the number of variates;
  • m the number of observations;
  • r the size of the solution;

The next step is to find X, either through a total least squares solution, or via a maximum likelihood solution.

In the recipe problem with just one observation, the Multivariate EIV model should convert to a general model, with simpler vectors and matrices. The solutions offered in document (1) are not (yet?) necessary. So no need to comprehend the algebra.

Remaining theoretical issues

Although a Multivariate errors-in-variables model seems to fit what is be done with the recipe problem, some issues remain. Solutions for this might be found in the literature.

Latent variables

A big issues are the latent variables is the recipe problem. The idea is that a proxy variable is used. This can be taken from the Ciqual or some other source. The problem is that there will be only one variable per observation. It is assumed that these are related, but there is no guarantee.

Lack of observational fitting

All statistical models assume that there are multiple observations. In the recipe case there is only one. This means that m = 1, which simplifies the equations enormously. But are we still trying to solve a statistical problem?

Constraints

  • The observable variables will between 0 and 1;
  • The latent variables will be between 0 and 1;
  • There are some constraints to the variates, like
    • the sum of the variates can not be large than one;
    • some variates will always be smaller than other variates (sugar<carbohydrates);

How can these constraints enter the formula's?

Unsatisfactory

The review of possible statistical models based on multivariate linear regression is unsatisfactory. Probably we will get the math correctly working, but it does not reflect what we are actually doing. Another way to look at the data and measurements is needed. For that a refrasing of a recipe is required. An attempt is made here.

Correlations

I briefly looked at the various theories around correlations, but those do not fit the bill.

Convolutions

The various theories around convolutions seem more appropriate. Convolutions is about combining probability distribution, which will give a new probability distributions. In the discussions before we already showed that we are combining distributions.

Each ingredient will have a distribution of nutritional values depending on how it is produced and how it is processed. To get to the distribution of a product we need to combine the distributions of the ingredients. We cannot simple add up distributions as this would imply that for a specific we would have used a specific ingredient. Instead we need to calculate a convolution, which means that for each point in the distribution of an ingredient, we could have any value of the distribution of another ingredient.

The problem with this approach is that it uses continuous functions. Those are not available to us. We might do a beta function fit to every ingredient. Then we can do convolutions of these fitted functions to predict the distribution of a product nutrients. The best recipe is then found by fitting the observed distribution against the predicted ingredient distributions. This however seems pretty unfeasible. No solutions for this could be found in the literature.

Time to downgrade. Instead of using functions one could imagine to use the actual data for products and ingredients. I guess it will involve fitting a recipe against all possible combinations of products and ingredients. No solutions for this can be found in the literature either. A very big question whether this is scalable. It is doable and might be worth an experiment some time.

OFF solution

As no statistical theory for the recipe problem can be found at the moment, we have to make things up a bit. We might use the mathematical approaches used for some least squares fitting problems.

No errors solution

The No errors solution assumes that we are looking for an exact solution. This will disregard and spread in the nutritional values. The solution will be similar to the examples here, but then extended to multiple nutrients.

We retake formula (1) of Recipe estimation and simplify:

i = Σj=0N-1 xij βj

This needs to be compared to the nutrients of the product yi for all i.

The best fit can be found through a least squares solution. The same formula's can be used, but the mening of the parameters will be different.

References

  1. The maximum likelihood estimation for multivariate EIV model
  2. Weighted total least squares solutions for applications in geodesy