Optional Section (Not to be turned in)


The best way to get acquainted with any software package is to run it through its paces. If the tasks specified in the first three sections were not enough of a work out, you can try some of the commands given below. Again, the tasks below are 100% optional. They are included only as a source of possibly interesting things to do to gain familiarity with S.

  1. Generate a sample of size 100 from the exponential distribution with scale parameter using the command

    X rexp(100)

    (remember that when X has exponential distribution with scale parameter 1, then 3X has exponential distribution with scale parameter 3). Next, sort the sample using sort. Next, create a new vector yp as you did in Section I, except this time, let p contain 100 equally spaced values strictly between 0 and 1. Finally plot the sorted sample against this yp. What do you find?

  2. Now, generate a sample of size 100 from the exponential distribution with scale parameter 1, and form the vector Y as follows

    X<- rexp(100)

    Use the command hist to construct a histogram of Y. Keeping in mind that a histogram can be used to get an idea of what the density of a distribution looks like, what curve do you expect to see from this plot? (Hint: See the solution to Problem 7 in Section 1.7 of your text). Plot this curve within the range of the horizontal axis of the histogram.

    Try this problem again, but set Y = exp(X) and consult Problem 8 of Section 1.7 of your text.

  3. Create a vector p of ten positive numbers and normalize p as follows

    p<-p/sum(p)

    These commands will give you a vector of positive numbers that sum to one. Let X denote a random variable such that , where is the ith element of .

  4. Create a sample of size 100 from the distribution of X, using the sample command (type help(sample) to see the description of the new sample command. The old command given in the manual will not do here) , and examine a stem-and-leaf diagram of this sample using the stem command. Is this what you would expect? Try a histogram of this sample.