Search code examples
rglmconfidence-interval

Does this code gives me confidence intervals? 95%


I am running logistic regression and want to be sure that I am getting 95% conficence intervals. Code:

# Dissable scientific notation. 
# From: stackoverflow.com/questions/25946047
options(scipen=999)



###############################################################################


OR_CI_round_number<-5  # How many decimal point to keep after rounding OR and CI.


dfAPI <- haven::read_dta(
  file = "https://stats.idre.ucla.edu/stat/stata/faq/eyestudy.dta") 


dfAPI$carrot<-factor(dfAPI$carrot)
dfAPI$carrot<-relevel(dfAPI$carrot, ref = "1")


glmAPI = glm(lenses ~ carrot, data= dfAPI, family=(binomial(link = "log")))
#glmAPI
#summary(glmAPI)
round(exp(cbind(RR = coef(glmAPI), confint(glmAPI))), OR_CI_round_number)
round(exp(cbind(RR = coef(glmAPI), confint(glmAPI, level = 0.95))), OR_CI_round_number)

Result:

> round(exp(cbind(RR = coef(glmAPI), confint(glmAPI, level = 0.95))), OR_CI_round_number)
Waiting for profiling to be done...
                 RR   2.5 %  97.5 %
(Intercept) 0.41176 0.28349 0.54870
carrot0     1.58601 1.09250 2.40172

> round(exp(cbind(RR = coef(glmAPI), confint(glmAPI))), OR_CI_round_number)
Waiting for profiling to be done...
                 RR   2.5 %  97.5 %
(Intercept) 0.41176 0.28349 0.54870
carrot0     1.58601 1.09250 2.40172

The reason that I am asking is because I am getting RR 2.5 % 97.5 %. As I understand they indicate upper and lower boundaries of 95% Confidence intervals. Is this correct?


Solution

  • Yes, correct, those are your boundaries and areas to the left of 2.5% and to the right of 97.5% are significance levels.