confint() $operator is invalid for atomic vectors

Hello,

I am trying to generate the upper and lower confidence interval for the variable "znadj" in my dataset.

stat.desc only gives one value under CI and I haven't been able to figure out how to interpret that into proper CI as I know them.

I tried the confint() function which has worked before on linear model summaries but I keep getting the error

$ operator is invalid for atomic vectors

I tried converting the vector to dataframe but it didn't work. I tried detaching all packages and libraries and still get the same error

a sample of my dataset is shown below

 A tibble: 6 x 123
  status znadj time_blood_draw  fast inflst   Fer  sTfR   RBP   CRP
  <chr>  <dbl>           <dbl> <dbl> <chr>  <dbl> <dbl> <dbl> <dbl>
1 low     59.4               1     0 norm   124.   4.83  1.45  4.97
2 low     59.1               1     0 earl   169.   5.26  1.36 19.2 
3 low     50                 1     0 norm    43.1  8.47  2.01  1.19
4 low     55.8               2     0 earl   250.   5.19  0.9  13.3 
5 ok      99.4               1     0 incu   224.   5.78  2.37  5.03
6 ok      68.8               2     0 norm   200.   3.61  1.69  0.84

any suggestions?

or another simpler way that I could calculate the CI here

Hi,

The function you were trying to use is for (linear) models, not vectors. If you like a function that can do this for you, can use the MeanCI from DescTools

library("DescTools")
MeanCI(runif(50), conf.level = 0.95)

Hope this helps
PJ

1 Like

It works. Thanks a lot

You can also do it with t.test() function from base R.
Also when you share sample data please do it using a copy/paste friendly format like in the example below.

df <- data.frame(stringsAsFactors=FALSE,
                 status = c("low", "low", "low", "low", "ok", "ok"),
                 znadj = c(59.4, 59.1, 50, 55.8, 99.4, 68.8),
                 time_blood_draw = c(1, 1, 1, 2, 1, 2),
                 fast = c(0, 0, 0, 0, 0, 0),
                 inflst = c("norm", "earl", "norm", "earl", "incu", "norm"),
                 Fer = c(124, 169, 43.1, 250, 224, 200),
                 sTfR = c(4.83, 5.26, 8.47, 5.19, 5.78, 3.61),
                 RBP = c(1.45, 1.36, 2.01, 0.9, 2.37, 1.69),
                 CRP = c(4.97, 19.2, 1.19, 13.3, 5.03, 0.84)
)

t.test(df$znadj)$conf.int
#> [1] 46.80542 84.02792
#> attr(,"conf.level")
#> [1] 0.95

I am not sure how to paste the data in this format (I looked at all the reprex videos and hours later, I still couldn't figure it out). Any other suggestion would be appreciated. Thanks

That is pretty easy, let's say your dataframe name is df, you just have to run datapasta::df_paste(df) and copy/paste the result. See this blog post by Mara for more details.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.