Hello every one
I have a problem calculating my confidence interval. I made a polr regression and wanted to look at the confidence intervals of my explanatory variables. I get the confidence intervals for all variables except for the variable "Age" where I get as an answer "NA".
Does anyone know why I am getting an "NA" and how I can solve this problem?
(By the way my variable "Age" includes 92 observations, and the age of individuals is between 20-29 years old)
I may have missed something but what is your date ? Where can we found data$Challenge ?
Could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.
You'll find some insight on how to provide data. However, what you did is ok. I was able to copy and use datapasta::tribble_paste to get a usable data for R.
> summary(data)
Individual Age gender Distance Challenge help
Min. : 1.00 Min. :20.00 Min. :0.0000 Min. : 529 Min. :1.00 Min. :0.0000
1st Qu.:23.75 1st Qu.:21.00 1st Qu.:0.0000 1st Qu.:1107 1st Qu.:1.00 1st Qu.:0.0000
Median :46.50 Median :22.00 Median :0.0000 Median :1367 Median :1.00 Median :1.0000
Mean :46.50 Mean :22.61 Mean :0.4674 Mean :2345 Mean :1.63 Mean :0.5652
3rd Qu.:69.25 3rd Qu.:24.00 3rd Qu.:1.0000 3rd Qu.:2079 3rd Qu.:2.00 3rd Qu.:1.0000
Max. :92.00 Max. :29.00 Max. :1.0000 Max. :8890 Max. :3.00 Max. :1.0000
I think the profiling is failing on confint() for the Age variable. There's a diagnostic plot for the profile that you can do, showing the parameter tau for each coefficient. It has to span a wide enough range (given a specific confidence interval requested, like 0.95 or 0.9 etc) or else the interval can't be calculated. It looks like Age doesn't meet the criterion. Radically lowering the requested CI (e.g. to 0.4) will give you a result, so I don't think it's a bug—it's just that the quantity you wan't can't be estimated for this model. The reprex below is similar to @cderv's, but I had to adjust the cleaning to get things to work so I've included the whole thing again, in addition to the plot.
url <- "https://forum.posit.co/uploads/default/original/2X/9/9429c5c23fed9dc09ef30508b8d837930062d5c7.pdf"
pdf_temp <- tempfile(fileext = ".pdf")
download.file(url, pdf_temp, mode = "wb")
## extract from pdf file
library(pdftools)
library(tidyverse)
data <- pdftools::pdf_text(pdf_temp) %>%
read_lines() %>%
str_trim() %>%
str_split_fixed("[ ]+", n = 6) %>%
as.data.frame(, stringsAsFactors = FALSE) %>%
as_tibble() %>%
set_names(nm = map(slice(., 1), as.character)) %>%
slice(-1) %>%
mutate_all(as.numeric)
## actual code ----
library(MASS)
#>
#> Attaching package: 'MASS'
#> The following object is masked from 'package:dplyr':
#>
#> select
data$CHL <- as.factor(data$Challenge)
levels(data$CHL) <- c("No affected","Moderate","Affected")
summary(data)
#> Individual Age gender Distance
#> Min. : 1.00 Min. :20.00 Min. :0.0000 Min. : 529
#> 1st Qu.:23.75 1st Qu.:21.00 1st Qu.:0.0000 1st Qu.:1107
#> Median :46.50 Median :22.00 Median :0.0000 Median :1367
#> Mean :46.50 Mean :22.61 Mean :0.4674 Mean :2345
#> 3rd Qu.:69.25 3rd Qu.:24.00 3rd Qu.:1.0000 3rd Qu.:2079
#> Max. :92.00 Max. :29.00 Max. :1.0000 Max. :8890
#> Challenge help CHL
#> Min. :1.00 Min. :0.0000 No affected:47
#> 1st Qu.:1.00 1st Qu.:0.0000 Moderate :32
#> Median :1.00 Median :1.0000 Affected :13
#> Mean :1.63 Mean :0.5652
#> 3rd Qu.:2.00 3rd Qu.:1.0000
#> Max. :3.00 Max. :1.0000
mo2 <- polr(formula = CHL ~ Age + Distance + gender + help, data,
method = c("logistic"), Hess =TRUE)
summary(mo2)
#> Call:
#> polr(formula = CHL ~ Age + Distance + gender + help, data = data,
#> Hess = TRUE, method = c("logistic"))
#>
#> Coefficients:
#> Value Std. Error t value
#> Age 0.1023205 0.0246094 4.158
#> Distance 0.0005437 0.0002367 2.297
#> gender 0.4871502 0.4608772 1.057
#> help -1.2882294 0.4567059 -2.821
#>
#> Intercepts:
#> Value Std. Error t value
#> No affected|Moderate 2.9482 0.0048 610.0403
#> Moderate|Affected 5.7471 0.5225 10.9983
#>
#> Residual Deviance: 137.6569
#> AIC: 149.6569
confint(mo2, level = 0.4)
#> Waiting for profiling to be done...
#> 30 % 70 %
#> Age 0.0415768227 0.1630394619
#> Distance 0.0004831186 0.0006068731
#> gender 0.2457709578 0.7286012025
#> help -1.5294930492 -1.0494528431
confint(mo2, level = 0.9)
#> Waiting for profiling to be done...
#> 5 % 95 %
#> Age NA NA
#> Distance 0.0003605271 0.0007520464
#> gender -0.2723704121 1.2474223473
#> help -2.0553019090 -0.5450240340
plot(profile(mo2))
If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it: