Rules

See the Section about Rules for Quizzes and Homeworks on the General Info page.

Your work handed into Moodle should be a plain text file with R commands and comments that can be run to produce what you did. We do not take your word for what the output is. We run it ourselves.

Note: Plain text specifically excludes Microsoft Word native format (extension .docx). If you have to Word as your text editor, then save as and choose the format to be Text (.txt) or something like that. Then upload the saved plain text file.

If you have questions about the quiz, ask them in the Moodle forum for this quiz. Here is the link for that https://ay16.moodle.umn.edu/mod/forum/view.php?id=1241814.

On future assignments you can use knitr or rmarkdown after we have talked about it. But avoid that on this assignment.

Quizzes must uploaded by the end of class (1:10). Moodle actually allows a few minutes after that. Here is the link for uploading the quiz https://ay16.moodle.umn.edu/mod/assign/view.php?id=1241821.

Homeworks must uploaded before midnight the day they are due. Here is the link for uploading the homework. https://ay16.moodle.umn.edu/mod/assign/view.php?id=1241828.

Quiz 2

Problem 1

Write an R function that, given a numeric matrix A and a numeric vector x, calculates xT A− 1 x. Note that this only makes sense when A is a square matrix and the dimension of x is the same as the dimensions of the row and column dimensions of A.

Follow GIEMO (garbage in, error messages out). Make sure your function gives an error when the dimensions are wrong or when either argument is not numeric. When either argument contains NA, NaN, Inf, -Inf, your function can give an error, give a warning, or produce one of these results (your choice).

We deduct points for actually inverting the matrix A. Think of this in terms of solving linear equations, instead.

We deduct points for using a loop or loops.

Not only write a function, but also show it working on the data obtained by the R command


load(url("http://www.stat.umn.edu/geyer/s17/3701/data/q2p1.rda"))
ls()

(This loads two R objects: a matrix a and a vector x.)

Problem 2

Rewrite your function for the preceding problem so it is a binary operator rather than an apparent function call, that is, if your function from the preceding problem was invoked

alice(a, x)
rewrite it so it is invoked
a %alice% x
(of course, you can change alice to any other valid R name.

Problem 3

Write a function that takes a numeric matrix and standardizes its columns (we will explain what this means). For any vector x its standardization is computed as follows.


(x - mean(x)) / sd(x)

Note that in the special case that the matrix has only one row, it cannot be standardized (because in that case the standard deviation of the columns is zero and the algorithm wants to divide by zero. You can either produce an error, a warning, or all components of the result NA, NaN, Inf, or -Inf, your choice.

There is no deduction of points for using a loop or loops in this problem.

Not only write a function, but also show it working on the data obtained by the R command


load(url("http://www.stat.umn.edu/geyer/s17/3701/data/q2p3.rda"))
ls()

(This loads one R object: a matrix a.)
But it might be better to add the error check
    stopifnot(nrow(a) > 1)
to the definition of standardize.