I have the following data set, and I have to find the line of best fit using this equation, y = a*(1 - exp(-b*x)). samples = seq(1,20,by=1) species = c(5,8,9,9,11,11,12,15,17,19,20,20,21,23,23,25,25,27,27,27) plot(samples,species, main = "Accumulation Curve for Tree Species Richness", xlab = "Samples", ylab = "Number of Species") curve((y = 27*(1 - exp(-.15*x))),from=0,to=20,add = T) I tried to find the best fit curve using: fit = nls(species ~ a *(1 - exp(-b*x)),start = list(a = 27, b = .15) but I get a "parameters without starting value in 'data': x" and I don't have any idea what this means, or how to fix the above code. -- View this message in context: http://r.789695.n4.nabble.com/Generating-a-best-fit-line-for-non-linear-data-tp3482193p3482193.html Sent from the R help mailing list archive at Nabble.com.
Hi, Try> d <- data.frame(samples, species) > fit = nls(species ~ a *(1 - exp(-b*samples)), start = list(a = 27, b .15), data = d) > summary(fit)Formula: species ~ a * (1 - exp(-b * samples)) Parameters: Estimate Std. Error t value Pr(>|t|) a 35.82472 3.02073 11.860 6.10e-10 *** b 0.07168 0.01023 7.009 1.53e-06 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 1.333 on 18 degrees of freedom Number of iterations to convergence: 5 Achieved convergence tolerance: 2.837e-06 HTH Jorge On Thu, Apr 28, 2011 at 4:56 PM, BornSurvivor <> wrote:> I have the following data set, and I have to find the line of best fit > using > this equation, > y = a*(1 - exp(-b*x)). > > samples = seq(1,20,by=1) > species = c(5,8,9,9,11,11,12,15,17,19,20,20,21,23,23,25,25,27,27,27) > plot(samples,species, main = "Accumulation Curve for Tree Species > Richness", > xlab = "Samples", ylab = "Number of Species") > curve((y = 27*(1 - exp(-.15*x))),from=0,to=20,add = T) > > I tried to find the best fit curve using: > > fit = nls(species ~ a *(1 - exp(-b*x)),start = list(a = 27, b = .15) > > but I get a "parameters without starting value in 'data': x" and I don't > have any idea what this means, or how to fix the above code. > > -- > View this message in context: > http://r.789695.n4.nabble.com/Generating-a-best-fit-line-for-non-linear-data-tp3482193p3482193.html > Sent from the R help mailing list archive at Nabble.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. >[[alternative HTML version deleted]]
I think that you probably need to provide the x values to nls. Try, for example, fit <- nls(species ~ a *(1 - exp(-b*samples)),start = list(a = 27, b = .15)) I hope that this helps, Andrew On Thu, Apr 28, 2011 at 01:56:43PM -0700, BornSurvivor wrote:> I have the following data set, and I have to find the line of best fit using > this equation, > y = a*(1 - exp(-b*x)). > > samples = seq(1,20,by=1) > species = c(5,8,9,9,11,11,12,15,17,19,20,20,21,23,23,25,25,27,27,27) > plot(samples,species, main = "Accumulation Curve for Tree Species Richness", > xlab = "Samples", ylab = "Number of Species") > curve((y = 27*(1 - exp(-.15*x))),from=0,to=20,add = T) > > I tried to find the best fit curve using: > > fit = nls(species ~ a *(1 - exp(-b*x)),start = list(a = 27, b = .15) > > but I get a "parameters without starting value in 'data': x" and I don't > have any idea what this means, or how to fix the above code. > > -- > View this message in context: http://r.789695.n4.nabble.com/Generating-a-best-fit-line-for-non-linear-data-tp3482193p3482193.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.-- Andrew Robinson Program Manager, ACERA Department of Mathematics and Statistics Tel: +61-3-8344-6410 University of Melbourne, VIC 3010 Australia (prefer email) http://www.ms.unimelb.edu.au/~andrewpr Fax: +61-3-8344-4599 http://www.acera.unimelb.edu.au/ Forest Analytics with R (Springer, 2011) http://www.ms.unimelb.edu.au/FAwR/ Introduction to Scientific Programming and Simulation using R (CRC, 2009): http://www.ms.unimelb.edu.au/spuRs/