Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ngallagher1218 opened this issue Jan 25, 2024 Discussed in #627 · 4 comments · Fixed by #629
Closed

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

ngallagher1218 opened this issue Jan 25, 2024 Discussed in #627 · 4 comments · Fixed by #629
Labels
bug 🐜 Something isn't working

Comments

@ngallagher1218
Copy link

Discussed in #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
Copy link
Member

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

This should be fixed now on #629

image

@mattansb mattansb added the bug 🐜 Something isn't working label Jan 25, 2024
@ngallagher1218
Copy link
Author

This is great, thanks so much!

@mattansb
Copy link
Member

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 mattansb reopened this Feb 21, 2024
@mattansb
Copy link
Member

Okay just reinstalled effectsize and it works 😅🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐜 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants