rquadratic

How to convert vector of values to concave down parabolic curve


I have a vector of values 0-100.

values <- runif(n = 1000, min = 0, max = 100)

I'd like to transform these values into a concave down parabolic curve where values at the middle (approximately 50) would have new values of the max (100) and those at the low (0) and high (100) would be 0. Plotting my original vector vs the new would essentially look like the plot below. Any suggestion for how to write this equation in R?

enter image description here


Solution

  • A little bit of algebra gives a quadratic (not a parabola) that goes through the points (0, 0), (50, 100) and (100, 0) as -((x-50)^2)/25 + 100.

    So does

    library(tidyverse)
    
    set.seed(123)
    
    tibble(
      value = runif(n = 1000, min = 0, max = 100),
      new_value = -((value - 50)^2/25) + 100
    ) %>% 
    ggplot() +
      geom_line(aes(x = value, y = new_value))
    

    enter image description here

    give you what you want?