Tools/rstudio
Rstudio is a tool do do statistical analysis on data.
Recipe
The tool can be used to find the recipe of products.
Steps
We use the order as found on packaging, i.e. fat, sat. fat, carbs, sugar, fiber, proteins, salt).
Create the product data, e.g:
product <- c(58.0, 6.4, 6.4, 4.2, 8.5, 0.01)
Create the individual ingredients, eg.:
walnuts <- c(67.3, 6.45, 6.88, 3, 6.7, 13.3, 0.1)
Create the ingredients, e.g.:
ingredients <- c(walnuts, hazelnuts, cashews, almonds)
Create the array for 4 ingredients, e.g.:
Z <-array(ingredients, dim=c(7,4))
Fit:
lsFit <- lm(y~Z)
Fit with no intercept:
lsFitZero <- lm(y~Z +0)
Fit with no negative coefficients:
nnFit <- nnls(Z,y)
GLMN-fit
glmnetFit <- glmnet(Z,y, lambda = 0, lower.limit = 0, intercept = FALSE)
Dataframe:
plotData <- data.frame(variance,residuals)
Graph
ggplot(plotData, aes(variance,residuals)) + geom_point() + labs(title="Comparing ingredients") + annotate(geom = "text", x = 0.4, y = 0.1, label = "Wheat 110 + butter") + annotate(geom = "text", x = 1.4, y = 0.8, label = "Wheat 110 + butteroil") + annotate(geom = "text", x = 1.4, y = 0.2, label = "Wheat 150 + butter") + annotate(geom = "text", x = 0.4, y = 0.9, label = "Wheat 80 + butter")
Nutrients blame chart
What ingredients are to blame for a specific nutrient? Can work with a stacked barchart. Each Nutrient on the horizontal axis. Each bar shows which ingredient has contributed to that nutrient. Each ingredient should have its own colour.
For each ingredient we have a coefficient. This coefficient should be multiplied with nutritional values. So we get an array for each nutrient. This should be fed into the dataFrame.
Ingredient order constraint
In order to enforce the ingredient order in the R models, things need to be done differently. The model must be closer to a multivariate version. Need to experiment how this can be done.
An approach is to assume that the data for each ingredient is a measurement. Thus we will have 7 measurements. This will be put in an array with 7 rows and 1 column. This must be done for each ingredient. And the names of the columns can be given as well, which helps handling later.