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

1 - 2*alpha confidence intervals returned by mm_diffs() #37

Closed
2 of 3 tasks
hoellers opened this issue May 12, 2020 · 1 comment
Closed
2 of 3 tasks

1 - 2*alpha confidence intervals returned by mm_diffs() #37

hoellers opened this issue May 12, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@hoellers
Copy link

Please specify whether your issue is about:

  • a possible bug
  • a question about package functionality
  • a suggested code or documentation change, improvement to the code, or feature request

It seems that there is an issue with calculation of confidence intervals in mm_diffs. Instead of returning a 1 - alpha confidence interval, a 1 - 2*alpha confidence interval is currently returned.
In lines 71-72 of mm_diffs(), the confidence intervals are calculated so:

        # CIs
        mm_split[[i]][["lower"]] <- mm_split[[i]][["estimate"]] - (stats::qnorm(1-alpha) * mm_split[[i]][["std.error"]])
        mm_split[[i]][["upper"]] <- mm_split[[i]][["estimate"]] + (stats::qnorm(1-alpha) * mm_split[[i]][["std.error"]])

But the function documentation specifies that alpha is a "A numeric value indicating the significance level at which to calculate confidence intervals for the MMs (by default 0.95, meaning 95-percent CIs are returned)." The default of alpha = 0.05 gives a 90-percent confidence interval as of right now. I'm sure the solution is obvious to you; changing alpha to alpha/2 in both cases above would fix the issue. Or adding + (alpha/2) within qnorm(), which seems to be what is done in mm() and amce_diffs()

This is mainly a problem for subsequent plotting, I think.

Thank you for this package, it's awesome!

Put your code here:

## load package
library("cregg")

data("immigration")
alpha <- .05
# Differences in MMs by Gender feature
temp <- mm_diffs(immigration, 
                 ChosenImmigrant ~ LanguageSkills + Education,
                 ~ Gender, id = ~ CaseID,
                 alpha = alpha)

#confidence interval from mm_diffs()
temp[, c("lower", "upper")]

#95% confidence interval calculated "by hand"
data.frame(lower = temp$estimate - qnorm(1 - alpha/2) * temp$std.error,
           upper = temp$estimate + qnorm(1 - alpha/2) * temp$std.error)


## session info for your system
sessionInfo()
@leeper
Copy link
Owner

leeper commented May 18, 2020

Thank you!

@leeper leeper added the bug Something isn't working label May 18, 2020
@leeper leeper closed this as completed in a9d912a May 18, 2020
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

No branches or pull requests

2 participants