[R] bowed linear approximations

Evans, Richard K. (GRC-H000) richard.k.evans at nasa.gov
Mon Sep 25 21:28:28 CEST 2017


Hello,

Please run the following code snippet and note the resulting plot:

x <- c(10, 50)
y <- c(0.9444483, 0.7680123)
plot(x,y,type="b",log="x")
for(i in 1:50){
 xx <- exp(runif(1,log(min(x)),log(max(x)) ))
yy <- approx(x,y,xout=xx, method = "linear")
points(xx,yy$y)
}

notice the "log=x" plot parameter and the resulting "bow" in the linear approximation.

This makes sense when I realized that the plot command is first making the plot and then drawing straight lines between points on a log plot AFTER the plot is generated and that that's why the line is straight. I get that.
.. and it also makes sense that the bowed points are a result of the linear approximations being made BEFORE plotted in a logarithmic plot. I get that..

My goal is to make approximations that lie on the line produced on the plot as shown, so I realize that what I want to do is NOT linear approximations, but maybe "log" approximations?
However, the approximation methods are only "linear" and "constant" .. there isn't a "log" method to approximate with.

So can anyone tell me how to fix the code such that he approximated points DO lie on the line as plotted with the "log=x" plot parameter?
Oh, and they have to be uniformly distributed along the Log=x axis.. I think that's the tricky part.

Any help and/or insight would be greatly appreciated.

Thank you!
-Rich


	[[alternative HTML version deleted]]



More information about the R-help mailing list