Fit Linear Model Using Generalized Least Squares
This function fits a linear model using generalized least squares. The errors are allowed to be correlated and/or have unequal variances.
gls(model, data, correlation, weights, subset, method, na.action, control, verbose)
- a two-sided linear formula object describing the
model, with the response on the left of a
~operator and the terms, separated by
+operators, on the right.
- an optional data frame containing the variables named in
subset. By default the variables are taken from the environment from which
- an optional
corStructobject describing the within-group correlation structure. See the documentation of
corClassesfor a description of the available
corStructclasses. If a grouping variable is to be used,
- an optional
varFuncobject or one-sided formula describing the within-group heteroscedasticity structure. If given as a formula, it is used as the argument to
varFixed, corresponding to fixed variance weights. See the do
- an optional expression indicating which subset of the rows of
datashould be used in the fit. This can be a logical vector, or a numeric vector indicating which observation numbers are to be included, or a character vector of the
- a character string. If
"REML"the model is fit by maximizing the restricted log-likelihood. If
"ML"the log-likelihood is maximized. Defaults to
- a function that indicates what should happen when the
NAs. The default action (
glsto print an error message and terminate if there are any incomplete observations.
- a list of control values for the estimation algorithm to
replace the default values returned by the function
glsControl. Defaults to an empty list.
- an optional logical value. If
TRUEinformation on the evolution of the iterative algorithm is printed. Default is
- an object of class
glsrepresenting the linear model fit. Generic functions such as
summaryhave methods to show the results of the fit. See
glsObjectfor the components of the fit. The functions
fittedcan be used to extract some of its components.
The different correlation structures available for the
correlation argument are described in Box, G.E.P., Jenkins,
G.M., and Reinsel G.C. (1994), Littel, R.C., Milliken, G.A., Stroup,
W.W., and Wolfinger, R.D. (1996), and Venables, W.N. and Ripley,
B.D. (1997). The use of variance functions for linear
and nonlinear models is presented in detail in Carroll, R.J. and Ruppert,
D. (1988) and Davidian, M. and Giltinan, D.M. (1995).
Box, G.E.P., Jenkins, G.M., and Reinsel G.C. (1994) "Time Series Analysis: Forecasting and Control", 3rd Edition, Holden-Day.
Carroll, R.J. and Ruppert, D. (1988) "Transformation and Weighting in Regression", Chapman and Hall.
Davidian, M. and Giltinan, D.M. (1995) "Nonlinear Mixed Effects Models for Repeated Measurement Data", Chapman and Hall.
Littel, R.C., Milliken, G.A., Stroup, W.W., and Wolfinger, R.D. (1996) "SAS Systems for Mixed Models", SAS Institute.
Venables, W.N. and Ripley, B.D. (1997) "Modern Applied Statistics with S-plus", 2nd Edition, Springer-Verlag.
data(Ovary) # AR(1) errors within each Mare fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) # variance increases as a power of the absolute fitted values fm2 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, weights = varPower())