This script covers the following steps
A. N = 1 model - unified Structural Equation Model (uSEM)
Set up the uSEM model
Check model summary (model fit statistics)
Data visualization and interpretation of results
B. N = all Multilevel VAR Model
Set up the mlVAR model
Check model summary(model fit statistics)
Data visualization and interpretation of results
C. Selected Readings
for uSEM model: Yang, X., Ram, N., Gest, S., Lydon, D., Conroy, D. E., Pincus, A. L., & Molenaar, P. C. M. (2018). Socioemotional dynamics of emotion regulation and depressive symptoms: A person-specific network approach. Complexity, 2018, Article ID 5094179. doi: 10.1155/2018/5094179 [Open Access https://www.hindawi.com/journals/complexity/2018/5094179/]
for mlVAR model: Bringmann LF, Vissers N, Wichers M, Geschwind N, Kuppens P, Peeters F, et al. (2013) A Network Approach to Psychopathology: New Insights into Clinical Longitudinal Data. PLoS ONE 8(4): e60188. https://doi.org/10.1371/journal.pone.0060188 [Open Access https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0060188]
Loading libraries used in this script
# Check to see if necessary packages are installed, and install if not
packages <- c("psych", "pompom", "mlVAR", "bootnet", "psychonetrics", "GGMncv", "EstimateGroupNetwork", "relaimpo")
if (length(setdiff(packages, rownames(installed.packages()))) > 0) {
install.packages(setdiff(packages, rownames(installed.packages())))
}
# Load packages
library(tidyr)
library(lubridate)
Attaching package: ‘lubridate’
The following objects are masked from ‘package:base’:
date, intersect, setdiff, union
library(stringr)
library(psych) #for data description
library(plyr) #for data manipulation
library(dplyr)
Attaching package: ‘dplyr’
The following objects are masked from ‘package:plyr’:
arrange, count, desc, failwith, id, mutate, rename, summarise, summarize
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
library(ggplot2) #for data visualization
Attaching package: ‘ggplot2’
The following object is masked _by_ ‘.GlobalEnv’:
Layout
The following objects are masked from ‘package:psych’:
%+%, alpha
# library(pompom) #for uSEM
# library(mlVAR) #for mlVAR models
library(bootnet)
This is bootnet 1.5
For questions and issues, please see github.com/SachaEpskamp/bootnet.
library(psychonetrics)
This is psychonetrics 0.10! Note: this is BETA software! Please mind that the package may not be stable and report any bugs! For more information, please see psychonetrics.org, for questions and issues, please see github.com/SachaEpskamp/psychonetrics.
Attaching package: ‘psychonetrics’
The following object is masked from ‘package:psych’:
bifactor
The following object is masked from ‘package:graphics’:
identify
library(EstimateGroupNetwork)
fs_demo_columns <- c('id', 'demographic_age', 'demographic_age_factor',
'demographic_education', 'demographic_gender',
'demographic_gender_factor', 'demographic_income',
'demographic_living_with', 'demographic_region',
# 'demographic_underage_children',
'demographic_underage_children_factor', 'fsd_end',
# 'fsd_id',
# 'fsd_no',
'fsd_round',
'fsd_start', 'fsd_vnk',
# 'fsd_vr',
'fsd_weight')
df <- read.csv("../citizen_shield/data/kp_df_eng_ordinal.csv", header=TRUE, row.names = "X")
remove_na <- function(DF, n=0) {
DF[, colSums(is.na(DF)) <= n]
}
df <- remove_na(df, n=4000)
# describeBy(df, group="user_id")
# tmp <- df %>%
# group_by(user_id) %>%
# summarise_at(vars(feature_list), funs(sd(., na.rm=TRUE)))
feature_list <- colnames(df %>% select(-fs_demo_columns))
Note: Using an external vector in selections is ambiguous.
ℹ Use `all_of(fs_demo_columns)` instead of `fs_demo_columns` to silence this message.
ℹ See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
This message is displayed once per session.
head(df)
# describeBy(df, group = "user_id")
# describe(df)
example_round <- 1
data_indiv <- df[df$fsd_round == example_round, ]
# head(data_indiv)
# describe(data_indiv)
plot_df <- data_indiv %>%
select(c(id, fsd_round), all_of(feature_list[1:20])) %>%
gather(key = "variable", value = "value", -c(id, fsd_round))
#plotting intraindividual change
ggplot(data = plot_df,
aes(x = id, y=value, group= fsd_round)) +
#first variable
geom_line(aes(color = variable)) +
#plot layouts
scale_x_continuous(name="Arbitrary Time") +
scale_y_continuous(name="Raw Values") +
theme_classic() +
theme(axis.title=element_text(size=14),
axis.text=element_text(size=14),
plot.title=element_text(size=14, hjust=.5)) +
ggtitle(example_round)
Warning: Removed 20 row(s) containing missing values (geom_path).
# standardize specific data columns (not the id or time variables in first 3 columns)
data_indiv[feature_list] <- lapply(data_indiv[feature_list],
function(x) c(scale(x, center=TRUE, scale=TRUE)))
# describe(data_indiv)
plot_df <- data_indiv %>%
select(c(id, fsd_round), all_of(feature_list[1:20])) %>%
gather(key = "variable", value = "value", -c(id, fsd_round))
#plotting intraindividual change
ggplot(data = plot_df,
aes(x = id, y=value, group= fsd_round)) +
#first variable
geom_line(aes(color = variable)) +
#plot layouts
scale_x_continuous(name="Arbitrary Time") +
scale_y_continuous(name="Raw Values") +
theme_classic() +
theme(axis.title=element_text(size=14),
axis.text=element_text(size=14),
plot.title=element_text(size=14, hjust=.5)) +
ggtitle(example_round)
Warning: Removed 20 row(s) containing missing values (geom_path).
Now we see that all the variables are in standardized form.
It is useful to check that there are data in all columns. If any one of the variables is all missing (or has no variance), the model cannot be fit. Missing data on a few observations within a column is ok.
# check column missing
na_col <- 0
for (col in 1:ncol(data_indiv)) {
if (sum(is.na(data_indiv[,col])) == nrow(data_indiv)){
na_col <- na_col + 1
}
}
na_col
[1] 0
All columns are reported.
describe(df)
For the following networks, the data are kept in their original form.
## Impute the feature_list missingness
# imp.cart <- mice::mice(df[, feature_list], method="cart", printFlag = FALSE)
# df[, feature_list] <- mice::complete(imp.cart)
complete_df <- df[complete.cases(df[, c("id", "fsd_round", feature_list)]), c("id", "fsd_round", feature_list)]
There is no accounting for the hierarchical nature of the data here. Unregularized Gaussian Graphical Model (“ggmModSelect”; GGM) using the glasso algorithm and stepwise model selection. Gaussian Markov random field estimation using graphical LASSO and extended Bayesian information criterion (“EBICglasso”) to select optimal regularization parameter.
net_modSelect <- estimateNetwork(complete_df[feature_list],
default = "ggmModSelect",
stepwise = FALSE,
corMethod = "cor")
Estimating Network. Using package::function:
- qgraph::ggmModSelect for model selection
- using glasso::glasso
Running glasso to obtain starting model...
net_thresh <- estimateNetwork(complete_df[feature_list],
tuning = 0, # EBICglasso sets tuning to 0.5 by default
default = "EBICglasso",
threshold = TRUE,
corMethod = "cor")
Estimating Network. Using package::function:
- qgraph::EBICglasso for EBIC model selection
- using glasso::glasso
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
Layout <- qgraph::averageLayout(net_modSelect, net_thresh)
layout(t(1:2))
plot(net_modSelect, layout = Layout, title = "ggmModSelect", edge.labels=TRUE, posCol="#306fbe", negCol="#e58038", label.scale.equal=TRUE, label.cex=10)
plot(net_thresh, layout = Layout, title = "Thresholded EBICglasso", edge.labels=TRUE, posCol="#306fbe", negCol="#e58038", label.scale.equal=TRUE, label.cex=10)
Here the principal direction is forced - this rescales variables according to the sign of the first eigen-vector. This will lead to most correlations to be positive (positive manifold), leading to negative edges to be substantively interpretable. (not sure this is preferable in this instance as the variables are not all from the same questionnaire).
net_modSelect_rescale <- estimateNetwork(complete_df[feature_list],
default = "ggmModSelect",
stepwise = FALSE,
principalDirection = TRUE)
Estimating Network. Using package::function:
- qgraph::ggmModSelect for model selection
- using glasso::glasso
Running glasso to obtain starting model...
net_thresh_rescale <- estimateNetwork(complete_df[feature_list],
tuning = 0,
default = "EBICglasso",
threshold = TRUE,
principalDirection = TRUE)
Estimating Network. Using package::function:
- qgraph::EBICglasso for EBIC model selection
- using glasso::glasso
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
layout(t(1:2))
plot(net_modSelect_rescale, layout = Layout,
title = "ggmModSelect", edge.labels=TRUE, posCol="#306fbe", negCol="#e58038", label.scale.equal=TRUE, label.cex=10)
plot(net_thresh_rescale, layout = Layout,
title = "Thresholded EBICglasso", edge.labels=TRUE, posCol="#306fbe", negCol="#e58038", label.scale.equal=TRUE, label.cex=10)
qgraph::centralityPlot(
list(
ggmModSelect = net_modSelect_rescale,
EBICGlasso_thresh = net_thresh_rescale
), include = "ExpectedInfluence"
)
Note: z-scores are shown on x-axis rather than raw centrality indices.
boots <- bootnet(net_thresh_rescale, statistics = "ExpectedInfluence",
nBoots = 100, nCores = 2, type = "case")
Note: bootnet will store only the following statistics: ExpectedInfluence
Bootstrapping...
| | 0 % ~calculating
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+ | 1 % ~19s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+ | 2 % ~19s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++ | 3 % ~20s
|++ | 4 % ~21s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++ | 5 % ~21s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++ | 6 % ~23s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++ | 7 % ~23s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++ | 8 % ~23s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++ | 9 % ~22s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++ | 10% ~22s
|++++++ | 11% ~21s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++ | 12% ~20s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++ | 13% ~20s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++ | 14% ~19s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++ | 15% ~19s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++ | 16% ~18s
|+++++++++ | 17% ~18s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++ | 18% ~18s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++ | 19% ~18s
|++++++++++ | 20% ~18s
|+++++++++++ | 21% ~17s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++ | 22% ~17s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++ | 23% ~17s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++ | 24% ~16s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++ | 25% ~16s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++ | 26% ~16s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++ | 27% ~15s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++ | 28% ~15s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++ | 29% ~15s
|+++++++++++++++ | 30% ~14s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++ | 31% ~14s
|++++++++++++++++ | 32% ~14s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++ | 33% ~14s
|+++++++++++++++++ | 34% ~14s
|++++++++++++++++++ | 35% ~13s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++ | 36% ~13s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++ | 37% ~13s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++ | 38% ~13s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++ | 39% ~12s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++ | 40% ~12s
|+++++++++++++++++++++ | 41% ~12s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++ | 42% ~12s
|++++++++++++++++++++++ | 43% ~12s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++ | 44% ~11s
|+++++++++++++++++++++++ | 45% ~11s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++ | 46% ~11s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++ | 47% ~11s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++ | 48% ~11s
|+++++++++++++++++++++++++ | 49% ~10s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++ | 50% ~10s
|++++++++++++++++++++++++++ | 51% ~10s
|++++++++++++++++++++++++++ | 52% ~10s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++++ | 53% ~10s
|+++++++++++++++++++++++++++ | 54% ~09s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++++++ | 55% ~09s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++++++ | 56% ~09s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++++++ | 57% ~09s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++++++ | 58% ~09s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++++++++ | 59% ~08s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++++++++ | 60% ~08s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++++++++ | 61% ~08s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++++++++ | 62% ~08s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++++++++++ | 63% ~08s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++++++++++ | 64% ~07s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++++++++++ | 65% ~07s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++++++++++ | 66% ~07s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++++++++++++ | 67% ~07s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++++++++++++ | 68% ~07s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++++++++++++ | 69% ~06s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++++++++++++ | 70% ~06s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++++++++++++++ | 71% ~06s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++++++++++++++ | 72% ~06s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++++++++++++++ | 73% ~06s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++++++++++++++ | 74% ~05s
|++++++++++++++++++++++++++++++++++++++ | 75% ~05s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++++++++++++++++ | 76% ~05s
|+++++++++++++++++++++++++++++++++++++++ | 77% ~05s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++++++++++++++++ | 78% ~04s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++++++++++++++++++ | 79% ~04s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++++++++++++++++++ | 80% ~04s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++++++++++++++++++ | 81% ~04s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++++++++++++++++++ | 82% ~04s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++++++++++++++++++++ | 83% ~03s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++++++++++++++++++++ | 84% ~03s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++++++++++++++++++++ | 85% ~03s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++++++++++++++++++++ | 86% ~03s
|++++++++++++++++++++++++++++++++++++++++++++ | 87% ~03s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++++++++++++++++++++++ | 88% ~02s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++++++++++++++++++++++ | 89% ~02s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++++++++++++++++++++++ | 90% ~02s
|++++++++++++++++++++++++++++++++++++++++++++++ | 91% ~02s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++++++++++++++++++++++++ | 92% ~02s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++++++++++++++++++++++++ | 93% ~01s
|+++++++++++++++++++++++++++++++++++++++++++++++ | 94% ~01s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++++++++++++++++++++++++++ | 95% ~01s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|++++++++++++++++++++++++++++++++++++++++++++++++ | 96% ~01s
Note: Network with lowest lambda selected as best network: assumption of sparsity might be violated.
|+++++++++++++++++++++++++++++++++++++++++++++++++ | 97% ~01s
|+++++++++++++++++++++++++++++++++++++++++++++++++ | 98% ~00s
|++++++++++++++++++++++++++++++++++++++++++++++++++| 99% ~00s
|++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=20s
Computing statistics...
| | 0 % ~calculating
|+ | 1 % ~01s
|+ | 2 % ~01s
|++ | 3 % ~01s
|++ | 4 % ~01s
|+++ | 5 % ~01s
|+++ | 6 % ~01s
|++++ | 7 % ~01s
|++++ | 8 % ~01s
|+++++ | 9 % ~01s
|+++++ | 10% ~01s
|++++++ | 11% ~01s
|++++++ | 12% ~01s
|+++++++ | 13% ~01s
|+++++++ | 14% ~01s
|++++++++ | 15% ~01s
|++++++++ | 16% ~01s
|+++++++++ | 17% ~01s
|+++++++++ | 18% ~01s
|++++++++++ | 19% ~01s
|++++++++++ | 20% ~01s
|+++++++++++ | 21% ~01s
|+++++++++++ | 22% ~01s
|++++++++++++ | 23% ~01s
|++++++++++++ | 24% ~01s
|+++++++++++++ | 25% ~01s
|+++++++++++++ | 26% ~01s
|++++++++++++++ | 27% ~01s
|++++++++++++++ | 28% ~01s
|+++++++++++++++ | 29% ~01s
|+++++++++++++++ | 30% ~01s
|++++++++++++++++ | 31% ~01s
|++++++++++++++++ | 32% ~01s
|+++++++++++++++++ | 33% ~01s
|+++++++++++++++++ | 34% ~01s
|++++++++++++++++++ | 35% ~01s
|++++++++++++++++++ | 36% ~01s
|+++++++++++++++++++ | 37% ~01s
|+++++++++++++++++++ | 38% ~01s
|++++++++++++++++++++ | 39% ~01s
|++++++++++++++++++++ | 40% ~01s
|+++++++++++++++++++++ | 41% ~01s
|+++++++++++++++++++++ | 42% ~01s
|++++++++++++++++++++++ | 43% ~01s
|++++++++++++++++++++++ | 44% ~01s
|+++++++++++++++++++++++ | 45% ~01s
|+++++++++++++++++++++++ | 46% ~01s
|++++++++++++++++++++++++ | 47% ~01s
|++++++++++++++++++++++++ | 48% ~01s
|+++++++++++++++++++++++++ | 49% ~01s
|+++++++++++++++++++++++++ | 50% ~01s
|++++++++++++++++++++++++++ | 51% ~01s
|++++++++++++++++++++++++++ | 52% ~01s
|+++++++++++++++++++++++++++ | 53% ~01s
|+++++++++++++++++++++++++++ | 54% ~01s
|++++++++++++++++++++++++++++ | 55% ~01s
|++++++++++++++++++++++++++++ | 56% ~01s
|+++++++++++++++++++++++++++++ | 57% ~01s
|+++++++++++++++++++++++++++++ | 58% ~01s
|++++++++++++++++++++++++++++++ | 59% ~00s
|++++++++++++++++++++++++++++++ | 60% ~00s
|+++++++++++++++++++++++++++++++ | 61% ~00s
|+++++++++++++++++++++++++++++++ | 62% ~00s
|++++++++++++++++++++++++++++++++ | 63% ~00s
|++++++++++++++++++++++++++++++++ | 64% ~00s
|+++++++++++++++++++++++++++++++++ | 65% ~00s
|+++++++++++++++++++++++++++++++++ | 66% ~00s
|++++++++++++++++++++++++++++++++++ | 67% ~00s
|++++++++++++++++++++++++++++++++++ | 68% ~00s
|+++++++++++++++++++++++++++++++++++ | 69% ~00s
|+++++++++++++++++++++++++++++++++++ | 70% ~00s
|++++++++++++++++++++++++++++++++++++ | 71% ~00s
|++++++++++++++++++++++++++++++++++++ | 72% ~00s
|+++++++++++++++++++++++++++++++++++++ | 73% ~00s
|+++++++++++++++++++++++++++++++++++++ | 74% ~00s
|++++++++++++++++++++++++++++++++++++++ | 75% ~00s
|++++++++++++++++++++++++++++++++++++++ | 76% ~00s
|+++++++++++++++++++++++++++++++++++++++ | 77% ~00s
|+++++++++++++++++++++++++++++++++++++++ | 78% ~00s
|++++++++++++++++++++++++++++++++++++++++ | 79% ~00s
|++++++++++++++++++++++++++++++++++++++++ | 80% ~00s
|+++++++++++++++++++++++++++++++++++++++++ | 81% ~00s
|+++++++++++++++++++++++++++++++++++++++++ | 82% ~00s
|++++++++++++++++++++++++++++++++++++++++++ | 83% ~00s
|++++++++++++++++++++++++++++++++++++++++++ | 84% ~00s
|+++++++++++++++++++++++++++++++++++++++++++ | 85% ~00s
|+++++++++++++++++++++++++++++++++++++++++++ | 86% ~00s
|++++++++++++++++++++++++++++++++++++++++++++ | 87% ~00s
|++++++++++++++++++++++++++++++++++++++++++++ | 88% ~00s
|+++++++++++++++++++++++++++++++++++++++++++++ | 89% ~00s
|+++++++++++++++++++++++++++++++++++++++++++++ | 90% ~00s
|++++++++++++++++++++++++++++++++++++++++++++++ | 91% ~00s
|++++++++++++++++++++++++++++++++++++++++++++++ | 92% ~00s
|+++++++++++++++++++++++++++++++++++++++++++++++ | 93% ~00s
|+++++++++++++++++++++++++++++++++++++++++++++++ | 94% ~00s
|++++++++++++++++++++++++++++++++++++++++++++++++ | 95% ~00s
|++++++++++++++++++++++++++++++++++++++++++++++++ | 96% ~00s
|+++++++++++++++++++++++++++++++++++++++++++++++++ | 97% ~00s
|+++++++++++++++++++++++++++++++++++++++++++++++++ | 98% ~00s
|++++++++++++++++++++++++++++++++++++++++++++++++++| 99% ~00s
|++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=01s
plot(boots, statistics = "ExpectedInfluence") +
theme(legend.position = "none")
There is no accounting for the hierarchical nature of the data here
# net_relimp <- estimateNetwork(complete_df[feature_list],
# default = "relimp",
# normalize = FALSE)
# net_relimp2 <- estimateNetwork(complete_df[feature_list],
# default = "relimp",
# normalize = FALSE,
# structureDefault = "ggmModSelect",
# stepwise = FALSE # Sent to structureDefault function
# )
# Layout <- qgraph::averageLayout(net_relimp, net_relimp2)
# layout(t(1:2))
# plot(net_relimp, layout = Layout, title = "Saturated", edge.labels=TRUE, posCol="#306fbe", negCol="#e58038")
# plot(net_relimp2, layout = Layout, title = "Non-saturated", edge.labels=TRUE, posCol="#306fbe", negCol="#e58038")
This approach is not really valid as it uses all time points as if they are from the same person which is not the case here
# Estimate model:
gvar <- estimateNetwork(
complete_df, default = "graphicalVAR", vars = feature_list,
tuning = 0, dayvar = "fsd_round", nLambda = 10
)
Loading required namespace: graphicalVAR
Estimating Network. Using package::function:
- graphicalVAR::graphicalVAR for model estimation
Warning: `funs()` was deprecated in dplyr 0.8.0.
Please use a list of either functions or lambdas:
# Simple named list:
list(mean = mean, median = median)
# Auto named with `tibble::lst()`:
tibble::lst(mean, median)
# Using lambdas
list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
This warning is displayed once every 8 hours.
Call `lifecycle::last_warnings()` to see where this warning was generated.
|
| | 0%
|
|= | 1%
|
|== | 2%
|
|=== | 3%
|
|===== | 4%
|
|====== | 5%
|
|======= | 6%
|
|======== | 7%
|
|========= | 8%
|
|========== | 9%
|
|============ | 10%
|
|============= | 11%
|
|============== | 12%
|
|=============== | 13%
|
|================ | 14%
|
|================= | 15%
|
|================== | 16%
|
|==================== | 17%
|
|===================== | 18%
|
|====================== | 19%
|
|======================= | 20%
|
|======================== | 21%
|
|========================= | 22%
|
|========================== | 23%
|
|============================ | 24%
|
|============================= | 25%
|
|============================== | 26%
|
|=============================== | 27%
|
|================================ | 28%
|
|================================= | 29%
|
|================================== | 30%
|
|==================================== | 31%
|
|===================================== | 32%
|
|====================================== | 33%
|
|======================================= | 34%
|
|======================================== | 35%
|
|========================================= | 36%
|
|=========================================== | 37%
|
|============================================ | 38%
|
|============================================= | 39%
|
|============================================== | 40%
|
|=============================================== | 41%
|
|================================================ | 42%
|
|================================================= | 43%
|
|=================================================== | 44%
|
|==================================================== | 45%
|
|===================================================== | 46%
|
|====================================================== | 47%
|
|======================================================= | 48%
|
|======================================================== | 49%
|
|========================================================== | 50%
|
|=========================================================== | 51%
|
|============================================================ | 52%
|
|============================================================= | 53%
|
|============================================================== | 54%
|
|=============================================================== | 55%
|
|================================================================ | 56%
|
|================================================================== | 57%
|
|=================================================================== | 58%
|
|==================================================================== | 59%
|
|===================================================================== | 60%
|
|====================================================================== | 61%
|
|======================================================================= | 62%
|
|======================================================================== | 63%
|
|========================================================================== | 64%
|
|=========================================================================== | 65%
|
|============================================================================ | 66%
|
|============================================================================= | 67%
|
|============================================================================== | 68%
|
|=============================================================================== | 69%
|
|================================================================================ | 70%
|
|================================================================================== | 71%
|
|=================================================================================== | 72%
|
|==================================================================================== | 73%
|
|===================================================================================== | 74%
|
|====================================================================================== | 75%
|
|======================================================================================= | 76%
|
|========================================================================================= | 77%
|
|========================================================================================== | 78%
|
|=========================================================================================== | 79%
|
|============================================================================================ | 80%
|
|============================================================================================= | 81%
|
|============================================================================================== | 82%
|
|=============================================================================================== | 83%
|
|================================================================================================= | 84%
|
|================================================================================================== | 85%
|
|=================================================================================================== | 86%
|
|==================================================================================================== | 87%
|
|===================================================================================================== | 88%
|
|====================================================================================================== | 89%
|
|======================================================================================================== | 90%
|
|========================================================================================================= | 91%
|
|========================================================================================================== | 92%
|
|=========================================================================================================== | 93%
|
|============================================================================================================ | 94%
|
|============================================================================================================= | 95%
|
|============================================================================================================== | 96%
|
|================================================================================================================ | 97%
|
|================================================================================================================= | 98%
|
|================================================================================================================== | 99%
|
|===================================================================================================================| 100%
Minimal tuning parameter for kappa selected.
Layout <- qgraph::averageLayout(gvar$graph$temporal,
gvar$graph$contemporaneous)
layout(t(1:2))
plot(gvar, graph = "temporal", layout = Layout,
title = "Temporal", edge.labels=TRUE, posCol="#306fbe", negCol="#e58038", label.scale.equal=TRUE, label.cex=10)
plot(gvar, graph = "contemporaneous", layout = Layout,
title = "Contemporaneous", edge.labels=TRUE, posCol="#306fbe", negCol="#e58038", label.scale.equal=TRUE, label.cex=10)
# gvar_boot <- bootnet(gvar, nBoots = 2, nCores = 2)
# plot(gvar_boot, graph = "contemporaneous", plot = "interval")
net_mgm <- estimateNetwork(complete_df[feature_list],
default = "mgm",
type="g",
level=1
# type=c("g", "g", "g", "g", "c", "c", "c", "g"),
# level=c(1, 1, 1, 1, 12, 7, 15, 1)
)
Estimating Network. Using package::function:
- mgm::mgm for network computation
- Using glmnet::glmnet
plot(net_mgm, layout = Layout,
title = "mgm", edge.labels=TRUE, posCol="#306fbe", negCol="#e58038", label.scale.equal=TRUE, label.cex=10)
par(mar=c(5,1,10,1)+7)
for (checkpoint in unique(complete_df[, "fsd_round"])) {
net_mgm <- estimateNetwork(complete_df[complete_df["fsd_round"]==checkpoint, feature_list],
default = "mgm",
type="g",
level=1)
plot(net_mgm, layout = Layout,
# title = paste("mgm network", "checkpoint =", checkpoint),
edge.labels=TRUE, posCol="#306fbe", negCol="#e58038", label.scale.equal=TRUE, label.cex=10)
title(main=paste("Mixed Graphical Model network", "checkpoint =", checkpoint), line=16.25)
}
Estimating Network. Using package::function:
- mgm::mgm for network computation
- Using glmnet::glmnet
Estimating Network. Using package::function:
- mgm::mgm for network computation
- Using glmnet::glmnet
Estimating Network. Using package::function:
- mgm::mgm for network computation
- Using glmnet::glmnet
Estimating Network. Using package::function:
- mgm::mgm for network computation
- Using glmnet::glmnet
Estimating Network. Using package::function:
- mgm::mgm for network computation
- Using glmnet::glmnet
Estimating Network. Using package::function:
- mgm::mgm for network computation
- Using glmnet::glmnet
Estimating Network. Using package::function:
- mgm::mgm for network computation
- Using glmnet::glmnet
Estimating Network. Using package::function:
- mgm::mgm for network computation
- Using glmnet::glmnet
Estimating Network. Using package::function:
- mgm::mgm for network computation
- Using glmnet::glmnet
Estimating Network. Using package::function:
- mgm::mgm for network computation
- Using glmnet::glmnet
Estimating Network. Using package::function:
- mgm::mgm for network computation
- Using glmnet::glmnet
Estimating Network. Using package::function:
- mgm::mgm for network computation
- Using glmnet::glmnet
Estimating Network. Using package::function:
- mgm::mgm for network computation
- Using glmnet::glmnet
Estimating Network. Using package::function:
- mgm::mgm for network computation
- Using glmnet::glmnet
Estimating Network. Using package::function:
- mgm::mgm for network computation
- Using glmnet::glmnet
Estimating Network. Using package::function:
- mgm::mgm for network computation
- Using glmnet::glmnet
Estimating Network. Using package::function:
- mgm::mgm for network computation
- Using glmnet::glmnet
Estimating Network. Using package::function:
- mgm::mgm for network computation
- Using glmnet::glmnet
net_par_cor <- estimateNetwork(complete_df[feature_list],
default = "pcor")
Estimating Network. Using package::function:
- qgraph::qgraph(..., graph = 'pcor') for network computation
- psych::corr.p for significance thresholding
plot(net_par_cor, layout = Layout,
title = "Partial Correlation", edge.labels=TRUE, posCol="#306fbe", negCol="#e58038", label.scale.equal=TRUE, label.cex=10)
par(mar=c(5,1,10,1)+7)
for (checkpoint in unique(complete_df[, "fsd_round"])) {
net_par_cor <- estimateNetwork(complete_df[complete_df["fsd_round"]==checkpoint, feature_list],
default = "pcor")
plot(net_par_cor, layout = Layout,
edge.labels=TRUE, posCol="#306fbe", negCol="#e58038", label.scale.equal=TRUE, label.cex=10)
title(main=paste("Partial Correlation network", "checkpoint =", checkpoint), line=16.25)
}
Estimating Network. Using package::function:
- qgraph::qgraph(..., graph = 'pcor') for network computation
- psych::corr.p for significance thresholding
Estimating Network. Using package::function:
- qgraph::qgraph(..., graph = 'pcor') for network computation
- psych::corr.p for significance thresholding
Estimating Network. Using package::function:
- qgraph::qgraph(..., graph = 'pcor') for network computation
- psych::corr.p for significance thresholding
Estimating Network. Using package::function:
- qgraph::qgraph(..., graph = 'pcor') for network computation
- psych::corr.p for significance thresholding
Estimating Network. Using package::function:
- qgraph::qgraph(..., graph = 'pcor') for network computation
- psych::corr.p for significance thresholding
Estimating Network. Using package::function:
- qgraph::qgraph(..., graph = 'pcor') for network computation
- psych::corr.p for significance thresholding
Estimating Network. Using package::function:
- qgraph::qgraph(..., graph = 'pcor') for network computation
- psych::corr.p for significance thresholding
Estimating Network. Using package::function:
- qgraph::qgraph(..., graph = 'pcor') for network computation
- psych::corr.p for significance thresholding
Estimating Network. Using package::function:
- qgraph::qgraph(..., graph = 'pcor') for network computation
- psych::corr.p for significance thresholding
Estimating Network. Using package::function:
- qgraph::qgraph(..., graph = 'pcor') for network computation
- psych::corr.p for significance thresholding
Estimating Network. Using package::function:
- qgraph::qgraph(..., graph = 'pcor') for network computation
- psych::corr.p for significance thresholding
Estimating Network. Using package::function:
- qgraph::qgraph(..., graph = 'pcor') for network computation
- psych::corr.p for significance thresholding
Estimating Network. Using package::function:
- qgraph::qgraph(..., graph = 'pcor') for network computation
- psych::corr.p for significance thresholding
Estimating Network. Using package::function:
- qgraph::qgraph(..., graph = 'pcor') for network computation
- psych::corr.p for significance thresholding
Estimating Network. Using package::function:
- qgraph::qgraph(..., graph = 'pcor') for network computation
- psych::corr.p for significance thresholding
Estimating Network. Using package::function:
- qgraph::qgraph(..., graph = 'pcor') for network computation
- psych::corr.p for significance thresholding
Estimating Network. Using package::function:
- qgraph::qgraph(..., graph = 'pcor') for network computation
- psych::corr.p for significance thresholding
Estimating Network. Using package::function:
- qgraph::qgraph(..., graph = 'pcor') for network computation
- psych::corr.p for significance thresholding
net_cor <- estimateNetwork(complete_df[feature_list],
default = "cor")
Estimating Network. Using package::function:
- psych::corr.p for significance thresholding
plot(net_cor, layout = Layout,
title = "Correlation", edge.labels=TRUE, posCol="#306fbe", negCol="#e58038", label.scale.equal=TRUE, label.cex=10)
net_GGMncv <- estimateNetwork(complete_df[feature_list],
default = "GGMncv")
Loading required namespace: GGMncv
Registered S3 method overwritten by 'GGMncv':
method from
plot.graph BDgraph
Estimating Network. Using package::function:
- GGMncv::ggmncv for model estimation
selecting lambda
|
| | 0%
|
|== | 2%
|
|===== | 4%
|
|======= | 6%
|
|========= | 8%
|
|============ | 10%
|
|============== | 12%
|
|================ | 14%
|
|================== | 16%
|
|===================== | 18%
|
|======================= | 20%
|
|========================= | 22%
|
|============================ | 24%
|
|============================== | 26%
|
|================================ | 28%
|
|================================== | 30%
|
|===================================== | 32%
|
|======================================= | 34%
|
|========================================= | 36%
|
|============================================ | 38%
|
|============================================== | 40%
|
|================================================ | 42%
|
|=================================================== | 44%
|
|===================================================== | 46%
|
|======================================================= | 48%
|
|========================================================== | 50%
|
|============================================================ | 52%
|
|============================================================== | 54%
|
|================================================================ | 56%
|
|=================================================================== | 58%
|
|===================================================================== | 60%
|
|======================================================================= | 62%
|
|========================================================================== | 64%
|
|============================================================================ | 66%
|
|============================================================================== | 68%
|
|================================================================================ | 70%
|
|=================================================================================== | 72%
|
|===================================================================================== | 74%
|
|======================================================================================= | 76%
|
|========================================================================================== | 78%
|
|============================================================================================ | 80%
|
|============================================================================================== | 82%
|
|================================================================================================= | 84%
|
|=================================================================================================== | 86%
|
|===================================================================================================== | 88%
|
|======================================================================================================== | 90%
|
|========================================================================================================== | 92%
|
|============================================================================================================ | 94%
|
|============================================================================================================== | 96%
|
|================================================================================================================= | 98%
|
|===================================================================================================================| 100%
plot(net_GGMncv, layout = Layout,
title = "GGMncv", edge.labels=TRUE, posCol="#306fbe", negCol="#e58038", label.scale.equal=TRUE, label.cex=10)