Learn R Programming

caper (version 0.4)

pgls: Phylogenetic generalized linear models

Description

Fits a linear model, taking into account phylogenetic non-independence between data points. The strength and type of the phylogenetic signal in the data matrix can also be accounted for by adjusting branch length transformations (lambda, delta and kappa). These transformations can also be optimised to find the maximum likelihood transformation given the data and the model.

Usage

pgls(formula, data, lambda = 1.0, kappa = 1.0,  delta= 1.0, param.CI = 0.95, control = list(fnscale=-1), bounds = list(lambda=c(1e-6,1), kappa=c(1e-6,3), delta=c(1e-6,3)))
pgls.likelihood(optimPar, fixedPar, y, x, V, optim.output=TRUE, names.optim=NULL)
pgls.blenTransform(V, fixedPar)

Arguments

formula
A model formula
data
A 'comparative.data' object containing the covariance matrix and data to be used in the model.
lambda
A value for the lambda transformation.
kappa
A value for the kappa transformation.
delta
A value for the delta transformation.
param.CI
A p value used to calculate confidence intervals.
control
A list of control parameters for the optim function.
bounds
A list of length three giving upper and lower bounds for branch length parameters.
optimPar
A named vector of branch length parameters to be optimised to find the maximum likelihood value.
fixedPar
A named vector of fixed values for branch length parameters.
y
A column matrix of the model response.
x
The design matrix of the model.
V
A phylogenetic covariance matrix.
optim.output
A logical value. If true then 'pgls.likelihood' returns only the likelihood value for use in the 'optim' function.
names.optim
The name of a single parameter being optimised. This is only required for estimating parameter confidence intervals, where the function 'uniroot' strips names from vectors.

Value

  • The 'pgls' function returns an object of class pgls containing the following:

    "na.action" "param.CI"

  • callThe original call to the 'pgls' function
  • modelA summary of the fitted model containing:
  • formulaThe model formula supplied.
  • dataThe comparative data object provided.
  • dnameThe name of the comparative data object.
  • logLikYThe log likelihood of the response variable given the model.
  • RMSThe residual mean square variance in the model.
  • RSSQThe residual sum of squares from the model.
  • NMSThe null mean square variance for the model.
  • NSSQThe null sum of squares for the response.
  • aicThe AIC score of the model
  • aiccThe AICc score of the model, correcting for the number of cases and parameters estimated
  • nThe number of rows of data used in fitting the model
  • kThe number of parameter estimates
  • sterrThe standard errors of the parameter estimates
  • VtThe phylogenetic covariance matrix used in the model, with branch length transformations applied.
  • fittedThe predicted values
  • residualsThe non-phylogenetic residuals
  • phyresThe phylogenetic residuals
  • xThe design matrix of the model
  • varNamesThe variables include in the model.
  • yThe response of the model.
  • nameyThe name of the response variable.
  • paramA named numeric vector of length three giving the branch length transformations used in the model.
  • mlValsA named logical vector of length three indicating which branch length values in 'param' are maximum likelihood estimates.
  • boundsThe bounds on branch length parameter estimates used in the model.
  • param.CIA named list of length three giving confidence intervals and the p values at the parameter bounds for optimised branch length transformations. Fixed parameters will have a NULL entry in this list.
  • na.actionA named vector identifying any rows of missing data excluded from the model.

Warning

The model is fitted using a data frame reduced to complete row cases to eliminate missing values. In order to ensure that the models fitted using different subsets of the data are comparable, the whole data frame data is reduced to complete cases. In the future, a scope argument may be provided to control this but at present the data frame should be reduced to only those variables used in the maximal model in order to avoid prevent redundant variables causing rows to be dropped unnecessarily.

Details

This function fits a linear model controlling for the non-independence between cases resulting from phylogenetic structure in the data. The stucture of the phylogenetic signal can be controlled by altering the parameters lambda, delta and kappa (see the 'caper' vignette for details). The implementation of the method is currently as described in Freckleton et al (2002).

The 'pgls.likelihood' and 'pgls.blenTransform' methods are not primarily intended to be called by users. The 'pgls.likelihood' function provides a general method to calculate the likelihood of a model, given the covariance matrix, response, design matrix and branch length parameters.

References

R. P. Freckleton, P. H. Harvey, and M. Pagel. Phylogenetic analysis and comparative data: A test and review of evidence. American Naturalist, 160:712-726, 2002.

See Also

pgls.profile, anova.pgls, summary.pgls

Examples

Run this code
data(shorebird)
shorebird <- comparative.data(shorebird.tree, shorebird.data, Species, vcv=TRUE, vcv.dim=3)
mod1 <- pgls(log(Egg.Mass) ~ log(M.Mass) * log(F.Mass), shorebird, lambda='ML')
mod2 <- pgls(log(Egg.Mass) ~ log(M.Mass), data=shorebird, lambda='ML', delta='ML')

Run the code above in your browser using DataLab