For each of the problems below (except in cases where you are asked to discuss your interpretaion) write R code blocks that will compute appropriate solutions. A good rule of thumb for judging whether your solution is appropriately “computable” is to ask yourself “If I added or changed observations to this data set, would my code still compute the right solution?”
When completed, submit your R Markdown document (the file with the extension .Rmd) and the knit HTML via Sakai.
Each of the problems below is worth 4 pts. Use matrix arithmetic operations to solve each problem. Each function may call earlier defined functions.
Write a function, mean.vector(X), that takes a matrix of real values (doubles) and returns the column means as a vector. Do not use built-in vector functions such as sum(), mean(), colSums(), etc.
Write a function, deviation.matrix(X), that takes a matrix of real values and returns a matrix the represents each values deviation from it’s respective column mean. Do not use built-in functions such as scale().
Write a function covariance.matrix(X), that takes as input a matrix of real values (variables in columns) and returns a covariance matrix. Compare the results with built-in cov() function to make sure your function works properly.
Write a function correlation.matrix(X), that takes as input a matrix of real values (variables in columns) and returns a correlation matrix. Compare the results with built-in cor() function to make sure your function works properly.