This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This function computes the equivalent graphical VAR model given a dynamical factor model. It requires graphicalVAR to be installed. | |
factorToVAR <- function(lambda, beta, psi, theta){ | |
if (missing(lambda) | missing(beta) | missing(psi) | missing(theta)){ | |
stop("'lambda', 'beta', 'psi' and 'theta' may not be missing.") | |
} | |
# Number of observed: | |
nObs <- nrow(lambda) | |
# Number of latents: | |
nLat <- ncol(lambda) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This is a Shiny web application. You can run the application by clicking | |
# the 'Run App' button above. | |
# | |
# Find out more about building applications with Shiny here: | |
# | |
# http://shiny.rstudio.com/ | |
# | |
library(shiny) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("BDgraph") | |
library("glasso") | |
# Seed to reproduce results: | |
set.seed(1) | |
# Simulate 20% sparse network and data: | |
bdres <- bdgraph.sim(20, n = 10000, prob = 0.8, b = 20, D = diag(20, 20)) | |
# Sparsify inverse: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("BDgraph") | |
library("glasso") | |
library("bootnet") # Install from github: devtools::install_github("sachaepskamp/bootnet) | |
# Seed to reproduce results: | |
set.seed(1) | |
# Simulate 20% sparse network: | |
bnres <- genGGM(20, 0.8, graph = "random") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(qgraph) | |
library(bootnet) | |
net <- genGGM(10) | |
Sigma <- cov2cor(solve(diag(10) - net)) | |
D <- diag(1, 10) # Change the value here to add or remove measurment error | |
qgraph(Sigma + D, graph = "pcor") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This is a Shiny web application. You can run the application by clicking | |
# the 'Run App' button above. | |
# | |
# Find out more about building applications with Shiny here: | |
# | |
# http://shiny.rstudio.com/ | |
# | |
library(shiny) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("bootnet") | |
library("qgraph") | |
library("dplyr") | |
library("ggplot2") | |
library("knitr") | |
nNodes <- 12 | |
neighborhood <- 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Needed packages: | |
library("qgraph") | |
library("psych") | |
library("huge") | |
data(bfi) | |
# Subset of 2000 to train model on: | |
bfiTrain <- huge.npn(bfi[1:1000,1:25]) | |
corMat_train <- cor_auto(bfiTrain, missing = "fiml", detectOrdinal = FALSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install psychonetrics: | |
# devtools::install_github("sachaepskamp/psychonetrics") | |
library("psychonetrics") | |
# Set the seed: | |
set.seed(1) | |
# Let's simulate some data, 2-factor model with 10 indicators each and residual chain graph. | |
# Generate factor loadings: | |
lambda <- matrix(0,20,2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("foreign") | |
Data <- read.spss("vHB_SESP_Datafile_for_sharing 29.8.15.sav", to.data.frame = TRUE) | |
# Relabel data: | |
names(Data) <- gsub("\\.","",names(Data)) | |
# Lavaan model: | |
mod <- ' | |
f1 =~ SexDifG1 + GenVio1 + UAtt1 + MenUnf1 + SexHorm1 + EvoPsy1 | |
f2 =~ SexDifG2 + GenVio2 + UAtt2 + MenUnf2 + SexHorm2 + EvoPsy2 |