Skip to content

Commit

Permalink
fix for na.data = "listwise" when using standard cor()
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexChristensen committed Mar 16, 2024
1 parent fbd39bf commit 1c3430b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 16 deletions.
12 changes: 6 additions & 6 deletions 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.5
Date: 2024-03-14
Version: 2.0.6
Date: 2024-03-16
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 All @@ -11,15 +11,15 @@ Authors@R: c(person("Hudson", "Golino", email = "hfg9s@virginia.edu", role = c("
Maintainer: Hudson Golino <hfg9s@virginia.edu>
Description: Implements the Exploratory Graph Analysis (EGA) framework for dimensionality
and psychometric assessment. EGA estimates the number of dimensions in
psychological data using network estimation methods and community detection
psychological data using network estimation methods and community detection
algorithms. A bootstrap method is provided to assess the stability of dimensions
and items. Fit is evaluated using the Entropy Fit family of indices. Unique
and items. Fit is evaluated using the Entropy Fit family of indices. Unique
Variable Analysis evaluates the extent to which items are locally dependent (or
redundant). Network loadings provide similar information to factor loadings and
can be used to compute network scores. A bootstrap and permutation approach are
can be used to compute network scores. A bootstrap and permutation approach are
available to assess configural and metric invariance. Hierarchical structures
can be detected using Hierarchical EGA. Time series and intensive longitudinal
data can be analyzed using Dynamic EGA, supporting individual, group, and
data can be analyzed using Dynamic EGA, supporting individual, group, and
population level assessments.
Depends: R (>= 3.5.0)
License: GPL (>= 3.0)
Expand Down
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
WEBSITE: https://r-ega.net

Changes in version 2.0.6

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


Changes in version 2.0.5

o FIX: 'stroke' parameter in `hierEGA` that broke with {ggplot2} update
Expand Down
33 changes: 25 additions & 8 deletions R/auto.correlate.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
#' @export
#'
# Automatic correlations ----
# Updated 07.09.2023
# Updated 16.03.2024
auto.correlate <- function(
data, # Matrix or data frame
corr = c("kendall", "pearson", "spearman"), # allow changes to standard correlations
Expand Down Expand Up @@ -140,8 +140,11 @@ auto.correlate <- function(

# Obtain correlation matrix
correlation_matrix <- cor(
x = data, use = na.data,
method = corr
x = data, use = swiftelse(
na.data == "pairwise",
"pairwise.complete.obs",
"complete.obs"
), method = corr
)

}else{ # Proceed with determination of categorical correlations
Expand Down Expand Up @@ -191,7 +194,11 @@ auto.correlate <- function(
continuous_variables, continuous_variables # ensure proper indexing
] <- cor(
x = data[,continuous_variables],
use = na.data, method = corr
use = swiftelse(
na.data == "pairwise",
"pairwise.complete.obs",
"complete.obs"
), method = corr
)

}
Expand Down Expand Up @@ -222,8 +229,11 @@ auto.correlate <- function(

# Compute Pearson's correlations
correlation_matrix <- cor(
x = data, use = na.data,
method = corr
x = data, use = swiftelse(
na.data == "pairwise",
"pairwise.complete.obs",
"complete.obs"
), method = corr
)

}
Expand Down Expand Up @@ -357,7 +367,7 @@ auto.correlate_errors <- function(data, ordinal.categories, forcePD, verbose, ..
#' Uses two-step approximation from {polycor}'s \code{polyserial}
#'
#' @noRd
# Updated 03.07.2023
# Updated 16.03.2024
polyserial.vector <- function(
categorical_variable, continuous_variables,
na.data = c("pairwise", "listwise")
Expand Down Expand Up @@ -388,7 +398,14 @@ polyserial.vector <- function(
sqrt((categorical_cases - 1) / categorical_cases) *
sd(categorical_variable, na.rm = TRUE) *
# Correlations with scaled continuous variables
cor(categorical_variable, scale(continuous_variables), use = na.data) /
cor(
categorical_variable, scale(continuous_variables),
use = swiftelse(
na.data == "pairwise",
"pairwise.complete.obs",
"complete.obs"
)
) /
# Compute sum of thresholds
sum(dnorm(obtain_thresholds(categorical_variable)), na.rm = TRUE)
)
Expand Down
10 changes: 8 additions & 2 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ needs_usable <- function(ellipse)
#' @noRd
# Obtain data, sample size, correlation matrix ----
# Generic function to get the usual needed inputs
# Updated 04.09.2023
# Updated 16.03.2024
obtain_sample_correlations <- function(data, n, corr, na.data, verbose, ...)
{

Expand Down Expand Up @@ -1501,7 +1501,13 @@ obtain_sample_correlations <- function(data, n, corr, na.data, verbose, ...)
)

}else{
correlation_matrix <- cor(data, use = na.data, method = corr)
correlation_matrix <- cor(
data, use = swiftelse(
na.data == "pairwise",
"pairwise.complete.obs",
"complete.obs"
), method = corr
)
}

}
Expand Down

0 comments on commit 1c3430b

Please sign in to comment.