# Nutrients consumed daily, R analysis story board

[This article was first published on

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

With any relatively complicated programming task, I prefer to first create a story board that provides the steps I will take to complete the overall task. This may end up being a heavily edited post if I find that my plans change part way through.**R in the Antipodes**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The point of this analysis is to produce a cleaned distribution of nutrient intakes for the Australian population, using two 24-hour intake recall periods. The general method being followed is from here where the method has been implemented for SAS. I was a SAS programmer for around 12 years, but never had much to do with macros as all my programming tasks were one-offs. This has meant that understanding the SAS code has taken me a reasonable period of time.

The approach will use the data sets constructed in the previous blog post, which I cleaned in Excel using VBA.

The main steps are:

- Identify a test data set (in this case, energy (KJ) intake),
- Reprogram the SAS code into R, hard coding in the variable names from the cleaned data set as these will be standard for the data analysis of the various nutrients,
- Compare the output distribution to that obtained by the previous method of analysis, then if all goes well
- Output the cleaned distribution to a .csv file for subsequent use by the client, and then finally
- Automate the process for the client, e.g. include GUI features for the client to select the input .csv data set, so the user does not need to change any of the R code.

- the MASS package is used to Box Cox transform the data to normality,
- the reshape2 package is required to melt the data so that repeated measures are separate observations, not separate variables – this will double the length of the data set as all observations have two 24-hour recall periods, and
- mixed effects analysis is being undertaken using lme4.

Along the way, I will be doing some additional testing. The NCI method linked above uses a number of covariates, such as age group. The client has been analysing the data (not using the NCI method) separately by age group. I will be testing the effect on the overall intake distribution by:

- analysing separately for age group (3 age groups), versus
- using age group as fixed effect covariates, versus
- using age-in-years as a continuous fixed effect variable instead of age group covariates (there are >4000 observations so there are multiple observations per age-in-years)

To

**leave a comment**for the author, please follow the link and comment on their blog:**R in the Antipodes**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.