Rules

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

Your work handed into Canvas should be an Rmarkdown file with text and code chunks that can be run to produce what you did. We do not take your word for what the output is. We may run it ourselves. But we also want the output.

You may ask questions if the wording of the questions are confusing. But the instructor will not be giving hints.

Quizzes must uploaded by the end of class (1:10). It should actually allow a few minutes after that, but those not uploaded by 1:10 will be marked late. Here is the link for uploading this quiz https://canvas.umn.edu/courses/330843/assignments/2795250.

Homeworks must uploaded before midnight the day they are due. Here is the link for uploading this homework. https://canvas.umn.edu/courses/330843/assignments/2795258.

Quiz 1

Problem 1

Write an R function that, given a numeric vector x returns a numeric vector whose components are the first 10 strictly positive components of x or all of the strictly positive components of x if there are fewer than 10. If x has no positive components, then your function should return a numeric vector of length zero.

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 numeric vectors having

And for each of the cases above show your function working on a vector having no non-positive components and also on another vector having some non-positive components. (So there are eight cases in total.)

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 NA or NaN components or is not of type "numeric".

Show that your new function still works on the data described in the preceding problem.

Note: In R the logical not operator is ! (exclamation point, also called bang). So to reverse a test, precede it with !. The expression ! (x < 0) does the same thing as x >= 0. This is illustrated several places in the notes but we did not mention it in class.

Problem 3

Modify the calculations of Section 7.5.4 of the first course notes Basics so that the statistical model is the Cauchy location family, that is, the Cauchy family of distributions (documented in the help for R function dcauchy) with unknown location parameter and known scale parameter, which we take to be the default value (1).

As in that section, use a function factory to make your log likelihood function.

Not only write a function, but also show it working for finding the MLE (maximum likelihood estimate) for the data obtained by the R command


x <- scan(url("https://www.stat.umn.edu/geyer/3701/data/2022/q1p3.txt"))

Note: If this does not work on your computer, see a note about downloading files. Of course, you have to modify the command used in that note to be the command used here. The point is to give R function scan a local file to input when the computer forbids downloads from the internet.

Note: For an interval to find the MLE use sample median plus or minus 1. Asymptotic theory says the standard error of the median considered as an estimator of the location parameter is (π ⁄ 2) ⁄ √ n where n is the sample size. This is much smaller than 1 here, so this interval should include the MLE.

Note: R function median calculates the median.

Note: For this problem ignore GIEMO (garbage in, error messages out). You do not have to detect erroneous arguments to your function.