-1

I have a column containing 95% confidence intervals as shown below. I would like to calculate standard error using the formula SE = (upper limit – lower limit)/3.92 in R studio.

I would like to know how to calculate SE when the upper limit and lower limit are in the same as shown below:

enter code here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
Mahan
  • 71
  • 1
  • 6
  • Note that you are making very strong assumptions with this (i.e., the confidence limits are quantiles of a normal distribution). These assumptions can be violated easily. Confidence intervals don't even need to be symmetric around the estimate. – Roland Aug 02 '22 at 06:23
  • Yes, as @Roland commented, could you please describe a little bit background on your model and what these CI are for. We don't want future readers to blindly apply your formula. – Zheyuan Li Aug 02 '22 at 06:31

1 Answers1

1

You want to first separate lower bound and upper bound into two columns.

interval <- c("(0.023, 0.031)", "(-0.031, -0.022)")
lim <- do.call("rbind", stringr::str_extract_all(interval, "[+-]?[0-9\\.]+"))
mode(lim) <- "numeric"
lim
#       [,1]   [,2]
#[1,]  0.023  0.031
#[2,] -0.031 -0.022

Then you can use your formula:

(lim[, 2] - lim[, 1]) / 3.92
#[1] 0.002040816 0.002295918

Note for others: 3.96 = 1.96 * 2, and 1.96 is -qnorm(0.025).

Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248