martinig / Fitness-and-dispersal-MA

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

how to convert median and range #11

Closed martinig closed 11 months ago

martinig commented 1 year ago
itchyshin commented 1 year ago

Use formula 3 and 5 in this paper - you can write your own function 1471-2288-14-135.pdf

martinig commented 11 months ago

@itchyshin Can you look over these functions and let me know if they are correct?

Convert median and min/max value to mean and SD:


#function to convert median and min/max value to mean and SD

calculate_mean_sd <- function(n, med, min, max) {
  mean_val <- (2 * med + (max + min)) / 4
  sd_val <- (max - min) / 4
  return(list(mean = mean_val, sd = sd_val))
}

#calculation
n <- 32
med <- 2356
min_val <- 190
max_val <- 19913

result <- calculate_mean_sd(n, med, min_val, max_val)
cat("Mean:", result$mean, "\n")
cat("Standard Deviation:", result$sd, "\n")

#output: Mean: 6203.75 and Standard Deviation: 4930.75 

Convert median and IQR to mean and SD:

# function for getting mean and sd from median, IQR, and sample size

mean_sd_from_iqr <- function(n, med, iqr) {
  mean_val <- med
  sd_val <- iqr / (2 * qnorm(0.75))
  return(list(mean = mean_val, sd = sd_val))
}

# estimation:
n <- 78
med <- 28
iqr <- 20.5

result <- mean_sd_from_iqr(n, med, iqr)
cat("Mean:", result$mean, "\n")
cat("Standard Deviation:", result$sd, "\n")

#output Mean: 28, Standard Deviation: 15.19667 
itchyshin commented 11 months ago

can you presents what it calcuates please - also what formula are you basing this on - send me the formula and then I can check - I do not know these off the top of my head (i.e., more info required)

martinig commented 11 months ago

@itchyshin I added the output above.

I tried to use the formulas in the PDF you linked above, but I found it was taking me hours to understand. I ended up using stackoverflow. I'll try to find the original posts!