R intro

Page 65

Chapter 11: Statistical models in R

59

> fmod <- glm(y ~ A + B + x, family = poisson(link=sqrt), data = worm.counts)

Quasi-likelihood models For all families the variance of the response will depend on the mean and will have the scale parameter as a multiplier. The form of dependence of the variance on the mean is a characteristic of the response distribution; for example for the poisson distribution Var[y] = µ. For quasi-likelihood estimation and inference the precise response distribution is not specified, but rather only a link function and the form of the variance function as it depends on the mean. Since quasi-likelihood estimation uses formally identical techniques to those for the gaussian distribution, this family provides a way of fitting gaussian models with non-standard link functions or variance functions, incidentally. For example, consider fitting the non-linear regression y=

θ1 z1 +e z2 − θ2

which may be written alternatively as y=

1 +e β 1 x1 + β 2 x2

where x1 = z2 /z1 , x2 = −1/z1 , β1 = 1/θ1 and β2 = θ2 /θ1 . Supposing a suitable data frame to be set up we could fit this non-linear regression as > nlfit <- glm(y ~ x1 + x2 - 1, family = quasi(link=inverse, variance=constant), data = biochem) The reader is referred to the manual and the help document for further information, as needed.

11.7 Nonlinear least squares and maximum likelihood models Certain forms of nonlinear model can be fitted by Generalized Linear Models (glm()). But in the majority of cases we have to approach the nonlinear curve fitting problem as one of nonlinear optimization. R’s nonlinear optimization routines are optim(), nlm() and nlminb(), which provide the functionality (and more) of S-Plus’s ms() and nlminb(). We seek the parameter values that minimize some index of lack-of-fit, and they do this by trying out various parameter values iteratively. Unlike linear regression for example, there is no guarantee that the procedure will converge on satisfactory estimates. All the methods require initial guesses about what parameter values to try, and convergence may depend critically upon the quality of the starting values.

11.7.1 Least squares One way to fit a nonlinear model is by minimizing the sum of the squared errors (SSE) or residuals. This method makes sense if the observed errors could have plausibly arisen from a normal distribution. Here is an example from Bates & Watts (1988), page 51. The data are: > x <- c(0.02, 0.02, 0.06, 0.06, 0.11, 0.11, 0.22, 0.22, 0.56, 0.56, 1.10, 1.10) > y <- c(76, 47, 97, 107, 123, 139, 159, 152, 191, 201, 207, 200) The fit criterion to be minimized is:


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.