Path analysis usding d-separation
Arguments
- x
a dSep object.
- plotCoef
if
TRUE
plot the path coefficients.- plotdSep
if
TRUE
plot the d-separation paths. By default in red.- legend
if
TRUE
add a legend.- lty
a vector of 2 elements with the line type of significant and non significant paths.
- color
a vector of 2 elements with the color of the causal paths and the color of the d-separation paths.
- alpha
significance level.
- ...
parameters passed to FUN. Parameters must be named following the FUN arguments (e.g. data=data.frame()).
- FUN
a function or a the name of the function to test the conditional independences. Currently tested with
lm
,glm
,gls
,pgls
,MCMCglmm
andbrm
.- formulaArg
argument name from FUN that accepts the formula parameter.
- orderResponse
parameter passed to
condIndep
.- n
sample size of the dataset. If omited the function tries to guess from the models using
nobs
and custom functions.- cl
the number of CPU cores or a cluster object to run the models in parallel. Cluster object can be defined with
makeCluster
in packageparallel
ormakeCluster
fromsnow
package.- pathCoef
if
TRUE
calculates the path coefficient withpathCoef
. It is advised to standardize the input data (seescale
). By doing this, the standardized coefficients represents the relative strength of each causal relationship in the model.
References
Gonzalez-Voyer, Alejandro, and Achaz Von Hardenberg. 2014. "An Introduction to Phylogenetic Path Analysis." In Modern Phylogenetic Comparative Methods and Their Application in Evolutionary Biology, edited by Laszlo Zsolt Garamszegi, 29. Berlin, Heidelberg: Springer Berlin Heidelberg. http://www.mpcm-evolution.org/practice/online-practical-material-chapter-8/chapter-8-2-step-step-guide-phylogenetic-path-analysis-using-d-sep-method-rhinograds-example
Author
Joan Maspons <j.maspons@creaf.uab.cat>
Examples
## Dummy data
g1<- gRbase::dag(~a:c:d + b:d)
g2<- gRbase::dag(~a:c:d + b:d:a)
g<- list(m1=g1, m2=g2)
d<- data.frame(a=rnorm(100), b=rnorm(100), c=rnorm(100), d=rnorm(100))
## Use of different functions
m.lm<- dSep(g1, FUN="lm", n=nrow(d), data=d)
#> Error in UseMethod("dSep"): no applicable method for 'dSep' applied to an object of class "igraph"
m.glm<- dSep(g, FUN="glm", n=nrow(d), data=d)
#> Error in UseMethod("dSep"): no applicable method for 'dSep' applied to an object of class "list"
if (require("nlme"))
m.gls<- dSep(g1, FUN=gls, formulaArg="model", n=nrow(d), data=d)
#> Loading required package: nlme
#> Registered S3 method overwritten by 'nlme':
#> method from
#> nobs.lme dSep
#> Error in UseMethod("dSep"): no applicable method for 'dSep' applied to an object of class "igraph"
if (require(caper)){
data(shorebird, package="caper")
shorebird.data[,2:5]<- scale(log(shorebird.data[,2:5]))
shorebird<- comparative.data(shorebird.tree, shorebird.data, 'Species')
g3<- gRbase::dag(~Egg.Mass:M.Mass:F.Mass)
g4<- gRbase::dag(~Egg.Mass:M.Mass:Cl.size + Cl.size:F.Mass:M.Mass)
m1.pgls<- dSep(list(mPhy1=g3, mPhy2=g4), FUN=caper::pgls, n=nrow(d), cl=2, data=shorebird, lambda='ML')
rhino.dat <- read.csv("http://mpcm-evolution.org/OPM/Chapter8_OPM/download/rhino.csv")
rhino.tree <- read.tree("http://mpcm-evolution.org/OPM/Chapter8_OPM/download/rhino.tree")
com.dat<- caper::comparative.data(rhino.tree, rhino.dat, SP, vcv=TRUE, vcv.dim=3, warn.dropped=TRUE)
m<- list()
m$h1<- gRbase::dag(~LS:BM + NL:BM + DD:NL + RS:DD)
m$h2<- gRbase::dag(~LS:BM + NL:BM + DD:NL + RS:DD:LS)
m$h3<- gRbase::dag(~LS:BM + NL:BM + DD:NL + RS:NL)
m$h4<- gRbase::dag(~LS:BM + NL:BM + DD:NL + RS:BM:NL)
m$h5<- gRbase::dag(~LS:BM + NL:BM + DD:NL + RS:BM:NL:DD)
m$h6<- gRbase::dag(~LS:BM + NL:BM:RS + DD:NL + RS:BM)
m$h7<- gRbase::dag(~LS:BM + NL:BM:RS + DD:NL + RS:BM:LS)
m$h8<- gRbase::dag(~LS:BM + NL:BM:RS + DD:NL)
m$h9<- gRbase::dag(~LS:BM + NL:BM:RS + DD:NL + RS:LS)
m2.pgls<- dSep(m, FUN=pgls, cl=2, orderResponse=c("BM", "RS", "LS", "NL", "DD"), data=com.dat, lambda="ML")
}
#> Loading required package: caper
#> Loading required package: ape
#> Loading required package: MASS
#> Loading required package: mvtnorm
#> Registered S3 method overwritten by 'caper':
#> method from
#> nobs.pgls dSep
#> Error in UseMethod("dSep"): no applicable method for 'dSep' applied to an object of class "list"
if (require("brms"))
m.brmfit<- dSep(g1, FUN=brm, n=nrow(d), cl=2, pathCoef=FALSE, data=d)
#> Loading required package: brms
#> Loading required package: Rcpp
#> Loading 'brms' package (version 2.20.4). Useful instructions
#> can be found by typing help('brms'). A more detailed introduction
#> to the package is available through vignette('brms_overview').
#>
#> Attaching package: ‘brms’
#> The following object is masked from ‘package:stats’:
#>
#> ar
#> Error in UseMethod("dSep"): no applicable method for 'dSep' applied to an object of class "igraph"
if (require("MCMCglmm"))
m.MCMCglmm<- dSep(g1, FUN=MCMCglmm, formulaArg="fixed", n=nrow(d), cl=2, data=d, verbose=FALSE)
#> Loading required package: MCMCglmm
#> Loading required package: Matrix
#> Loading required package: coda
#>
#> Attaching package: ‘MCMCglmm’
#> The following object is masked from ‘package:brms’:
#>
#> me
#> Error in UseMethod("dSep"): no applicable method for 'dSep' applied to an object of class "igraph"
##
plot(m.glm)
#> Error in eval(expr, envir, enclos): object 'm.glm' not found