Skip to content

Commit

Permalink
update paper
Browse files Browse the repository at this point in the history
  • Loading branch information
rempsyc committed May 20, 2023
1 parent 385bf0c commit f796437
Show file tree
Hide file tree
Showing 9 changed files with 493 additions and 235 deletions.
43 changes: 25 additions & 18 deletions paper/paper.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ code-efficient syntax. Second, it facilitates the analysis-to-publication
workflow by providing publication-ready tables and figures (following the
style of the American Psychological Association, APA).

## Alternative Syntax
## Usage

There is a single function at the center of the proposed alternative syntax,
`write_lavaan()`. The idea behind `write_lavaan()` is to define individual
Expand Down Expand Up @@ -112,7 +112,7 @@ need to define the latent variables again, only the new components. With the
`lavaanExtra` syntax, when defining our lists of components, we can think of
the `=` sign as "predicted by", a bit like `~` for regression. There is
an exception to this for the `indirect` object, which also allows specifying
our variables directly instead. When such is the case, `write_lvaan()` will
our variables directly instead. When such is the case, `write_lavaan()` will
define all indirect paths automatically.

```{r}
Expand All @@ -125,8 +125,12 @@ regression <- list(speed = IV, textual = IV)
covariance <- list(speed = "textual", ageyr = "grade", x4 = c("x5", "x6"))
indirect <- list(IV = IV, M = M, DV = DV)
model.sem <- write_lavaan(mediation, regression, covariance,
indirect, latent, label = TRUE)
model.sem <- write_lavaan(mediation = mediation,
regression = regression,
covariance = covariance,
indirect = indirect,
latent = latent,
label = TRUE)
cat(model.sem)
```

Expand All @@ -145,7 +149,8 @@ library(lavaan)
fit.cfa <- cfa(model.cfa, data = HolzingerSwineford1939)
fit.sem <- sem(model.sem, data = HolzingerSwineford1939)
fit_table <- nice_fit(dplyr::lst(fit.cfa, fit.sem), nice_table = TRUE)
list.mods <- list(fit.cfa = fit.cfa, fit.sem = fit.sem)
fit_table <- nice_fit(list.mods, nice_table = TRUE)
```

```{r, eval=F}
Expand Down Expand Up @@ -191,15 +196,17 @@ compare the default `lavaanPlot()` and `nice_lavaanPlot()` outputs
side-by-side for demonstration purposes.

```{r nice_lavaanPlot}
lavaanPlot::lavaanPlot(fit.sem)
# lavaanPlot::lavaanPlot(fit.sem)
# This is temporarily commented out because it is generating a bug on my home
# computer. I will have to reknit the document from my work laptop.
nice_lavaanPlot(fit.sem)
```

As these figures demonstrate, `nice_lavaanPlot()` has several elements
frequently requested by researchers (especially in psychology): (a)
an horizontal, rather than vertical, layout; (b) the coefficients
appear per default (but only significant ones); (c) significance
a horizontal, rather than vertical, layout; (b) the coefficients
appear by default (but only significant ones); (c) significance
stars; and (d) the use of a sans serif font (as required by APA
style for figures).

Expand All @@ -208,7 +215,7 @@ example for the use of curved lines, which many researchers dislike.
Nonetheless, it will still yield excellent and satisfying results for a
quick and easy check.

In turn, the best option for publication is `nice_tidySEM`. Let's first
The best option for publication then is `nice_tidySEM`. Let's first
look at the default output of the base `tidySEM::graph_sem()` for
reference.

Expand Down Expand Up @@ -238,7 +245,7 @@ For the time being, `nice_tidySEM` only supports this three-level
automatic layout, but designs with more levels are in the works. In the
meantime, when the model is more complex (or that we want to include items),
it is necessary to specify the layout manually using a matrix or data frame,
which allows a fine-grained control over the generated figure.
which allows fine-grained control over the generated figure.

```{r}
mylayout <- data.frame(
Expand Down Expand Up @@ -268,8 +275,7 @@ x$edges[from == "ageyr" & to == "textual", "curvature"] <- -40
plot(x)
```

In any case, the resulting figure can be saved using `ggplot2::ggsave()`
[@ggplot2Package].
The resulting figure can be saved using `ggplot2::ggsave()` [@ggplot2Package]:

```{r, eval=FALSE}
ggplot2::ggsave("my_semPlot.pdf", width = 8, height = 6)
Expand All @@ -279,7 +285,7 @@ Other differences between {tidySEM} and `nice_tidySEM()` are that: (a) the
latter displays standardized coefficients by default (but unstandardized
coefficients can be specified with `est_std = FALSE`), (b) if using
standardized coefficients, the leading zero is omitted (as per APA
requirements); (c) does not plot the variances per default, (d) uses
requirements); (c) does not plot the variances by default, (d) uses
full double-headed arrows instead of dashed lines with no arrows for
covariances, (e) has further arguments for easy customization (e.g.,
`reduce_items`), and (f) allows defining an automatic layout in specific
Expand All @@ -306,10 +312,11 @@ https://github.com/rempsyc/lavaanExtra/issues/.

# Acknowledgements

I would like to thank Hugues Leduc, Jany St-Cyr, Andreea Gavrila, Charles-Étienne
Lavoie, and Björn Büdenbender for statistical or technical advice that helped
inform some functions of this package and/or useful feedback on this manuscript.
I would also like to acknowledge funding from the Social Sciences and Humanities
Research Council of Canada.
I would like to thank Hugues Leduc, Jany St-Cyr, Andreea Gavrila, Patrick
Coulombe, Jay Olson, Charles-Étienne Lavoie, and Björn Büdenbender for
statistical or technical advice that helped inform some functions of this
package and/or useful feedback on this manuscript. I would also like to
acknowledge funding from the Social Sciences and Humanities Research Council of
Canada.

# References
Loading

0 comments on commit f796437

Please sign in to comment.