# [R] Deformulation and R

S Ellison S.Ellison at LGCGroup.com
Mon Jan 21 16:40:39 CET 2013

```Usually, foods have more ingredients than listed nutritional component values. Further, for many foods nutritional composition (particularly fat, protein, fibre,  carbohydrate, calorie count) are cacluated from the ingredient list and caloprie count in particular is derived from the fat, protein and carbohydrate levels.

The practical outcome of those features is that you will often have more unknowns (ingredient content) than knowns (nutritional composition values), and on top of that fewer _independent_ 'knowns' than the label is telling you. That would leave you with a fundamentally insoluble problem.

Having said that, if you are in the more useful position of having more nutritional component values than ingredients, in principle you just have a linear model that relates the amount of each ingredient to the declared nutritional composition, with 'known' levels of nurititional component for each ingredient from somewhere like McCance and Widdowson, and the unknowns being the coefficients for each nutirent ingredient . That can be solved by linear modelling - essentially a multiple regression problem with the observed nutritional component values as the fitted responses. I'm not sure that can be solved directly in lm, though I _think_ it could possibly be so set up, but I'm quite sure sure that if not, it could be done via iterative numerical methods (optim and the like in R). After all, you only need to guess the ingredient list, calculate nutiritional values, compare with observed, and update the guess - which is what optim does - so all you need at the heart of it all is a function that can predict the nutritional composition from a set of ingredient valuesand a way of measuring the 'distance' of the guess from th e label values.

On the down side, nuritional components are likely to have very different units, scaling and uncertainty so the weighting is going to be very hard to justify. Ideally, I'd do this - if at all - on a nice large selection of products I knew the answers for before trusting it on new foods.

S Ellison

> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of Lorenzo Isella
> Sent: 19 January 2013 19:42
> To: r-help at stat.math.ethz.ch
> Subject: [R] Deformulation and R
>
> Dear All,
> I hope this is not too off-topic.
> Essentially, I need to know if there is any R package which
> can help me with a deformulation project.
> Suppose e.g. that you know from a chemical analysis the fat,
> mineral, vitamin, energy [and so on] content of a certain
> food product.
> You also know the ingredients of this product (e.g. milk,
> lactose, vegetable oil) and you know the chemical composition
> of each ingredient in terms of fat, minerals, vitamins etc...
> At this point the question, assuming that the procedure to
> create the product from the ingredients does not alter the
> chemical composition of any ingredient, is to determine the
> amount of each ingredient (milk, lactose, vegetable oil) in
> the final product.
> Can anyone point me in the right direction?
> Many thanks
>
> Lorenzo
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help