My questions is about smoothing or flattening a series of numbers. I have searched for options, but have not found any. In my sample data set:
dat <- list(-21,-18,-16,-10,-8,-4,-3,-2,-1,-0.9,-0.7,-0.5,-0.3,-0.1,0,0.2,0.4,0.6,0.8,1,2,4,6,9,13,17,20,24)
I would like to logarithmically flatten or smooth the data, possibly to something like this (numbers are rounded to one decimal place):
smooth<-list(-4.6,-4.2,-4,-3.2,-2.8,-2,-1.7,-1.4,-1,-0.9,-0.8,-0.7,-0.5,-0.3,0,0.4,0.6,0.8,0.9,1,1.4,2,2.4,3,3.6,4.1,4.5,4.9)
The above is the square root of the original; however, the signs had to be changed for the negative numbers and it is also not desirable, in my case, that the absolute values of the numbers between 1 and -1 actually increased, instead of decreased. I am able to construct the above, but it is not easy or ideal, and I am wondering if there were simpler and better procedures. Thank you.
How about something like this:
sign(dat)*log(abs(dat)+1)
plot(dat, col = "red")
points(smooth, col = "green")
points(sign(dat)*log(abs(dat)+1), col = "blue")
legend(x = 1, y = 23, legend = c("original", "smooth", "missuse"),
fill = c("red", "green", "blue"))
with log2:
data:
dat <- c(-21,-18,-16,-10,-8,-4,-3,-2,-1,-0.9,-0.7,-0.5,-0.3,-0.1,0,0.2,
0.4,0.6,0.8,1,2,4,6,9,13,17,20,24)
smooth <- c(4.6,-4.2,-4,-3.2,-2.8,-2,-1.7,-1.4,-1,-0.9,-0.8,-0.7,-0.5,-0.3,0,0.4,0.6,
0.8,0.9,1,1.4,2,2.4,3,3.6,4.1,4.5,4.9)