easystats / effectsize

:dragon: Compute and work with indices of effect size and standardized parameters
https://easystats.github.io/effectsize/
Other
331 stars 22 forks source link

CIs in phi() function show jitter when ci approaches 1. #628

Closed ngallagher1218 closed 4 months ago

ngallagher1218 commented 5 months ago

Discussed in https://github.com/easystats/effectsize/discussions/627

Originally posted by **ngallagher1218** January 24, 2024 Hello, I am working on a paper involving a series of chi-square tests, and have been using the phi() function to calculate and report phi and a 95% CI for phi. However, when adjusting the ci value from 0.95 to 0.983 (this is related to a correction for multiple comparisons), the resulting confidence interval shrank rather than increasing. To explore this, I looked at the upper and lower bounds returned by the phi() function for various levels of ci, and found an odd jittering effect - for some values of ci close to 1, the upper bound goes closer to the point estimate rather than further from it. The issue appears both with and without the adjustment applied. It's possible that this is somehow related to the non-centrality parameter method for establishing CIs, with which I am not extremely familiar, but it seemed odd enough that I am submitting it as a possible glitch. Reprex is below, as well as visualization of the upper and lower bounds given different CI values for this particular dataset. Thanks in advance for any guidance about this issue! Best, Nat Screenshot 2024-01-24 at 8 36 10 PM ------------------------------------------------------------------------------------------------ library(tidyverse) GB_tbl <- data.frame(Variable = c("A", "B"), Boy = c(42, 126), Girl = c(71, 127)) GB_tbl %>% column_to_rownames(var = "Variable") -> GB_tbl X <- data.frame(civalue = seq(0.001,0.999,0.001), phi = NA, LowerBound = NA, UpperBound = NA) X %>% mutate(Adjustment = FALSE) %>% bind_rows(X) %>% mutate(Adjustment = ifelse(is.na(Adjustment), TRUE, Adjustment)) -> X for(i in 1:nrow(X)){ effectsize::phi(GB_tbl, ci = X$civalue[i], adjust = X$Adjustment[i], alternative="two.sided") -> Y if(X$Adjustment[i] == TRUE) { X$phi[i] <- Y$phi_adjusted } if(X$Adjustment[i] == FALSE) { X$phi[i] <- Y$phi } X$LowerBound[i] <- Y$CI_low X$UpperBound[i] <- Y$CI_high } X %>% mutate(Adjustment = ifelse(Adjustment == TRUE, "Adjustment Applied", ifelse(Adjustment == FALSE, "Adjustment Not Applied", NA))) %>% gather(WhichValue, Value, -civalue, -Adjustment) %>% filter(civalue >= 0.5) %>% ggplot(aes(x = civalue, y = Value, group = WhichValue, color = WhichValue)) + geom_line() + facet_grid(Adjustment~.) + theme_bw()
mattansb commented 5 months ago

Thanks @ngallagher1218 - this was indeed a weird little bug, due to how we optimized for NCPs.

This should be fixed now on #629

image

ngallagher1218 commented 5 months ago

This is great, thanks so much!

mattansb commented 4 months ago

Something in the fix to this made results wonky - see changes to low bound:

Old:

effectsize::F_to_eta2(3.23, 1, 137)
#> Eta2 (partial) |       95% CI
#> -----------------------------
#> 0.02           | [0.00, 1.00]
#> 
#> - One-sided CIs: upper bound fixed at [1.00].

Created on 2024-02-21 with reprex v2.0.2

New:

effectsize::F_to_eta2(3.23, 1, 137)
#> Eta2 (partial) |       95% CI
#> -----------------------------
#> 0.02           | [0.08, 1.00]
#> 
#> - One-sided CIs: upper bound fixed at [1.00].

Created on 2024-02-21 with reprex v2.0.2

mattansb commented 4 months ago

Okay just reinstalled effectsize and it works 😅🤔