OK, I am thankful and understand what my mistakes were, but now I look at my real data and have tried self starting functions and creating my own functions, resulting in other errors.
This is one data set. I have used linear models, but as these data reflect fish consuming energy during a starvation period, there is a lower asymptote. I also realize that data is rather scattered and not the cleanest. I am interested in looking at how fast the animals reach the asymptote. With three different temperatures, I expect that the three curves are different. I feel like I am making this more difficult than it really is. Data... Days<-c(12, 12, 12, 12, 22, 22, 22, 22, 32, 32, 32, 32, 37, 38, 38, 39, 39, 39, 39, 39, 39, 39, 1, 1, 1, 1) joules<-c(8.782010, 8.540524, 8.507526, 11.296904, 4.232690, 13.026588, 10.213342, 4.771482, 4.560359, 6.146684, 9.651727, 8.064329, 9.419335, 7.129264, 6.079012, 7.095888, 17.996794, 7.028287, 8.028352, 5.497564, 11.607090, 9.987215, 11.065307, 21.433094, 20.366385, 22.475717) X11() par(cex=1.6) plot(joules~Days,xlab="Days after fasting was initiated",ylab="Mean energy per fish (KJ)") model<-nls(joules~a+b*exp(-c*Days),start=list(a=8,b=9,c=-.229), control=list(minFactor=1e-12),trace=TRUE) summary(model) As always, thank you...keith On Fri, Aug 27, 2010 at 10:59 AM, Peter Ehlers <ehl...@ucalgary.ca> wrote: > Just a small fix to my solution; inserted below. > > > On 2010-08-27 3:51, Peter Ehlers wrote: > >> On 2010-08-26 15:52, Marlin Keith Cox wrote: >> >>> I agree. I typically do not use non-linear functions, so am seeing the >>> "art" in describing functions of non-linear plots. One last thing. I >>> tried >>> to use a self-starting Weibull function with the posted data and received >>> the following error. >>> >>> model<-nls(Level~ SSweibull(Time,Asym,Drop,lrc,pwr)) >>> Error in qr.default(.swts * attr(rhs, "gradient")) : >>> NA/NaN/Inf in foreign function call (arg 1) >>> >>> I do not understand the error statement. >>> >> >> The problem is the zeros in your independent variable (see >> the definition of coefficient 'lrc'). You can try using >> SSweibull(Time + 0.000001, ...). But a better way would >> be to use >> >> init <- getInitial(Level~ SSweibull(Time,Asym,Drop,lrc,pwr)) >> > > This needs a 'data=' argument for getInitial(). I had put > the variables in a data.frame, then modified the code by > deleting 'data=dat', forgetting that getInitial() does not > default to looking in the global environment for its data. > Easily fixed with > > init <- getInitial(Level~ SSweibull(Time,Asym,Drop,lrc,pwr), > data=.GlobalEnv) > > or, of course, with an appropriate data.frame. > > > -Peter Ehlers > > > >> (which will often give the converged values). You can >> follow up with >> >> fm <- nls(Level ~ Asym-Drop*exp(-exp(lrc)*Time^pwr), start = init) >> >> -Peter Ehlers >> >> >>> kc >>> On Thu, Aug 26, 2010 at 1:44 PM, Bert Gunter<gunter.ber...@gene.com> >>> wrote: >>> >>> My opinions only below; consume at your own risk. >>>> >>>> On Thu, Aug 26, 2010 at 2:20 PM, Marlin Keith Cox<marlink...@gmail.com> >>>> wrote: >>>> >>>>> The background you requested are energetic level (joules) in a group of >>>>> starved fish over a time period of 45 days. Weekly, fish (n=5) were >>>>> >>>> removed >>>> >>>>> killed and measured for energy. This was done at three temperatures. I >>>>> >>>> am >>>> >>>>> comparing the rates at which the fish consume stored body energy at >>>>> each >>>>> >>>> of >>>> >>>>> the three temperatures. Initial data looks like the colder fish >>>>> have different rates (as would be expected) than do warmer fish. In all >>>>> cases the slope is greatest at the beginning of the curve and flattens >>>>> >>>> after >>>> >>>>> several weeks. This is what is interesting - where in time the line >>>>> starts to flatten out. >>>>> >>>>> By calculating a non-linear equation of a line, I was hoping to use the >>>>> first and second derivatives of the function to compare and explain >>>>> differences between the three temperature. >>>>> >>>> >>>> Bad idea. Derivatives from fitted curves are generally pretty >>>> imprecisely determined. And you don't need them: If the curves are >>>> being (adequately/appropriately) parameterized as Weibull, then all >>>> the information is in the parameters anyway, which can be directly >>>> modeled, fitted, and compared as functions of temperature -- provided >>>> that the design permits this (i.e. provides sufficient precision for >>>> the characterizations/comparisons). >>>> >>>> If you don't know how to do this, seek further statistical help. >>>> >>>> -- >>>> Bert Gunter >>>> Genentech Nonclinical Statistics >>>> >>>> >>>> >>>>> The data originally posted was an example of one of the curves >>>>> >>>> experienced. >>>> >>>>> >>>>> kc >>>>> >>>>> On Thu, Aug 26, 2010 at 9:48 AM, David Winsemius< >>>>> dwinsem...@comcast.net >>>>> wrote: >>>>> >>>>> >>>>>> On Aug 26, 2010, at 1:35 PM, Marlin Keith Cox wrote: >>>>>> >>>>>> I need the parameters estimated for a non-linear equation, an example >>>>>> >>>>> of >>>> >>>>> the >>>>>>> data is below. >>>>>>> >>>>>>> >>>>>>> # rm(list=ls()) I really wish people would add comments to >>>>>>> >>>>>> destructive >>>> >>>>> pieces of code. >>>>>>> >>>>>>> >>>>>> Time<-c( 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, >>>>>> >>>>>>> 4, 4, 5, 5, 5, 5, 5, 8, 8, 8, 8, 8) >>>>>>> Level<-c( 100, 110, 90, 95, 87, 60, 65, 61, 55, 57, 40, 41, >>>>>>> >>>>>> 50, >>>> >>>>> 47, >>>>>>> 44, 44, 42, 38, 40, 37, 37, 35, 40, 34, 32, 20, 22, 25, >>>>>>> >>>>>> 27, >>>> >>>>> 29) >>>>>>> plot(Time,Level,pch=16) >>>>>>> >>>>>>> >>>>>> You did not say what sort of "non-linear equation" would best suit, >>>>>> nor >>>>>> >>>>> did >>>> >>>>> you offer any background regarding the domain of study. There must be >>>>>> >>>>> many >>>> >>>>> ways to do this. After looking at the data, a first pass looks like >>>>>> >>>>> this: >>>> >>>>> >>>>>> lm(log(Level) ~Time ) >>>>>>> >>>>>> >>>>>> Call: >>>>>> lm(formula = log(Level) ~ Time) >>>>>> >>>>>> Coefficients: >>>>>> (Intercept) Time >>>>>> 4.4294 -0.1673 >>>>>> >>>>>> exp(4.4294) >>>>>>> >>>>>> [1] 83.88107 >>>>>> >>>>>>> points(unique(Time), exp(4.4294 -unique(Time)*0.1673), col="red", >>>>>>> >>>>>> pch=4) >>>> >>>>> >>>>>> Maybe a Weibull model would be more appropriate. >>>>>> >>>>>> >>>>>> -- >>>>>> >>>>>> David Winsemius, MD >>>>>> West Hartford, CT >>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>> [[alternative HTML version deleted]] >>>>> >>>> > >>>> >>>>> ______________________________________________ >>>>> 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<http://www.r-project.org/posting-guide.html> >>>> <http://www.r-project.org/posting-guide.html> >>>> >>>> and provide commented, minimal, self-contained, reproducible code. >>>>> >>>>> >>>> >>>> >>>> -- >>>> Bert Gunter >>>> Genentech Nonclinical Biostatistics >>>> 467-7374 >>>> http://devo.gene.com/groups/devo/depts/ncb/home.shtml >>>> >>>> >>> >>> >> -- M. Keith Cox, Ph.D. Alaska NOAA Fisheries, National Marine Fisheries Service Auke Bay Laboratories 17109 Pt. Lena Loop Rd. Juneau, AK 99801 keith....@noaa.gov marlink...@gmail.com U.S. (907) 789-6603 [[alternative HTML version deleted]] ______________________________________________ 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.