\HeaderA{mgcv-package}{GAMs with GCV smoothness estimation and GAMMs by REML/PQL}{mgcv.Rdash.package}
\keyword{package}{mgcv-package}
\keyword{models}{mgcv-package}
\keyword{smooth}{mgcv-package}
\keyword{regression}{mgcv-package}
\begin{Description}\relax
\code{mgcv} provides functions for generalized additive modelling  and
generalized additive mixed modelling. The term GAM is taken to include 
any GLM estimated by quadratically penalized (possibly quasi-) likelihood maximization.

Particular features of the package are facilities for automatic smoothness selection, 
and the provision of a variety of smooths of more than one variable. User defined 
smooths can be added. A Bayesian approach to confidence/credible interval calculation is
provided. Linear functionals of smooths, penalization of parametric model terms and linkage 
of smoothing parameters are all supported. Lower level routines for generalized ridge 
regression and penalized linearly constrained least squares are also provided.
\end{Description}
\begin{Details}\relax
\code{mgcv} provides generalized additive modelling functions \code{\LinkA{gam}{gam}},
\code{\LinkA{predict.gam}{predict.gam}} and \code{\LinkA{plot.gam}{plot.gam}}, which are very similar
in use to the S functions of the same name designed by Trevor Hastie (with some extensions). 
However the underlying representation and estimation of the models is based on a
penalized regression spline approach, with automatic smoothness selection. A
number of other functions  such as \code{\LinkA{summary.gam}{summary.gam}} and \code{\LinkA{anova.gam}{anova.gam}} 
are also provided, for extracting information from a fitted \code{\LinkA{gamObject}{gamObject}}.

Use of \code{\LinkA{gam}{gam}} is much like use of \code{\LinkA{glm}{glm}}, except that
within a \code{gam} model formula, isotropic smooths of any number of predictors can be specified using
\code{\LinkA{s}{s}} terms, while scale invariant smooths of any number of
predictors can be specified using \code{\LinkA{te}{te}} terms. \code{\LinkA{smooth.terms}{smooth.terms}} provides an 
overview of the built in smooth classes. Estimation is by
penalized likelihood or quasi-likelihood maximization, with smoothness
selection by GCV or gAIC/ UBRE. See \code{\LinkA{gam}{gam}}, \code{\LinkA{gam.models}{gam.models}}, 
\code{\LinkA{linear.functional.terms}{linear.functional.terms}} and \code{\LinkA{gam.selection}{gam.selection}} for some discussion of model specification and
selection. For detailed control of fitting see \code{\LinkA{gam.convergence}{gam.convergence}},
\code{\LinkA{gam.method}{gam.method}} and \code{\LinkA{gam.control}{gam.control}}. For checking and
visualization see \code{\LinkA{gam.check}{gam.check}}, \code{\LinkA{choose.k}{choose.k}}, \code{\LinkA{vis.gam}{vis.gam}} and \code{\LinkA{plot.gam}{plot.gam}}.
While a number of types of smoother are built into the package, it is also
extendable with user defined smooths, see \code{\LinkA{smooth.construct}{smooth.construct}}, for example.

A Bayesian approach to smooth modelling is used to derive standard errors on
predictions, and hence credible intervals. The Bayesian covariance matrix for
the model coefficients is returned in \code{Vp} of the
\code{\LinkA{gamObject}{gamObject}}. See \code{\LinkA{predict.gam}{predict.gam}} for examples of how
this can be used to obtain credible regions for any quantity derived from the
fitted model, either directly, or by direct simulation from the posterior
distribution of the model coefficients. Approximate p-values can also be obtained for testing 
individual smooth terms for equality to the zero function, using similar ideas. Frequentist
approximations can be used for hypothesis testing based model comparison. See \code{\LinkA{anova.gam}{anova.gam}} and
\code{\LinkA{summary.gam}{summary.gam}} for more on hypothesis testing.

The package also provides a generalized additive mixed modelling function,
\code{\LinkA{gamm}{gamm}}, based on a PQL approach and  
\code{lme} from the \code{nlme} library. \code{gamm} is particularly useful
for modelling correlated data (i.e. where a simple independence model for the
residual variation is inappropriate). In addition, low level routine \code{\LinkA{magic}{magic}}
can fit models to data with a known correlation structure.

Some underlying GAM fitting methods are available as low level fitting
functions: see \code{\LinkA{magic}{magic}} and \code{\LinkA{mgcv}{mgcv}}. But there is little functionality 
that can not be more conventiently accessed via \code{\LinkA{gam}{gam}} . 
Penalized weighted least squares with linear equality and inequality constraints is provided by 
\code{\LinkA{pcls}{pcls}}.

For a complete list of functions type \code{library(help=mgcv)}.
\end{Details}
\begin{Author}\relax
Simon Wood <simon.wood@r-project.org>

with contributions and/or help from Kurt Hornik, Mike Lonergan, Henric Nilsson
and Brian Ripley. 

Maintainer: Simon Wood <simon.wood@r-project.org>
\end{Author}
\begin{References}\relax
Wood, S.N. (2004) Stable and efficient multiple smoothing parameter estimation for
generalized additive models. J. Amer. Statist. Ass. 99:673-686. 

Wood, S.N. (2006) \emph{Generalized Additive Models: an introduction with R},
CRC

Wood, S.N. (2008) Fast stable direct fitting and smoothness selection for generalized
additive models. J.R.Statist.Soc.B 70(3):495-518
\end{References}
\begin{Examples}
\begin{ExampleCode}
## see examples for gam and gamm
\end{ExampleCode}
\end{Examples}

