[R] bowed linear approximations

Evans, Richard K. (GRC-H000) richard.k.evans at nasa.gov
Tue Sep 26 17:18:03 CEST 2017


[solved] -- As always, the solution is simple and I always feel foolish for not having seen it right away. 

Thank you, John, for showing that the frequency data can be "converted" to log before the linear approximations are made.. once the linear approximations are done with log data, the approximations can be plotted into the "log=x" plot and everything is spot on :-) 

Here is the updated code that does exactly what I had originally wanted:

freq <- c(2, 3, 5, 10, 50, 100, 200, 300, 500, 750, 1000, 1300, 1800, 2450, 2900, 3000, 4000, 5000, 6000, 7000, 8200, 9300, 10000, 11000, 18000, 26500, 33000, 40000); 
mag <- c(1.9893038, 1.5088071, 1.1851947,  0.9444483, 0.7680123, 0.7458169, 0.7069638, 0.6393066, 0.6261539, 0.6263381, 0.7053774, 0.6900626, 0.6953527, 0.7843036, 0.9056359, 0.8867276, 0.8937421, 0.9492288, 0.9629118, 1.1972268, 1.0010515, 0.9945838, 1.0564356, 0.8733333, 1.1666667, 1.5366667, 1.4666667, 1.3166667); 
flog <- log(freq);
plot(exp(flog),mag,type="b",log="x"); 
for(i in 1:2000){ 
xx <- runif(1,min(flog),max(flog)); 
yy <- approx(flog,mag,xout=xx, method = "linear"); 
points(exp(xx),yy$y,col=rgb(1,0,0)); 
}

Thank you!
-Rich



More information about the R-help mailing list