Skip to content

Instantly share code, notes, and snippets.

View SachaEpskamp's full-sized avatar

Sacha Epskamp SachaEpskamp

View GitHub Profile
# Needs https://www.jcchouinard.com/wget/
pokemon_image <- function(pokemon){
sapply(pokemon,function(p){
tryres <- try({
# URL to image:
url <- sprintf("https://img.pokemondb.net/artwork/large/%s.jpg",tolower(p))
# set downlaod method:
if (grepl("apple",sessionInfo()$platform)){
library("parSim")
library("ggplot2")
library("tidyr")
library("dplyr")
res <- parSim(
nIndicator = 5,
nu_diff = c(0,0.5),
sampleSize = c(50, 100,500,1000,5000),
reps = 100,
# Load libraries:
library("dplyr")
library("psychonetrics")
# Read table:
data <- read.table("fwbmlqsgavagai.dat")
names(data) <- c('fwb1', 'fwb2', 'fwb3', 'fwb4', 'fwb5',
'mlqs1', 'mlqs2', 'mlqs3', 'mlqs4', 'mlqs5',
'gavagai')
library("bootnet")
library("qgraph")
# This sets the constraint. 1 for normal behavior, higher for more constrained layouts:
constrain <- 10
# Three similar networks:
net1 <- genGGM(10, p = 0.1, propPositive = 1, nei = 2)
net2 <- genGGM(10, p = 0.1, propPositive = 1, nei = 2)
net3 <- genGGM(10, p = 0.1, propPositive = 1, nei = 2)
# This script contains some functions to automate things:
cat("THIS FUNCTION IS OUTDATED, PLEASE SEE https://github.com/SachaEpskamp/RIVMgrowth")
# Function to automize dummy encoding:
rivm_lgc_dummy <- function(
data, # Dataset
design, # Design matrix, as in psychonetrics
type = c("non-linear","linear"), # Type of analysis to do
predictor_var, # Variable name of predictor (only one supported at the moment)
@SachaEpskamp
SachaEpskamp / global.R
Created November 17, 2020 16:27
Adaptive Ising app
library("shiny")
library("psychonetrics")
library("IsingFit")
library("IsingSampler")
library("qgraph")
# Load networks:
trueNetwork <- read.csv('http://sachaepskamp.com/files/weiadj.csv')[,-1]
trueNetwork <- as.matrix(trueNetwork)
Symptoms <- rownames(trueNetwork) <- colnames(trueNetwork)
@SachaEpskamp
SachaEpskamp / app.R
Last active November 16, 2020 16:13
library(shiny)
ui <- fluidPage(
h4("Click on plot to start drawing, click again to pause. Draw from LEFT to RIGHT"),
# sliderInput("mywidth", "width of the pencil", min=1, max=30, step=1, value=10),
plotOutput("plot", width = "800px", height = "500px",
hover=hoverOpts(id = "hover", delay = 100, delayType = "throttle", clip = TRUE, nullOutside = TRUE),
click="click"),
actionButton("reset", "RESET DRAWING"),
textInput("userid","Write your participant ID"),
downloadButton("downloadData", "Download data"))
library("lavaan")
library("psychonetrics")
library("dplyr")
# Generate data:
mod <- '
F1 =~ X1 + X2 + X3
F2 =~ X4 + X5 + X6
F3 =~ X7 + X8 + X9
G =~ F1 + F2 + F3
library("psychonetrics")
library("psychTools")
library("dplyr")
data("bfi")
# Extraversion and Neuroticism items:
data <- bfi[,11:20]
# ggm model:
mod_ggm <- ggm(data, estimator = "FIML") %>%
# FIML multilevel
# Model described in https://psyarxiv.com/8ha93/
# See also http://statmodel.com/bmuthen/articles/Article_055.pdf
# Load packages:
library("lavaan")
library("psychonetrics")
library("bootnet")
library("mvtnorm")
library("qgraph")