# # Epage > 137 # # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- if(is.null(version$language) == FALSE){ require(alr3) }else{ library(alr3) } if(is.null(version$language) == FALSE) data(swan96) attach(swan96) postscript("../../WriteUp/Graphics/Chapter11/prob_4_scatterplot.eps", onefile=FALSE, horizontal=FALSE) plot( Day, LCPUE ) # fit quadratic polynomial to this data and plot with scatter plot m0 <- lm( LCPUE ~ Day + I(Day^2), data=swan96 ) xx <- seq(0,max(Day),length=100) lines( xx, predict(m0, data.frame(Day=xx)) ) dev.off() # use the delta method to estimate variance of the maximum delta.method(m0,"-b1/(2*b2)") # lets do the same problem via the bootstrap (first generate coefficients): # bCoefficients <- boot.case( m0, B=2000 ) # next compute the maximum: maxs <- -bCoefficients[,2]/(2*bCoefficients[,3]) print(mean(maxs)) print(sqrt(var(maxs))) # estimate the maximum with a nonlinear regression # ... use the linear model as an initial guess # cs = coefficients(m0) names(cs) = NULL b0 = cs[1] b1 = cs[2] b2 = cs[3] m1 = nls( LCPUE ~ th1 - 2 * th2 * th3 * Day + th3 * Day * Day, data=swan96, start=list( th1=b0, th2=-b1/(2*b2), th3=b2 ) ) summary(m1)