Last active
July 28, 2017 22:55
-
-
Save yonghanjung/92b5d772539aaef4516f97bc42af15a8 to your computer and use it in GitHub Desktop.
Example: pcalg
This file contains hidden or 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(pcalg) | |
df <- read.csv("Data/reduce_final_R.csv") # Load CSV file as dataframe format. | |
# re-encode into matrix format. | |
matrix_df = data.matrix(df[,c(2:20)]) | |
# PC Algorithm | |
## Parameters | |
SuffStat = list(C=cor(matrix_df),n=nrow(matrix_df)) | |
## Fitting | |
result.pc = pc(suffStat = SuffStat, indepTest = gaussCItest, p=ncol(matrix_df),alpha=0.01 ) | |
## plot | |
plot(result.pc) | |
# GES Algorithm | |
dev.off() # clear the last plot | |
## Compute score | |
colnames(matrix_df) = c(1:ncol(matrix_df)) # If colume names are too long, then the node in the plot become empty. | |
score.ges = new("GaussL0penObsScore", matrix_df) | |
## Fitting | |
result.ges = ges(score.ges) | |
## Plot | |
plot(result.ges$essgraph) | |
# RFCI algorithm (RFCI is a fast version of FCI algorithm) | |
dev.off() # clear the last plot | |
## Compute score | |
result.rfci = rfci(SuffStat,indepTest = gaussCItest, p = ncol(matrix_df), alpha=0.01 ) | |
## plot | |
plot(result.rfci) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment