HW 19 Stat 705 Fall 2017 -------------------------- Assigned 11/28/2017, due 12/6 16 points ============================== Assigned Tuesday 11/28/17 DUE Wednesday 12/6/17 ---------------------------------------------- Read in the dataset "anorexia" from the MASS library datasets, containing experimental treatment labels and pre- and post-test weights for 72 anorexic women. (A) Plot a scatterplot of the Postwt versus Prewt for these data, using a different plotting character for each of the three Treat groups. Provide axis labels, a graph title, and a legend for your plotting characters. (B) On the same graph axes, plot fits of the following curves y = g(x) = E(Postwt | Prewt=x) to these data: (i) a polynomial regression of degree 3 (fitted by ordinary or weighted least squares), (ii) a cubic smoothing spline with all points as knots, (iii) a local polynomial regression of degree 2. You may use the defaults in the R functions you call to do the fitting, but you should say what they are on these data. Also, you will have to select reasonable bandwidths in (ii), (iii). Find a way to display the raw scatterplot along with the 4 fitted curves in one or two pictures, with appropriate labeling and legends for the nonparametric regressions. Hand in the R code for your curve fits and the pictures. (C) Consider the density function f(t) = C t/(1+t^3+t^5) for t > 0. Code a function Finv(x) closely approximating the inverse of the cumulative distribution function for this density by the following steps. (i) For the points pts[i] = 1/(1-i/5001)^0.25-1, i=1,...,5000, evaluate the distribution function cdf[i] = F(pts[i]) using numerical integration to accuracy at least 1.e-6. (ii) Fit a smoothing spline to the points (cdf[i], pts[i]), i=1,...,5000, with high smoothing parameter (say, spar=0.5 or 0.6), and code Finv(x) as the (vectorized) function on new data x on the interval (0,cdf[5000]) obtained by using predict on the fitted smooth.spline object. (iii) Find a way to estimate the accuracy of Finv as an approximation of the inverse distribution function.