Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Math 185 hw2



Problem 1.  (A comparison of running times)

A. Write a function permChisqTest(tab, B = 1e4) that takes in a table of joint counts tab and a number of Monte Carlo draws B and returns an estimate of the permutation p-value for the Pearson statistic based on B random permutations.

B.  Compare the running time of your function to chisq.test for the same  B =  1e6.   Use the School Admissions data (Homework 1, Problem 3).  [Hint:  to compute the processing time, use the function proc.time.  Try not to use your computer in other ways while performing these computations so as not to bias the results.]

 

 

Problem 2.  (The large-sample behavior of the median)  Consider Xl, . . . , Xn iid from some distribution F with density f .  We assume that F has a unique median θ.  If f is continuous at θ with f (θ) > 0, the sample median is, as n becomes large, approximately normal with mean θ and variance 1/(4nf (θ)2 ).  Perform some Monte Carlo simulations to verify this theoretical result numerically.  One way to do that is to generate a sample of size n from F , compute the sample median, repeat a large number of times, and then compare the distribution of these sample medians with the asymptotic distribution.  A histogram overlaid with the asymptotic density can provide a good visual assessment, and a goodness-of-fit test can provide a more quantitative assessment. This can be done for various values of n to gauge how accurate the asymptotic distribution is in finite samples.  For F , choose the standard normal distribution, and then another distribution of your choice.