Skip to content

Commit

Permalink
fixed Delta se
Browse files Browse the repository at this point in the history
  • Loading branch information
ihrke committed Aug 16, 2024
1 parent 89a2ea8 commit 22bddb6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Description: What the package does (one paragraph).
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Imports:
blavaan,
cSEM,
Expand Down
16 changes: 16 additions & 0 deletions NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Notes

MATTHIAS:

- add a warning to the output under "Effect sizes" in case that the indirect effect is larger than the total effect
- that care should be taken in interpreting the effect size estimates
- add such a warning to the plot_effect() function as well

- fix website

## Improvements

- catch misspecifications by the user, for example:
Expand Down Expand Up @@ -31,6 +39,14 @@ med_results <- rmedsem(est.full.lpa.mod4, indep="Attractive",
print(med_results)
```

## Bootstrap vs. Monte-Carlo

- implement bootstrap also for CB-SEM
- implement monte carlo also for cSEM
- allow options for both methods in the same function
- also add bias-corrected bootstrap and accelerated bias-corrected bootstrap (see Preacher & Selig, 2012)


## Standard errors

- Stata uses OIM (observed information matrix) for estimating standard errors by default
Expand Down
4 changes: 2 additions & 2 deletions R/plotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ plot_effect <- function(res, description=TRUE){
descr.label <- ""
if(description){
descr.label <- sprintf("Total effect=%.3f\nThat means %.1f%% of the total effect of '%s' on '%s' is mediated by '%s'.",
es$RIT$tot_eff, 100*es$RIT$ind_eff/es$RIT$tot_eff, res$vars$indep,
res$vars$dep, res$vars$med)
es$RIT$tot_eff, 100*es$RIT$ind_eff/es$RIT$tot_eff,
res$vars$indep, res$vars$dep, res$vars$med)
}

ggplot2::ggplot(effs, ggplot2::aes(x="", y=value, fill=eff)) +
Expand Down
3 changes: 2 additions & 1 deletion R/rmedsem_csem.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ rmedsem.cSEMResults <- function(mod, indep, med, dep,
sobel_lci <- prodterm - 1.959964*sobel_se
sobel_uci <- prodterm + 1.959964*sobel_se

delta_se <- sqrt( (coef_dom^2)*var_moi + (coef_moi^2)*var_dom + (var_moi*var_dom) )
#delta_se <- sqrt( (coef_dom^2)*var_moi + (coef_moi^2)*var_dom + (var_moi*var_dom) )
delta_se <- sqrt( (coef_dom^2)*var_moi + (coef_moi^2)*var_dom + 2*coef_dom*coef_moi*corrmoidom )
delta_z <- prodterm/delta_se
delta_pv <- 2*(1-stats::pnorm(abs(delta_z)))
delta_lci <- prodterm - 1.959964*delta_se
Expand Down
4 changes: 3 additions & 1 deletion R/rmedsem_lavaan.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ rmedsem.lavaan <- function(mod, indep, med, dep, standardized=TRUE, mcreps=NULL,
# in the DELTA METHOD below, it seems like normaly theory limits
# are used there as well, that is 1.959964 is used

delta_se <- sqrt( (coef_dom^2)*var_moi + (coef_moi^2)*var_dom + (var_moi*var_dom) )
#delta_se <- sqrt( (coef_dom^2)*var_moi + (coef_moi^2)*var_dom + (var_moi*var_dom) )
delta_se <- sqrt( (coef_dom^2)*var_moi + (coef_moi^2)*var_dom + 2*coef_dom*coef_moi*corrmoidom )

delta_z <- prodterm/delta_se
delta_pv <- 2*(1-stats::pnorm(abs(delta_z)))
delta_lci <- prodterm - 1.959964*delta_se
Expand Down
2 changes: 1 addition & 1 deletion man/rmedsem.lavaan.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 22bddb6

Please sign in to comment.