Title: | Modeling Group Differences and Moderation Effects in Statistical Network Models |
---|---|
Description: | A toolbox for modeling manifest and latent group differences and moderation effects in various statistical network models. |
Authors: | Jonas Haslbeck [aut, cre] |
Maintainer: | Jonas Haslbeck <[email protected]> |
License: | GPL-2 |
Version: | 0.1.4 |
Built: | 2025-03-15 06:30:39 UTC |
Source: | https://github.com/jmbh/mnet |
Does inference on group differences in mlVAR models using a permutation test. The function is a wrapper around the function mlVAR()
from the mlVAR
package.
mlVAR_GC(data, vars, idvar, dayvar = NULL, beepvar = NULL, groups, test = "permutation", partest = "Welch", paired = FALSE, estimator, contemporaneous, temporal, scale, nCores = 1, nP = 500, saveModels = FALSE, saveEmpModels = FALSE, verbose = FALSE, pbar = TRUE)
mlVAR_GC(data, vars, idvar, dayvar = NULL, beepvar = NULL, groups, test = "permutation", partest = "Welch", paired = FALSE, estimator, contemporaneous, temporal, scale, nCores = 1, nP = 500, saveModels = FALSE, saveEmpModels = FALSE, verbose = FALSE, pbar = TRUE)
data |
The data.frame containing the data (rows=cases, columns=variables) including the variables to be modeled, a unique id per subject, and potentially additional variables about the measurement procedure (see |
vars |
A character vector with the column names of the variables that should be included in the mlVAR models. |
idvar |
The name of the column containing the unique subject id. |
dayvar |
Optional: The name of the column indicating assessment day. Adding this argument makes sure that the first measurement of a day is not regressed on the last measurement of the previous day. IMPORTANT: only add this if the data has multiple observations per day. See also |
beepvar |
Optional: The name of the column indicating measurement occasion per day. Adding this argument will cause non-consecutive beeps to be treated as missing! See also |
groups |
The name of the column indicating group membership. |
test |
The type of test used. Defaults to |
partest |
The type of parametric test used if |
paired |
Indicates whether samples are paired or not (independent). If |
estimator |
The estimator to be used. |
contemporaneous |
How should the contemporaneous networks be estimated? These networks are always estimated post-hoc by investigating the residuals of the temporal models. |
temporal |
How should the temporal effects be estimated? |
scale |
Argument passed to |
nCores |
Number of cores to use in computation. See also |
nP |
Number of permutations used to create the sampling distribution under the null hypothesis for the permutation test. Defaults to |
saveModels |
If true, the pair of mlVAR objects for each permutations are saved in the output. Defaults to |
saveEmpModels |
If true, the pair of mlVAR objects estimated on the two groups in the empirical data are returned in a list of two. The first entry contains the mlVAR model object for the first group. Defaults to |
verbose |
If true, the the verbose option in foreach, which is used in side |
pbar |
If true, a progress bar is shown. Defaults to |
The output consists of a list with the following entries:
Returns a list with the following entries:
EmpDiffs |
A list containing five matrices with the empirically observed differences (Group 1 - Group 2) in the between-person network, the fixed and random effects variances of the temporal network, and the fixed and random effects variances of the contemporaneous network. |
Pval |
Same structure as |
SampDist |
A list of arrays, containing the sampling distributions for between-person network, the fixed and random effects variances of the temporal network, and the fixed and random effects variances of the contemporaneous network. |
Models |
If |
Runtime |
The runtime of the function in minutes. |
Jonas Haslbeck <[email protected]>
Epskamp, S., Waldorp, L. J., Mõttus, R., & Borsboom, D. (2018). The Gaussian graphical model in cross-sectional and time-series data. Multivariate behavioral research, 53(4), 453-480.
# Use simulated example data loaded with package head(ExampleData) # Call Permutation test out <- mlVAR_GC(data = ExampleData, vars = c("V1", "V2", "V3"), idvar = "id", groups = "group", nCores = 2, # choose max cores possible on your machine nP = 2) # Should be much more in practice, see paper! # P-values for the five parameter types: out$Pval # e.g., we see that there is a small p-value for out$Pval$Phi_mean[1,2] # which is a parameter with a true group difference # (which we know since this is simulated data) # The observed group differences (i.e., the test statistics) # Can be found in: out$EmpDiffs # Specifically, the difference is: group 1 - group 2 # For example: out$EmpDiffs$Phi_mean[1,2,] # The true group difference was -0.4
# Use simulated example data loaded with package head(ExampleData) # Call Permutation test out <- mlVAR_GC(data = ExampleData, vars = c("V1", "V2", "V3"), idvar = "id", groups = "group", nCores = 2, # choose max cores possible on your machine nP = 2) # Should be much more in practice, see paper! # P-values for the five parameter types: out$Pval # e.g., we see that there is a small p-value for out$Pval$Phi_mean[1,2] # which is a parameter with a true group difference # (which we know since this is simulated data) # The observed group differences (i.e., the test statistics) # Can be found in: out$EmpDiffs # Specifically, the difference is: group 1 - group 2 # For example: out$EmpDiffs$Phi_mean[1,2,] # The true group difference was -0.4
Function to test whether parameters of two VAR(1) models are different
VAR_GC(data, vars, dayvar, beepvar, groups, test = "parametric", nP = 1000)
VAR_GC(data, vars, dayvar, beepvar, groups, test = "parametric", nP = 1000)
data |
A n x p data matrix. |
vars |
An integeger vector indicating the column numbers of the variables that should be modeled in the pair of VAR models. |
dayvar |
Integener indicating the column number of the variable specifying the day of the measurement point. This is designed for EMA studies. If not applicable, this argument can be left unspecified. |
beepvar |
Integener indicating the column number of the variable specifying the number of the measurement occasion during a specific day. The full set of measurement occasions has to be consecutive and increasing sequence of integers (e.g., 1, 2,..., 5). This is designed for EMA studies. If not applicable, this argument can be left unspecified. |
groups |
Integer indiciating the column number of the group variable. The values of the group variable have to be 1 and 2. |
test |
If |
nP |
The number of permuted datasets used if |
Call |
Returns the call of the function |
phi_diff |
A p x p matrix of differences in phi coefficients (Group 1 - Group 2) in the empirical data. The test-statistics. |
phi_pval |
A p x p matrix with pvalues corresponding to |
int_diff |
A p numeric vector of differences in intercepts (Group 1 - Group 2). |
int_pvar |
A p numeric vector of pvalues corresponding to |
Jonas Haslbeck <[email protected]>
library(mlVAR) # for simulateVAR() function # Specify Model p <- 4 A1 <- diag(p) * 0.8 A2 <- diag(p) * 0.8 A2[2,1] <- 0.7 # Simulate datasets Nt <- 500 set.seed(13) # for reproducibility data1_x <- simulateVAR(A1, means=rep(0, p), Nt = Nt, residuals=.1) data2_x <- simulateVAR(A2, means=rep(0, p), Nt = Nt, residuals=.1) # Add beep and day vars dayvar1 <- dayvar2 <- rep(1:(Nt/5), each=5) beepvar1 <- beepvar2 <- rep(1:5, Nt/5) # Add grouping var groups1 <- rep(1, Nt) groups2 <- rep(2, Nt) # Combine data1 <- data.frame(cbind(dayvar1, beepvar1, groups1, data1_x)) data2 <- data.frame(cbind(dayvar2, beepvar2, groups2, data2_x)) colnames(data1) <- colnames(data2) <- c("dayvar", "beepvar", "groups", paste0("V", 1:4)) data <- rbind(data1, data2) # Call out <- VAR_GC(data = data, vars = 4:7, dayvar = 1, beepvar = 2, groups = 3) round(out$phi_pval, 2) round(out$phi_pval[2,1], 2) # worked!
library(mlVAR) # for simulateVAR() function # Specify Model p <- 4 A1 <- diag(p) * 0.8 A2 <- diag(p) * 0.8 A2[2,1] <- 0.7 # Simulate datasets Nt <- 500 set.seed(13) # for reproducibility data1_x <- simulateVAR(A1, means=rep(0, p), Nt = Nt, residuals=.1) data2_x <- simulateVAR(A2, means=rep(0, p), Nt = Nt, residuals=.1) # Add beep and day vars dayvar1 <- dayvar2 <- rep(1:(Nt/5), each=5) beepvar1 <- beepvar2 <- rep(1:5, Nt/5) # Add grouping var groups1 <- rep(1, Nt) groups2 <- rep(2, Nt) # Combine data1 <- data.frame(cbind(dayvar1, beepvar1, groups1, data1_x)) data2 <- data.frame(cbind(dayvar2, beepvar2, groups2, data2_x)) colnames(data1) <- colnames(data2) <- c("dayvar", "beepvar", "groups", paste0("V", 1:4)) data <- rbind(data1, data2) # Call out <- VAR_GC(data = data, vars = 4:7, dayvar = 1, beepvar = 2, groups = 3) round(out$phi_pval, 2) round(out$phi_pval[2,1], 2) # worked!