Skip to content

Commit

Permalink
version 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wwcs2023 authored and cran-robot committed Apr 23, 2023
0 parents commit a7489cb
Show file tree
Hide file tree
Showing 17 changed files with 1,329 additions and 0 deletions.
23 changes: 23 additions & 0 deletions DESCRIPTION
@@ -0,0 +1,23 @@
Package: mnet
Type: Package
Title: Modeling Group Differences and Moderation Effects in Statistical
Network Models
Version: 0.1.0
Authors@R: c(
person("Jonas", "Haslbeck", email = "jonashaslbeck@protonmail.com",role = c("aut", "cre")))
Maintainer: Jonas Haslbeck <jonashaslbeck@protonmail.com>
Description: A toolbox for modeling manifest and latent group differences and moderation effects in various statistical network models.
BugReports: https://github.com/jmbh/mnet/issues
Encoding: UTF-8
LazyData: true
License: GPL-2
Imports: mlVAR, doParallel, parallel, foreach
Suggests: knitr, rmarkdown, testthat (>= 3.0.0)
VignetteBuilder: knitr
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2023-04-22 07:47:31 UTC; jonas
Author: Jonas Haslbeck [aut, cre]
Depends: R (>= 3.5.0)
Repository: CRAN
Date/Publication: 2023-04-23 15:10:02 UTC
16 changes: 16 additions & 0 deletions MD5
@@ -0,0 +1,16 @@
ddd04bab6bb576eb2c518737547fbabb *DESCRIPTION
1017e4be61f5c9707cb205e8387ec18b *NAMESPACE
740a1ee1167a1a3e59229b06e42d555f *R/Process_mlVAR.R
a6f1f6598bcb16f410e40c3555c66f6f *R/mlVAR_GC.R
e6144c585cc3bdfbe09eacebf49ef687 *R/startup_msg.R
7f6b535997c2108895480217d1567d8f *README.md
558206e44deb8fc083352a154910e434 *build/vignette.rds
364b44dafe67b8c838082045e91246e9 *data/mlVARGD_sim.RData
d70f8f6ae9980781bbb92f91ea2b1d3d *inst/doc/Vignette_mlVAR_GC.R
02fed196b3e4947d84301fbb0b67638b *inst/doc/Vignette_mlVAR_GC.Rmd
63d508f228ac9aff0598cfd31ac56347 *inst/doc/Vignette_mlVAR_GC.html
556240bcc79df509fccaf408781a6b0d *man/mlVAR_GC.Rd
c3df94e1654d9f86047c44e091fb89ee *man/mnet-internal.Rd
308984c7beb11a0d49ff38a388692f20 *tests/testthat.R
43433c45bd3a5059148ee9945b08558e *tests/testthat/test-mlVAR_GC.R
02fed196b3e4947d84301fbb0b67638b *vignettes/Vignette_mlVAR_GC.Rmd
11 changes: 11 additions & 0 deletions NAMESPACE
@@ -0,0 +1,11 @@
exportPattern("^[[:alpha:]]+")

# Suggested by RMD Check
importFrom("utils", "setTxtProgressBar", "txtProgressBar")
importFrom("mlVAR", "mlVAR")
importFrom("mlVAR", "getNet")

# For parallelization
import("foreach")
import("parallel")
import("doParallel")
72 changes: 72 additions & 0 deletions R/Process_mlVAR.R
@@ -0,0 +1,72 @@
# jonashaslbeck@protonmail; April 17, 2023

# ------------------------------------------------------------
# -------- Function to Process mlVAR Outputs -----------------
# ------------------------------------------------------------


Process_mlVAR <- function(object1,
object2,
contemporaneous = "orthogonal",
temporal = "orthogonal") {

# Number of vars:
p <- ncol(object1$results$Gamma_Omega_mu$mean)

# a) Between network (using function from mlVAR package)
# For very low number of subjects close to the boundary of identifiability
# it is possible that lme4 in mlVAR estimates zero variances for random intercepts
# which then does not allow one to estimate the between person network
# for these cases we set the differences to zero here; later, when calculating
# p-values we will just exclude those cases

if(any(is.na(object1$results$Omega_mu$pcor$mean))) {
btw_1 <- matrix(NA, p, p)
} else {
btw_1 <- mlVAR::getNet(object1, "between", nonsig="show")
}
if(any(is.na(object2$results$Omega_mu$pcor$mean))) {
btw_2 <- matrix(NA, p, p)
} else {
btw_2 <- mlVAR::getNet(object2, "between", nonsig="show")
}
btw_diff <- btw_1 - btw_2

# b.1) VAR: fixed effects
phi_fix_1 <- object1$results$Beta$mean
phi_fix_2 <- object2$results$Beta$mean
phi_fix_diff <- phi_fix_1 - phi_fix_2

# b.2) VAR: RE sds
phi_RE_sd_1 <- object1$results$Beta$SD
phi_RE_sd_2 <- object2$results$Beta$SD
phi_RE_sd_diff <- phi_RE_sd_1 - phi_RE_sd_2

# c.1) Contemp: fixed effects
Gam_fix_1 <- object1$results$Gamma_Theta$mean
Gam_fix_1 <- (Gam_fix_1 + t(Gam_fix_1)) / 2 # Apply AND-rule
Gam_fix_2 <- object2$results$Gamma_Theta$mean
Gam_fix_2 <- (Gam_fix_2 + t(Gam_fix_2)) / 2 # Apply AND-rule
Gam_fix_diff <- Gam_fix_1 - Gam_fix_2

# c.2) Contemp: RE sds
Gam_RE_sd_1 <- object1$results$Gamma_Theta$SD
Gam_RE_sd_1 <- (Gam_RE_sd_1 + t(Gam_RE_sd_1)) / 2 # Apply AND-rule
Gam_RE_sd_2 <- object2$results$Gamma_Theta$SD
Gam_RE_sd_2 <- (Gam_RE_sd_2 + t(Gam_RE_sd_2)) / 2 # Apply AND-rule
Gam_RE_sd_diff <- Gam_RE_sd_1 - Gam_RE_sd_2


outlist <- list("diff_between" = btw_diff,
"diff_phi_fix" = phi_fix_diff,
"diff_phi_RE_sd" = phi_RE_sd_diff,
"diff_gam_fix" = Gam_fix_diff,
"diff_gam_RE_sd" = Gam_RE_sd_diff)

return(outlist)

} # eoF




0 comments on commit a7489cb

Please sign in to comment.