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=1221096.
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). It should actually allow a few minutes after that. Here is the link for uploading the quiz https://ay16.moodle.umn.edu/mod/assign/view.php?id=1221097.
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=1221099.
Quiz 1
Problem 1
Write an R function that, given a numeric
vector x
calculates its mean, population variance
,
and population standard deviation
, that is, if xi
are the components of x
and n is the length
of x
, then the mean is
population varianceis given by
population standard deviationis σ (the square root of the variance).
Do not use the R functions mean
, var
,
or sd
. You may use the R function sum
or any other
R function in the R core (what is available without using the R function
library
to attach a package).
Your function should return a list with three components named
mean
, var
, and sd
, which are the
three things you calculated.
For this problem you do not have to worry about GIEMO (garbage in, error messages out). That is the next problem. If your function does what it is supposed to when the input is correct, that gets full credit.
Not only write a function, but also show it working on the data obtained by the R command
x <- scan(url("http://www.stat.umn.edu/geyer/s17/3701/data/q1p1.txt"))
Problem 2
Rewrite your function for the preceding problem so it does GIEMO (garbage in, error messages out).
It should give an error if its argument has length zero,
has NA
or NaN
or Inf
or -Inf
components,
or is not of type "numeric"
.
Hint: in Section 8 of the first
course notes Basics
we used the function is.finite
.
Look it up and see if you want to use that.
Show that your new function still works on the data described in the preceding problem.
Problem 3
Modify the calculations of
Sections 7.5.2, 7.5.3, and 7.5.4 of the first
course notes Basics
so that they are done by one R function.
Your R function will have one argument, which is the data
(x
in the example in the notes) and will produce
one scalar value, which is the MLE (maximum likelihood estimate)
(oout$maximum
in the example in the notes).
For this problem you can use the easier
method of Section 7.5.3
of the first course notes because inside your function x
is not
a global variable (hence not evil
) because it is a local variable
in your function.
For this problem you do not have to worry about GIEMO (garbage in, error messages out). If your function does what it is supposed to when the input is correct, that gets full credit.
Not only write a function, but also show it working on the data obtained by the R command
x <- scan(url("http://www.stat.umn.edu/geyer/s17/3701/data/q1p3.txt"))