hfgolino/EGAnet

{BGGM} usage in {EGAnet}

Closed this issue · 1 comments

For now, there is a dependency issue for {BGGM} (see #136) that prevents the direct usage of BGGM in {EGAnet}. The workaround to resolve this issue is provided below:

# Ensure {remotes} is installed
if(!"remotes" %in% row.names(installed.packages())){
  install.packages("remotes")
}

# Install {BFpack} from GitHub (with dependencies)
remotes::install_github(
  "jomulder/BFpack",
  dependencies = "Imports"
)

# Install {BGGM} from GitHub (with dependencies)
remotes::install_github(
  "donaldRwilliams/BGGM",
  dependencies = "Imports"
)

# Install latest {EGAnet}
remotes::install_github("hfgolino/EGAnet")

# Restart R/RStudio

# Load packages
library(BGGM); library(EGAnet)

# Set data
data <- wmt2[,7:24] # change

# Check for unidimensionality
unidimensional <- community.unidimensional(data)

# Proceed with multidimensional if not unidimensional
if(EGAnet:::unique_length(unidimensional) != 1){
 
  # If using *any* categorical data,
  # values must start at 1!
  
  # Estimate {BGGM}
  bggm_output <- estimate(
    Y = data, type = "binary", # change for your data: "continuous", "binary", or "ordinal"
    analytic = FALSE
    # analytic = TRUE computes equivalent to
    # Pearon's correlation (not recommended for
    # categorical data)
  )
  
  # Select {BGGM}
  bggm_select <- select(
    bggm_output, cred = 0.95 # credible interval
  )
  
  # Get network
  network <- bggm_select$pcor_adj
  
  # Set variable names
  row.names(network) <- colnames(network) <- colnames(data)

  # Estimate communities
  wc <- community.detection(
    network, algorithm = "louvain" # set algorithm
  )
  
  # Set up object as "EGA" class
  ega_output <- list(
    network = network, wc = wc
  )
  class(ega_output) <- "EGA"
  
  # Plot
  plot(ega_output)
  
}

Branch created, see #136