The variables are "case", "initial" and "eaten". We will explore linear regression and nonlinear regression to get models to fit the data.
symbol1 c=black i=none value=star ; symbol2 c=black i=join value=none ; axis1 label=('Initial Egg Density'); axis2 label=('Eggs Eaten'); proc gplot data=sasuser.rwg180; plot eaten*initial PRED*initial /overlay haxis=axis1 vaxis=axis2; run;
The parameter beta is probably more tricky to guess at. Here is one approach -- the key idea is to take the mean of the nonlinear regression and transform the data so that the mean is a linear function in beta. Similar to what we did in class -- remember that logs get rid of exps. 1) Take the guess of alpha, a0, (it should be larger than all of the Eaten values otherwise this won't work). Divide everything by a0 and subtract both sides of equation 15.8 from 1. Ignoring the error term, we have:
1 - Eaten/a0 = exp(-beta*Initial)If we take the natural logs of both sides we get:
log(1 - eaten/a0) = -beta*Initialwhich suggests that a good estimate of beta can be obtained it a linear regression of log(1 - Eaten/a0) on "Initial". To do this, you must add the transformed Y variable to the data set. Although you could do this with theINSIGHT transformations, it is easier to just Submit the following lines in the PROGRAM EDITOR window:
data sasuser.rwg180; set sasuser.rwg180; y = log(1 - eaten/a0); run; proc reg data=sasuser.rwg180; model y = initial; run;Remember that the dataset can't be open when you are Submitting these commands! Substitute your number for a0!
A starting value for beta is the -1*(slope coefficient) from the above regression. (look in the OUTPUT window.) The starting value for alpha equals a0.
data sasuser.rwg180; set sasuser.rwg180; yhat = a0*(1 - exp(-b0*initial)); run; symbol1 c=black i=none value=star ; symbol2 c=black i=join value=none ; axis1 label=('Initial Egg Density'); axis2 label=('Eggs Eaten'); proc gplot data=sasuser.rwg180; plot eaten*initial yhat*initial /overlay haxis=axis1 vaxis=axis2; run;How well does this fit the data? We can use "trial and error" to get a better fit -- or use nonlinear least squares to find better estimates that minimize the residual sum of squares.
proc nlin data=sasuser.rwg180; parms a= a0 b= b0 ; model eaten = a*(1 - exp(-b*initial)); run;The output will be in the SAS:OUTPUT window. You'll notice that the output tells you the parameter estimates. You will want to make a plot of the residuals of this regression. The easiest way to do this is to make another new variable in your data set (isn't SAS programming fun?). Make sure that the dataset is closed, and Submit the following lines to the PROGRAM EDITOR window, using the parameter estimates for a and b:
data sasuser.rwg180; set sasuser.rwg180; fitted = a*(1-exp(-b*initial)); residual = eaten - fitted; run;Repeat the commands before to plot Eaten versus Initial and add the fitted curve.
Look at the residual plots (Residual vs Fitted)and comment. Is there any evidence that the model from the nonlinear regression is inadequate (lack of fit)? All assumptions for the linear model must apply for the nonlinear regression model -- do you see any problems? (explain)