[R] approx function wierd result

David Winsemius dwinsemius at comcast.net
Tue Apr 6 18:21:13 CEST 2010


On Apr 6, 2010, at 12:13 PM, marta rufino wrote:

> ok, not really sorted :-(does not work in other values,...and I am  
> not really sure how to come over it
>
> x=c(0.0191,0.0088,0.0150,0.0105,0.0430,0.0697,0.1999)
> y=c(58,107,152,239,362,512,724)
> x1=0.02220172
> kk=y[x==min(x)]
> approxExtrap(x[y>kk],y[y>kk],x1, method="linear")
> approx(x[y>kk],y[y>kk],x1)
> plot(x, y, typ="o")
> abline(v=x1, col=8)
> abline(h=approx(x[y>kk],y[y>kk],x1), col=6)
>
> Once again, I wanted to get the upper value, the one close to 300  
> and not the lowest or middle :-(
> Any ideia how to get that? I tried looking inside the code of  
> approx, but it is in .C

I am not finding your request to be very clear. You use the term  
extrapolation but what you are requesting is interior to the range of  
the x values, so it's not really extrapolation. Do you want an  
estimate based on a linear fit to the data?

plot(x,y)
lines(x, predict(lm(y ~ x) )
points(0.02220172 , predict(lm(y ~ x),  
newdata=data.frame(x=0.02220172)), col="red", cex=3)



>
> Thank you once again,
> All the best,
> Marta
>
>

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list