Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set confidence intervals in "emmeans"

I am have been working with the emmeans package to create an estimated marginal means for my data at .95% confidence level. Although I cannot seem to change it to .99% confidence level. Any help would be much appreciated. Usually I would use the "levels=" function but it does not seem to exist for emmeans.

library(emmeans)

emmeans(AcidLevels1, specs=~MAScore,)

Best, -Nathan

like image 582
Nathan Avatar asked Oct 16 '25 15:10

Nathan


1 Answers

emmeans provides method confint.emmGrid to recalculate confidence intervals, and (probably more importantly) also adjust for multiple hypothesis testing.

As you don't provide sample data, here is an example using the warpbreaks data.

library(emmeans)
lm <- lm(breaks ~ wool * tension, data = warpbreaks)
emm <- emmeans(lm, ~ wool | tension);

To recalculate confidence intervals at the 99% level (without correcting for multiple testing) do

confint(emm, adjust = "none", level = 0.99)
#tension = L:
# wool   emmean       SE df lower.CL upper.CL
# A    44.55556 3.646761 48 34.77420 54.33691
# B    28.22222 3.646761 48 18.44086 38.00358
#
#tension = M:
# wool   emmean       SE df lower.CL upper.CL
# A    24.00000 3.646761 48 14.21864 33.78136
# B    28.77778 3.646761 48 18.99642 38.55914
#
#tension = H:
# wool   emmean       SE df lower.CL upper.CL
# A    24.55556 3.646761 48 14.77420 34.33691
# B    18.77778 3.646761 48  8.99642 28.55914
#
#Confidence level used: 0.99

To recalculate CIs at the 99% level and correct for multiple hypothesis testing using the Bonferroni correction you can do

confint(emm, adjust = "bonferroni", level = 0.99)
#tension = L:
# wool   emmean       SE df lower.CL upper.CL
# A    44.55556 3.646761 48 33.82454 55.28657
# B    28.22222 3.646761 48 17.49120 38.95324
#
#tension = M:
# wool   emmean       SE df lower.CL upper.CL
# A    24.00000 3.646761 48 13.26898 34.73102
# B    28.77778 3.646761 48 18.04676 39.50880
#
#tension = H:
# wool   emmean       SE df lower.CL upper.CL
# A    24.55556 3.646761 48 13.82454 35.28657
# B    18.77778 3.646761 48  8.04676 29.50880
#
#Confidence level used: 0.99
#Conf-level adjustment: bonferroni method for 2 estimates
like image 172
Maurits Evers Avatar answered Oct 19 '25 04:10

Maurits Evers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!