Skip to content

Commit

Permalink
#86
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexChristensen committed Nov 7, 2021
1 parent 0ebc5ef commit 2ca44e2
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions R/utils-EGAnet.R
Original file line number Diff line number Diff line change
Expand Up @@ -4072,7 +4072,7 @@ mode <- function(v, fin.vec)
#'
# Homogenize Membership
# For itemStability
# Updated 14.04.2021
# Updated 07.11.2021
homogenize.membership <- function (target.wc, convert.wc)
{
# Obtain whether vector or matrix is input for 'convert.wc'
Expand Down Expand Up @@ -4126,24 +4126,27 @@ homogenize.membership <- function (target.wc, convert.wc)
names(rand) <- na.omit(new.uniq)
len <- rand

for(j in new.uniq)
{
for(j in new.uniq){
# Target nodes
target <- which(new.vec==j)

# Lengths of target
len[paste(j)] <- length(target)

# Compute rand index
if(length(target) >= 3){
rand[paste(j)] <- igraph::compare(new.vec[target],target.wc[target],method="rand")
}else{
# Comparisons give error when variables are less than three
if(length(target.wc[target]) == length(unique(target.wc[target]))){
rand[paste(j)] <- ifelse(
length(unique(target.wc[target])) == 1, 1, 0
)
}else if(length(new.vec[target]) == length(unique(new.vec[target]))){
rand[paste(j)] <- ifelse(
length(unique(new.vec[target])) == 1, 1, 0
)
}else{
rand[paste(j)] <- igraph::compare(new.vec[target],target.wc[target],method="rand")
}

}

# Remove NAs
Expand Down Expand Up @@ -4187,13 +4190,16 @@ homogenize.membership <- function (target.wc, convert.wc)
len[paste(j)] <- length(target)

# Compute rand index
if(length(target) >= 3){
rand[paste(j)] <- igraph::compare(new.vec[target],target.wc[target],method="rand")
}else{
# Comparisons give error when variables are less than three
if(length(target.wc[target]) == length(unique(target.wc[target]))){
rand[paste(j)] <- ifelse(
length(unique(target.wc[target])) == 1, 1, 0
)
}else if(length(new.vec[target]) == length(unique(new.vec[target]))){
rand[paste(j)] <- ifelse(
length(unique(new.vec[target])) == 1, 1, 0
)
}else{
rand[paste(j)] <- igraph::compare(new.vec[target],target.wc[target],method="rand")
}

}
Expand Down Expand Up @@ -4268,22 +4274,25 @@ homogenize.membership <- function (target.wc, convert.wc)
names(rand) <- na.omit(new.uniq)
len <- rand

for(j in new.uniq)
{
for(j in new.uniq){
# Target nodes
target <- which(new.vec==j)

# Lengths of target
len[paste(j)] <- length(target)

# Compute rand index
if(length(target) >= 3){
rand[paste(j)] <- igraph::compare(new.vec[target],target.wc[target],method="rand")
}else{
# Comparisons give error when variables are less than three
if(length(target.wc[target]) == length(unique(target.wc[target]))){
rand[paste(j)] <- ifelse(
length(unique(target.wc[target])) == 1, 1, 0
)
}else if(length(new.vec[target]) == length(unique(new.vec[target]))){
rand[paste(j)] <- ifelse(
length(unique(new.vec[target])) == 1, 1, 0
)
}else{
rand[paste(j)] <- igraph::compare(new.vec[target],target.wc[target],method="rand")
}

}
Expand Down

0 comments on commit 2ca44e2

Please sign in to comment.