Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading