> # principles and practice of sem, 5th ed.
> # rex b. kline, guilford press, 2023
>
> # chapter 6, table 6.3, analysis 1
> # locate all conditional independencies and generate
> # a union basis set for the roth et al. (1989)
> # nonparametric model of illness
>
> # to avoid the problem that some R packages share the same name
> # for different functions, all functions are specified next as
>
> # package::function
>
> # which prevents masking, or the default hiding of
> # a function with a redundant name from a package used next
>
> date()
[1] "Thu Apr 13 13:59:44 2023"
>
> v <- R.Version()
> print(paste0(v$language, " version ", v$major, ".",
+ v$minor, " (", v$year, "-", v$month, "-", v$day, ")"))
[1] "R version 4.2.3 (2023-03-15)"
>
> library(dagitty)
> library(ggm)
Attaching package: ‘ggm’
The following object is masked from ‘package:dagitty’:
isAcyclic
> library(CauseAndCorrelation)
>
> # get citation information
> citation("dagitty", auto = TRUE)
To cite package ‘dagitty’ in publications use:
Textor J, van der Zander B, Ankan A (2021). _dagitty: Graphical
Analysis of Structural Causal Models_. R package version 0.3-1,
.
A BibTeX entry for LaTeX users is
@Manual{,
title = {dagitty: Graphical Analysis of Structural Causal Models},
author = {Johannes Textor and Benito {van der Zander} and Ankur Ankan},
year = {2021},
note = {R package version 0.3-1},
url = {https://CRAN.R-project.org/package=dagitty},
}
ATTENTION: This citation information has been auto-generated from the
package DESCRIPTION file and may need manual editing, see
‘help("citation")’.
> citation("ggm", auto = TRUE)
To cite package ‘ggm’ in publications use:
Marchetti GM, Drton M, Sadeghi K (2020). _ggm: Graphical Markov
Models with Mixed Graphs_. R package version 2.5,
.
A BibTeX entry for LaTeX users is
@Manual{,
title = {ggm: Graphical Markov Models with Mixed Graphs},
author = {Giovanni M. Marchetti and Mathias Drton and Kayvan Sadeghi},
year = {2020},
note = {R package version 2.5},
url = {https://CRAN.R-project.org/package=ggm},
}
ATTENTION: This citation information has been auto-generated from the
package DESCRIPTION file and may need manual editing, see
‘help("citation")’.
> citation("CauseAndCorrelation", auto = TRUE)
To cite package ‘CauseAndCorrelation’ in publications use:
Shipley B (2017). _CauseAndCorrelation: Functions for Path Analysis
and SEM_. R package version 0.1,
.
A BibTeX entry for LaTeX users is
@Manual{,
title = {CauseAndCorrelation: Functions for Path Analysis and SEM},
author = {Bill Shipley},
year = {2017},
note = {R package version 0.1},
url = {http://github.com/BillShipley/CauseAndCorrelation},
}
ATTENTION: This citation information has been auto-generated from the
package DESCRIPTION file and may need manual editing, see
‘help("citation")’.
>
> # specify model in dagitty
> # locate all conditional independencies
> # implied by the graph
>
> rothdag1 <- dagitty::dagitty("dag{
+ exercise <-> hardy;
+ exercise -> fitness; hardy -> stress;
+ fitness -> illness; stress -> illness}")
>
> dagitty::impliedConditionalIndependencies(rothdag1, type="all.pairs")
exrc _||_ illn | ftns, hrdy
exrc _||_ illn | ftns, strs
exrc _||_ illn | ftns, hrdy, strs
exrc _||_ strs | hrdy
exrc _||_ strs | ftns, hrdy
exrc _||_ strs | ftns, hrdy, illn
ftns _||_ hrdy | exrc
ftns _||_ hrdy | exrc, strs
ftns _||_ hrdy | exrc, illn, strs
ftns _||_ strs | exrc
ftns _||_ strs | hrdy
ftns _||_ strs | exrc, hrdy
hrdy _||_ illn | exrc, strs
hrdy _||_ illn | ftns, strs
hrdy _||_ illn | exrc, ftns, strs
>
> # this version of dagitty did not generate a union basis set
>
> # specify model in ggm
> # "~" means "regressed on"
> # U is an unmeasured common cause
>
> rothdag2 <- ggm::DAG(
+ fitness ~ exercise,
+ stress ~ hardy,
+ illness ~ fitness + stress,
+ exercise ~ U, hardy ~ U)
>
> # use CauseAndCorrelation to convert ggm dag
> # to a mixed acyclic graph (mag) that omits the
> # the latent variable while keeping all implied
> # conditional independencies among observed variables
> # generate union basis for the mag
>
> rothmag <- CauseAndCorrelation::DAG.to.MAG(full.DAG = rothdag2,
+ latents = c("U"))
the original DAG is:
exercise -> fitness
fitness -> illness
U -> exercise
hardy -> stress
stress -> illness
U -> hardy
latent variable(s): U
_____________________
Mixed Acyclic Graph involving only the observed variables:
exercise -> fitness
fitness -> illness
exercise <-> hardy
hardy -> stress
stress -> illness
___________________________
X->Y means X that is a cause of Y given these observed variables
although there could also be latent common causes between them as well.
X<->Y means that X and Y are not causes of each other but are correlated
via one or more marginal common latent causes.
X--Y means that X and Y are not causes of each other but are
correlated via one or more common latent effects that have been conditioned
due to biased sampling.
___________________________
___________________________
>
> CauseAndCorrelation::basiSet.mag(rothmag)
Basis Set for MAG:
I(X,Y|Z) means X is m-separated from Y given the set Z in the MAG
I( fitness , stress | exercise hardy )
I( fitness , hardy | exercise )
I( exercise , stress | hardy )
I( exercise , illness | fitness stress )
I( hardy , illness | fitness stress )
[[1]]
[1] "fitness" "stress" "exercise" "hardy"
[[2]]
[1] "fitness" "hardy" "exercise"
[[3]]
[1] "exercise" "stress" "hardy"
[[4]]
[1] "exercise" "illness" "fitness" "stress"
[[5]]
[1] "hardy" "illness" "fitness" "stress"