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

Open
hoellers opened this issue May 12, 2020 · 1 comment
Open

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

hoellers opened this issue May 12, 2020 · 1 comment
Labels
bug

Comments

@hoellers
Copy link

@hoellers hoellers commented May 12, 2020

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 leeper commented May 18, 2020

Thank you!

@leeper leeper added the bug label May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.