Homework #5
This assignment is due on Monday, April 7.
You should turn in sufficient work to indicate
that you have completed the assignment.
I ask you to do a number of things which refer back to old lectures.
Problems 1-3 refer back to the lecture on algorithms for the mean and
standard deviation.
The remaining problems refer to the lecture notes
on random number generation.
Problems
- Verify that the two formulae for updating the mean and sum of squares
in the lecture notes for the method of provisional means are correct.
Hint. Begin with the expressions for m_k - m_{k-1}
and s_k - s_{k-1} using their definitions and manipulate
to match the given expressions.
- Write functions in S-PLUS which implement the desk calculator algorithm,
the method of provisional means, and the subtract-the-first-value algorithm,
to return the standard deviation of an array of numbers.
Also consider this modification
of the built in S-PLUS function var.
sd <- function(x) { sqrt(var(x)) }
Try them out on a few challenging examples and report which method(s)
appear to do the best.
- Read the on-line lecture notes where it discusses the machine EPSILON
of a computer.
Find the smallest value of the form 2^{-k} such that S-PLUS
computes the sum of 1 plus this value to be a number different than 1.
- Write a function in S-PLUS which generates a sequence of n
pseudo-random variables according to a linear congruential random number
generator.
The function should take n as a required variable
and have the seed, a, c, and m,
be variables with default settings.
A choice could be the RANDU values mentioned in class:
seed = 1 or anything non-zero, a = 65539, c = 0,
and m = 2^31.
- Test RANDU and runif from S-PLUS according to several
measures to see if they do a good job of generating random numbers.
Specifically, for each generator generate a sequence of 10,000 numbers.
For each sequence, complete the following tests.
- Do a chi-square goodness of fit test
where the interval is divided into 1024 pieces.
Hint. You can use hist
to do the counting for you.
- Plot the autocorrelation function using acf.
- Create a matrix with first row x_1, x_2, x_3,
second row x_4, x_5, x_6, and
third row x_7, x_8, x_9, etcetera.
Use the function spin to see if these points plotted
in three dimensional space are located uniformly in the unit cube,
as they should be if they were genuine independent random variables.
Last modified: April 1, 1997
Bret Larget,
larget@mathcs.duq.edu