pwr: Phylogenetically weighted regression: a method for modeling...

Description Usage Arguments Value Note Author(s) References See Also Examples

Description

pwr.cv performs model cross validation on the holdout set holdout, K-fold cross validation can be specified using fold. pwr.treePlot plots the phylogeny and allows for plotting of PWR model coefficients at the tips of the tree. PWR model coefficients to be pllotted must be appended to the phylo4d object. pwr.phylobubbles plots either circles or squares corresponding to the magnitude of each cell of a phylo4d object, and allows the plotting of PWR moel coefficients. Model coefficients to be plotted must be appended to the phylo4d object

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
pwr(formula, phy4d, which.tips, bw, wfun, verbose = FALSE)

## S3 method for class 'pwr'
coef(object, ...)

pwr.cv(formula, phy4d, holdout, coef = c("formula", "slope", "all"),
  model = c("pwr", "pgls"), wfun, method)

## S3 method for class 'pwr'
plot(x, ...)

Arguments

formula

Model formula to be fit

phy4d

phylobase format object to be used for fitting

which.tips

vector of integers indicating position of tips on the tree to be used, defaults to all species on the tree

bw

Bandwidth for model fit

wfun

Weighting function to be used; myust be one of brownian, martins, gaussian, or Gaus

verbose

Whether to be verbose during model fitting (default FALSE)

object

pwr object to have its coefficients extracted

...

Optional argument passed on to internal phylobase plotting functions

holdout

vector of integers indicating position of tips on the tree to be held out during model fitting

coef

coefficients to extract from the model; must be one of formula, slope, or all

model

Model type to be fit; must be either pwr, or pgls

method

for estimating weighting; should be one of subplex, optimize, L-BFGS-B,

x

output from

Value

Phylogenetically weighted model object; use coef.pwr to extract coefficients, and pwr.tp and pwr.phylobubbles for plotting.

Note

Some information about this

Author(s)

Jim Regetz, T. Jonathan Davies, Elizabeth M. Wolkovich, Brian J. McGill, and a tiny bit of cosmetic tidying from Will Pearse. Plotting code (pwr.tp and pwr.phylobubbles) only slightly adapted from code in phylobase; thank you to the authors of phylobase!

References

Davies, T. J., Regetz, J., Wolkovich, E. M., & McGill, B. J. (2019). Phylogenetically weighted regression: A method for modelling non-stationarity on evolutionary trees. Global Ecology and Biogeography, 28(2), 275-285.

See Also

caper:pgls phylobase:tp phylobase:phylobubbles

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Below are some examples in order of increasing complexity: (1) a
# simple demonstration, and (2) some cross-validation examples.

##########################################
# (1) A simple example ###################
##########################################
# Make up some data
# - Note the deep bifurcation in the slope term
if(FALSE){
tree <- read.tree(text=
    "(((A:1,B:1):1,(C:1,D:1):1):1,((E:1,F:1):1,(G:1,H:1):1):1);")
dat <- data.frame(
   x = c(0, 1, 2, 3, 0, 1, 2, 3),
   y = rnorm(8, c(1, 2, 3, 4, 2, 1.5, 1, 0.5), sd=0.25)
)

# Combine in phylobase format, and then run a scatterplot
c.data <- phylo4d(tree, dat)
plot(tipData(c.data)$x, tipData(c.data)$y, pch=rep(c(1,16), each=4),
    xlab="Predictor", ylab="Response", bty="l")
text(tipData(c.data)$x, tipData(c.data)$y, labels=rownames(tipData(c.data)),
    pos=3, cex=0.8)

# Phylogenetically weighted-regression with various weighting functions
pwr.b <- coef(pwr(y ~ x, combined.data, wfun="brownian"))
pwr.m <- coef(pwr(y ~ x, combined.data, wfun="martins"))
pwr.g <- coef(pwr(y ~ x, combined.data, wfun="gaussian"))
pwr.G <- coef(pwr(y ~ x, combined.data, wfun="Gauss"))

# Run a PGLS
pgls <- gls(y ~ x, data=dat, correlation=corBrownian(phy=tree))

# Contrast the PWR and PGLS estimates
pwr.treePlot(addData(c.data, data.frame(gest=coef(pgls)[2], glb=confint(pgls)[2,1],
   gub=confint(pgls)[2,2], pwr.m))[,c("est", "lb", "ub", "gest", "glb",
   "gub")], show.tip.label=TRUE, lower=-1., upper=1.5, pex=2, aex=3.5)
}

willpearse/pez documentation built on June 18, 2019, 9:33 p.m.