Hi David, thanks for the reply. This is not a homework problem, although it may sound like one :) I was trying to provide a reproducible example of what I am trying to do.
The problem is something I am trying to work on for my PhD program. I've been using the nls() function to derive a self-starting logistic function to calculate snowmelt duration in Alaskan watersheds. Here's a snippet of the nls function calculation **not reproducible** #year 2000 print("year 2000") Asym.2000 <- mean(na.omit(dat.cl.2000$dat)[1:10]) na.dat.2000 <- which(!is.na(dat.cl.2000$dat)) loess.smooth.2000 <- loess.smooth(dat.cl.2000$x[na.dat.2000], dat.cl.2000$dat[na.dat.2000], span=0.20) diff.loess.smooth.2000 <- which(diff(loess.smooth.2000$y) == (min(diff(loess.smooth.2000$y))), arr.ind=T) val.in.jday.2000 <- loess.smooth.2000$y[diff.loess.smooth.2000] xmid.2000 <- val.in.jday.2000 scal.2000 <- (min(na.omit(dat.cl.2000$dat)) - max(na.omit(dat.cl.2000$dat))) / (max(na.omit(dat.cl.2000$x)) - min(na.omit(dat.cl.2000$x))) * 10 fit.dat.2000 <- nls(dat ~ SSlogis(x, Asym, xmid,scal), data = dat.cl.2000, start=list(Asym=round(Asym.2000), xmid=round(xmid.2000), scal=scal.2000), control = list(maxiter = 500, warnOnly = TRUE), trace=TRUE) What I want to be able to do however, is to determine the start and end points (dates) of the asymptote of the curve when the snowmelt initiates. Prior to this I was using the second derivative mins and maxes. #init <- optimize(f=fn.sslogis.deriv2, interval=c(1:mid.point), a=a, m=m, s=s)$minimum #this is the start of the snowmelt season #term <- optimize(f=fn.sslogis.deriv2, interval=c(mid.point:153), a=a, m=m, s=s, maximum=TRUE)$maximum #this is the end of the snowmelt season However, this cuts the melt too short. Any assistance on this non-hw problem would be appreciated. Sincerely, Katrina On Thu, Apr 19, 2012 at 4:34 AM, David Winsemius <dwinsem...@comcast.net> wrote: > > On Apr 19, 2012, at 4:41 AM, Katrina Bennett wrote: > >> Hi all, >> >> I would like to find the x position of an two asymptotes. >> >> Here is a sample of what I would like to do: >> >> x <- seq(1, 153,, 153) >> a <- 85 >> m <- 65 >> s =-1.5 >> fn <- function (x, a, m, s) { a * (exp((m - x)/s) * (1/s))/((1 + >> exp((m - x)/s)))^2 } >> plot.deriv1 <- fn(1:153, a, m, s) >> >> I can find the midpoint/minimum of this function easily. However, I >> can not find the start and end of the two asymptote position (along >> the x). > > > This is not a homework help-line. > > >> mid.point <- optimize(f=fn.sslogis.deriv1, interval=c(1:153), a=a, >> m=m, s=s)$minimum >> >> Thanks for your assistance, >> >> Katrina > > > -- > > David Winsemius, MD > West Hartford, CT > -- Katrina E. Bennett PhD Student University of Alaska Fairbanks International Arctic Research Center 930 Koyukuk Drive, PO Box 757340 Fairbanks, Alaska 99775-7340 907-474-1939 office 907-385-7657 cell kebenn...@alaska.edu Personal Address: UAF, PO Box 752525 Fairbanks, Alaska 99775-2525 bennett.katr...@gmail.com ______________________________________________ R-help@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.