Created
October 16, 2014 16:36
-
-
Save joaovissoci/7baf9c5b713fdb62eb82 to your computer and use it in GitHub Desktop.
ising_model_template
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("IsingFit") | |
library("qgraph") | |
library("Matrix") | |
library("glmnet") | |
library("IsingSampler") | |
lapply(c("IsingFit","qgraph","Matrix","glmnet","IsingSampler","psych"), | |
library, character.only=T) | |
data <- repmis::source_DropboxData("marcela_network.csv", | |
"62e4d6emy0aa25i", | |
sep = ",", | |
header = TRUE) | |
summary(data) | |
cor_data<-polychoric(data) | |
dataMatrix <- t(as.matrix(data)) %*% as.matrix(data) | |
summary(data) | |
color<-c("red",rep(c("steelblue"),33),rep(c("gold"),11),rep(c("lightgreen"),11)) | |
freq<-c() | |
qgraph(dataMatrix, layout="spring",vsize = 5,esize=3, cut = 8, | |
minimum = 0,color=color) | |
data_risk <- repmis::source_DropboxData("marcela_data.csv", | |
"wi038s1n4ahpgxw", | |
sep = ",", | |
header = TRUE) | |
risk<-data.frame(data,data_risk$CLASS.ESCORE) | |
par(nrow(3:1)) | |
risk_verde<-subset(risk,risk$data_risk.CLASS.ESCORE=='VERDE') | |
risk_verde<-remove.vars(risk_verde,c("data_risk.CLASS.ESCORE")) | |
dataMatrix <- t(as.matrix(risk_verde)) %*% as.matrix(risk_verde) | |
qgraph(dataMatrix, layout="spring",vsize = 5,esize=3, cut = 5, | |
minimum = 5,color=color) | |
risk_amarelo<-subset(risk,risk$data_risk.CLASS.ESCORE=='AMARELO') | |
risk_amarelo<-remove.vars(risk_amarelo,c("data_risk.CLASS.ESCORE")) | |
dataMatrix <- t(as.matrix(risk_amarelo)) %*% as.matrix(risk_amarelo) | |
qgraph(dataMatrix, layout="spring",vsize = 5,esize=3, cut = 5, | |
minimum = 5,color=color) | |
risk_amarelo<-subset(risk,risk$data_risk.CLASS.ESCORE=='VERMELHO') | |
risk_amarelo<-remove.vars(risk_amarelo,c("data_risk.CLASS.ESCORE")) | |
dataMatrix <- t(as.matrix(risk_amarelo)) %*% as.matrix(risk_amarelo) | |
qgraph(dataMatrix, layout="spring",vsize = 5,esize=3, cut = 5, | |
minimum = 5,color=color) | |
library(pcalg) | |
names<-rownames(dataMatrix) | |
n = nrow(dataMatrix) | |
p = ncol(dataMatrix) | |
## define independence test (partial correlations) | |
indepTest <- disCItest | |
## define sufficient statistics | |
suffStat <- list(dm = dataMatrix, adaptDF=FALSE) | |
## estimate CPDAG | |
alpha <- 0.01 | |
pc.fit <- pc(suffStat, indepTest, alpha,names,verbose=TRUE) | |
qgraph(pc.fit) | |
plot(pc.fit, main = "",labels=names) | |
IsingFit(data,plot=TRUE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment