martinig / Fitness-and-dispersal-MA

https://martinig.github.io/Fitness-and-dispersal-MA/
0 stars 0 forks source link

how to convert 85% CI #15

Closed martinig closed 6 months ago

martinig commented 7 months ago

conversion CI to SD

ci_to_sd <-function(upper, lower, n){

upper: upper limit of CI

# lower: lower limit of CI
# n: sample size
# return: SD
# SD = (upper - lower) / (2 * qt(0.975, n-1))
return((upper - lower) / (2 * qt(0.975, n-1)))

}

testing code for ci_to_sd

ci_to_sd(upper = 2.91, lower = 1.02, n = 4) ci_to_sd(upper = 0.961315, lower = 0.7528937, n = 8)

itchyshin commented 7 months ago

@martinig - can you cut and paste the formula for CI here I gave you before - if not I can write it again

martinig commented 7 months ago

@itchyshin Added above! :)

itchyshin commented 7 months ago

As said you just need to use 92.5%

so

ci_to_sd2 <-function(upper, lower, n){
# upper: upper limit of CI
# lower: lower limit of CI
# n: sample size
# return: SD
# SD = (upper - lower) / (2 * qt(0.925, n-1))
return((upper - lower) / (2 * qt(0.925, n-1)))
}
martinig commented 7 months ago

@itchyshin Two other questions:

  1. In all cases, we have the overall n (e.g., n=104, which corresponds to group 1 n = 67, group 2 n = 37). We then typically extract the SD using ci_to_sd(upper = 2.91, lower = 1.02, n = 67). In the 85% CI case, the error is around the estimate, so would I just use the overall n instead (104)?

  2. Am I remembering correctly that I am supposed to convert all the estimate +/- CIs to estimate +/- SE? (Not SD?)

itchyshin commented 7 months ago

OK - it seems like you have an estimate and 85% CI. Then you n = 104 and then you get SE (which is SD - SD of estimate) and you can use this SE to use for the function which takes an estimate and SE

martinig commented 7 months ago

@itchyshin I am not sure I follow your response.

To confirm - yes, I use overall n and yes, I convert all errors to SE for linear estimates?

itchyshin commented 7 months ago

Good- then you can use this method - estimate_method1: linear regression with estimate and SE

martinig commented 6 months ago

Function above was wrong. This is the correct function.

# conversion 85% CI to SE
# I need a function to convert 85% CI to SE

ci85_to_se <-function(upper, lower, n){
    # upper: upper limit of CI
    # lower: lower limit of CI
    # n: sample size
    # return: SE
    se_value<-(upper - lower) / (2 * qt(0.925, n-1))
    return(se_value)
}

upper_ci <- 0.83  # Replace with your upper CI value
lower_ci <- 0.28  # Replace with your lower CI value
sample_size <- 104  # Replace with your sample size

se_result <- ci85_to_se(upper_ci, lower_ci, sample_size)
se_result