stephen sefick
2010-Jul-15 23:33 UTC
[R] loess line predicting number where the line crosses zero twice
These data represent stream channel cross-sectional surveys. I would
like to be able to find the measurement on the tape (measure) where
the Bank Full Depth (bkf_depths) is 0. This will happen twice because
the channel has two sides. I thought fitting a loess line to these
data and then predicting the measurment number would do it. I was
wrong. Below is my failed attempt. My naive thought is this - I
would like to run my finger along this line and when it hits zero I
would like to pick out the value of measure. This should happen twice.
Any help would be greatly appreciated!
w <- (structure(list(measure = c(0, 0.2, 0.4, 0.6, 0.8, 1, 1, 1.2,
1.4, 1.6, 1.8, 2, 2.2, 2.4, 2.6, 2.8, 3, 3.2, 3.4, 3.6, 3.8,
4, 4.2, 4.4, 4.6, 4.8, 4.8, 4.84, 5, 5.2, 5.4, 5.6, 5.68), bkf_depths = c(0,
0.44, 0.46, 0.66, 0.9, 1.1, 1.1, 1.2, 1.3, 1.33, 1.36, 1.36,
1.36, 1.38, 1.38, 1.36, 1.36, 1.38, 1.37, 1.37, 1.34, 1.32, 1.36,
1.35, 1.36, 1.4, 1.4, 1.3, 0.7, 0.57, 0.21, -0.05, -0.12)), .Names
c("measure",
"bkf_depths"), row.names = c(32L, 1L, 2L, 3L, 4L, 5L, 29L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L,
20L, 21L, 22L, 23L, 31L, 24L, 30L, 25L, 26L, 27L, 28L, 33L), class
"data.frame")
)
plot(w[,"bkf_depths"]~w[,"measure"])
lines(loess(w[,"bkf_depths"]~w[,"measure"]))
#this is what I tried and there should be two 0s one at the left side
of the graph and one at the right side
predict(loess(w[,"measure"]~w[,"bkf_depths"]), 0)
kindest regards,
--
Stephen Sefick
____________________________________
| Auburn University? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? |
| Department of Biological Sciences? ? ? ? ?? |
| 331 Funchess Hall? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
| Auburn, Alabama? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? |
| 36849? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
|___________________________________|
| sas0025 at auburn.edu? ? ? ? ? ? ? ? ? ? ? ? ? ?? |
| http://www.auburn.edu/~sas0025? ? ? ? ? ?? |
|___________________________________|
Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.? We are mammals, and have not exhausted the
annoying little problems of being mammals.
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? -K. Mullis
Peter Alspach
2010-Jul-16 02:25 UTC
[R] loess line predicting number where the line crosses zero twice
Tena koe Stephen You'll need to use loess(w[,"bkf_depths"]~w[,"measure"])) and predict with a sufficiently dense sequence of w[,'measure'] to interpolate to an 'accuracy' that meets your requirements. Actually, if I understand your data correctly, it could be that simple linear interpolation (i.e., without loess) would be sufficient (even better). HTH .... Peter Alspach> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of stephen sefick > Sent: Friday, 16 July 2010 11:33 a.m. > To: r-help at r-project.org > Subject: [R] loess line predicting number where the line crosses zero > twice > > These data represent stream channel cross-sectional surveys. I would > like to be able to find the measurement on the tape (measure) where > the Bank Full Depth (bkf_depths) is 0. This will happen twice because > the channel has two sides. I thought fitting a loess line to these > data and then predicting the measurment number would do it. I was > wrong. Below is my failed attempt. My naive thought is this - I > would like to run my finger along this line and when it hits zero I > would like to pick out the value of measure. This should happen twice. > Any help would be greatly appreciated! > > w <- (structure(list(measure = c(0, 0.2, 0.4, 0.6, 0.8, 1, 1, 1.2, > 1.4, 1.6, 1.8, 2, 2.2, 2.4, 2.6, 2.8, 3, 3.2, 3.4, 3.6, 3.8, > 4, 4.2, 4.4, 4.6, 4.8, 4.8, 4.84, 5, 5.2, 5.4, 5.6, 5.68), bkf_depths > c(0, > 0.44, 0.46, 0.66, 0.9, 1.1, 1.1, 1.2, 1.3, 1.33, 1.36, 1.36, > 1.36, 1.38, 1.38, 1.36, 1.36, 1.38, 1.37, 1.37, 1.34, 1.32, 1.36, > 1.35, 1.36, 1.4, 1.4, 1.3, 0.7, 0.57, 0.21, -0.05, -0.12)), .Names > c("measure", > "bkf_depths"), row.names = c(32L, 1L, 2L, 3L, 4L, 5L, 29L, 6L, > 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, > 20L, 21L, 22L, 23L, 31L, 24L, 30L, 25L, 26L, 27L, 28L, 33L), class > "data.frame") > ) > > plot(w[,"bkf_depths"]~w[,"measure"]) > lines(loess(w[,"bkf_depths"]~w[,"measure"])) > > #this is what I tried and there should be two 0s one at the left side > of the graph and one at the right side > predict(loess(w[,"measure"]~w[,"bkf_depths"]), 0) > > > kindest regards, > > > -- > Stephen Sefick > ____________________________________ > | Auburn University? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? | > | Department of Biological Sciences? ? ? ? ?? | > | 331 Funchess Hall? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | > | Auburn, Alabama? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? | > | 36849? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | > |___________________________________| > | sas0025 at auburn.edu? ? ? ? ? ? ? ? ? ? ? ? ? ?? | > | http://www.auburn.edu/~sas0025? ? ? ? ? ?? | > |___________________________________| > > Let's not spend our time and resources thinking about things that are > so little or so large that all they really do for us is puff us up and > make us feel like gods.? We are mammals, and have not exhausted the > annoying little problems of being mammals. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? -K. Mullis > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.