How to convert vector of values to concave down parabolic curve

45 Views Asked by At

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

2

There are 2 best solutions below

3
Limey On BEST ANSWER

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?

2
AudioBubble On

Something like this?

library(tidyverse)

df <- data.frame(n=seq(1,1000))
df$v_old <- sort(runif(1000,min=0,max=100))
df$v_new <- -1/50*(df$v_old - 50) ^ 2 + 50
df %>% ggplot(aes(x=v_old,y=v_new)) + geom_line()

enter image description here