Skip to content

Commit

Permalink
update for net.loads signs
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexChristensen committed Mar 22, 2024
1 parent 1c3430b commit 34c08ac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 36 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: EGAnet
Title: Exploratory Graph Analysis – a Framework for Estimating the Number of Dimensions in Multivariate Data using Network Psychometrics
Version: 2.0.6
Date: 2024-03-16
Date: 2024-03-22
Authors@R: c(person("Hudson", "Golino", email = "hfg9s@virginia.edu", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-1601-1447")),
person("Alexander", "Christensen", email = "alexpaulchristensen@gmail.com", role = "aut", comment = c(ORCID = "0000-0002-9798-7037")),
person("Robert", "Moulder", email = "rgm4fd@virginia.edu", role = "ctb", comment = c(ORCID = "0000-0001-7504-9560")),
Expand Down
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changes in version 2.0.6

o FIX: bug when using `na.data = "listwise"` in standard `cor()` function

o FIX: update to revised network loadings signs


Changes in version 2.0.5

Expand Down
53 changes: 18 additions & 35 deletions R/net.loads.R
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ organize_input <- function(A, wc)
#' @noRd
# Obtain signs ----
# Function to obtain signs on dominant community
# Updated 11.07.2023
# Updated 22.03.2024
obtain_signs <- function(target_network)
{

Expand Down Expand Up @@ -438,6 +438,11 @@ obtain_signs <- function(target_network)

}

# Determine whether signs should be flipped
if(sum(signs) <= -1){
signs <- -signs
}

# Add signs as an attribute to the target network
attr(target_network, "signs") <- signs

Expand All @@ -448,13 +453,17 @@ obtain_signs <- function(target_network)

#' @noRd
# Experimental loadings ----
# Updated 10.03.2024
# Updated 22.03.2024
experimental_loadings <- function(
A, wc, nodes, node_names,
communities, unique_communities
)
{

# Set up reset
A <- bfi_ega$network
wc <- bfi_ega$wc

# Initialize loading matrix
loading_matrix <- matrix(
0, nrow = nodes, ncol = communities,
Expand Down Expand Up @@ -504,17 +513,16 @@ experimental_loadings <- function(
if(communities > 1){

# Get negative sign indices
negative_signs <- signs == -1
negative_signs <- which(signs == -1)

# Check for any negative signs
if(any(negative_signs)){
# Loop over negative signs
if(length(negative_signs) != 0){

# Make a copy
A_copy <- A
# Flip signs
for(negative in negative_signs){
A[negative,] <- A[,negative] <- -A[,negative]
}

# Flip them
A[negative_signs,] <- -A_copy[negative_signs,]
A[,negative_signs] <- -A_copy[,negative_signs]
}

# Populate loading matrix with cross-loadings
Expand Down Expand Up @@ -544,31 +552,6 @@ experimental_loadings <- function(
# Set signs
loading_matrix <- loading_matrix * signs

# Using signs, ensure positive orientation based on most common direction
for(community in unique_communities){

# Get community index
community_index <- wc == community

# Check for negative orientation
if(sum(signs[community_index]) <= -1){

# Reverse community signs across all communities
loading_matrix[community_index,] <- -loading_matrix[community_index,]

# Check for cross-loadings
if(communities > 1){

# Reverse cross-loading signs on target community
loading_matrix[!community_index, community] <-
-loading_matrix[!community_index, community]

}

}

}

# Add attributes
attr(loading_matrix, "community") <- list(
community_sums = community_sums,
Expand Down

0 comments on commit 34c08ac

Please sign in to comment.