
Name: ________________________________________
22S:166 Computing in Statistics
Instructor: Cowles
Midterm 2
Nov 6-7, 2007
Instructions: You may use Windows R, or if you prefer, you may log into a Linux
computer and run Linux R. Copy and paste your solutions into this Word document.
Submit your midterm by uploading it into ICON.
1. The sd function in R computes the sample standard deviation of a vector of
numbers. Write a function to do the following:
a. accept a vector of numbers
b. compute the sample standard deviation
c. obtain jackknife estimates of bias and standard error
d. return the original estimate, the bias-corrected estimate, and the standard error
Generate a random sample of size 20 from a Gamma density with parameters
shape=10 and rate=1, and use it as input to your jackknife function. Paste the
code for your function, the call to the function, and the output here.
2. Is the sample standard deviation a biased estimator, and does jackknife bias
correction make the bias better or worse? Carry out a simulation study to find
out for the case when the population distribution is Gamma with parameters
shape=10 and rate=1. Note that the following line of R code calculates the true
standard deviation of a Gamma density with parameters shape=alpha and
rate=beta.
truesd <- sqrt( alpha / beta^2)
Write an R program to carry out a simulation study as follows. Simulate S
replicate datasets of size n=20 from a Gamma(10,1) density. For each replicate
dataset, calculate the sample standard deviation and the jackknife bias-corrected
estimate.
Test and debug your code with S set small (5 or10). Do your final run with
S=1000. Summarize the results in a table that shows: the true population
standard deviation, the mean of the original statistic across datasets and the mean
of the jackknife bias-corrected estimates across datasets.
Paste your R code and the output from the final run here.