Difference between revisions of "Tools/rstudio"
Jump to navigation
Jump to search
Line 35: | Line 35: | ||
Graph | 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") | 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. |
Revision as of 17:37, 2 February 2025
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.