-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I have the following data:> y[1] 0.000 0.004 0.008 0.016 0.024 0.032 0.044 0.064 0.072 0.088 0.108 0.140 [13] 0.156 0.180 0.208 0.236 0.264 0.296 0.320 0.360 0.408 0.444 0.472 0.524 [25] 0.576> x[1] 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 [16] 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 I'd like to plot the points and calculate a curved line of best fit. I know I need to use nls(), but I'm unsure how to begin....any pointers? Cheers, Nathan - -- - -------------------------------------------------------- Dr. Nathan S. Watson-Haigh OCE Post Doctoral Fellow CSIRO Livestock Industries Queensland Bioscience Precinct St Lucia, QLD 4067 Australia Tel: +61 (0)7 3214 2922 Fax: +61 (0)7 3214 2900 Web: http://www.csiro.au/people/Nathan.Watson-Haigh.html - -------------------------------------------------------- -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAklqqJsACgkQ9gTv6QYzVL4gCgCgy4qShoFX/9QWgKsBqHPhLCDS r+AAnRD3kbkImG3rVaBN6d4BP2cUmqYZ =yVLj -----END PGP SIGNATURE-----
First, try plot(x,y) If you want to use nls, you have to specify a nonlinear function to fit to your data. See ?nls. If you are really stuck on how to fit regression models, you should consult a statistician (CSIRO has a lot of expertise). Simon. On Mon, 2009-01-12 at 12:19 +1000, Nathan S. Watson-Haigh wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > I have the following data: > > > y > [1] 0.000 0.004 0.008 0.016 0.024 0.032 0.044 0.064 0.072 0.088 0.108 0.140 > [13] 0.156 0.180 0.208 0.236 0.264 0.296 0.320 0.360 0.408 0.444 0.472 0.524 > [25] 0.576 > > x > [1] 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 > [16] 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 > > I'd like to plot the points and calculate a curved line of best fit. I know I need to use nls(), but > I'm unsure how to begin....any pointers? > > Cheers, > Nathan > > > - -- > - -------------------------------------------------------- > Dr. Nathan S. Watson-Haigh > OCE Post Doctoral Fellow > CSIRO Livestock Industries > Queensland Bioscience Precinct > St Lucia, QLD 4067 > Australia > > Tel: +61 (0)7 3214 2922 > Fax: +61 (0)7 3214 2900 > Web: http://www.csiro.au/people/Nathan.Watson-Haigh.html > - -------------------------------------------------------- > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.9 (MingW32) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org > > iEYEARECAAYFAklqqJsACgkQ9gTv6QYzVL4gCgCgy4qShoFX/9QWgKsBqHPhLCDS > r+AAnRD3kbkImG3rVaBN6d4BP2cUmqYZ > =yVLj > -----END PGP SIGNATURE----- > > ______________________________________________ > 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.-- Simon Blomberg, BSc (Hons), PhD, MAppStat. Lecturer and Consultant Statistician Faculty of Biological and Chemical Sciences The University of Queensland St. Lucia Queensland 4072 Australia Room 320 Goddard Building (8) T: +61 7 3365 2506 http://www.uq.edu.au/~uqsblomb email: S.Blomberg1_at_uq.edu.au Policies: 1. I will NOT analyse your data for you. 2. Your deadline is your problem. The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. - John Tukey.
As x goes from 200 to 400, y goes from ,004 to .016 so y is quadrupling while x doubles -- quadratic growth. Fitting to a quadratic and plotting shows this to be the case. Note that for y to be quadratic in x it must be linear in the coefficients of x so we can just use lm and don't need nls: plot(y ~ x) y.lm <- lm(y ~ poly(x, 2)) lines(x, fitted(y.lm)) y.lm On Sun, Jan 11, 2009 at 9:19 PM, Nathan S. Watson-Haigh <nathan.watson-haigh at csiro.au> wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > I have the following data: > >> y > [1] 0.000 0.004 0.008 0.016 0.024 0.032 0.044 0.064 0.072 0.088 0.108 0.140 > [13] 0.156 0.180 0.208 0.236 0.264 0.296 0.320 0.360 0.408 0.444 0.472 0.524 > [25] 0.576 >> x > [1] 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 > [16] 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 > > I'd like to plot the points and calculate a curved line of best fit. I know I need to use nls(), but > I'm unsure how to begin....any pointers? > > Cheers, > Nathan > > > - -- > - -------------------------------------------------------- > Dr. Nathan S. Watson-Haigh > OCE Post Doctoral Fellow > CSIRO Livestock Industries > Queensland Bioscience Precinct > St Lucia, QLD 4067 > Australia > > Tel: +61 (0)7 3214 2922 > Fax: +61 (0)7 3214 2900 > Web: http://www.csiro.au/people/Nathan.Watson-Haigh.html > - -------------------------------------------------------- > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.9 (MingW32) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org > > iEYEARECAAYFAklqqJsACgkQ9gTv6QYzVL4gCgCgy4qShoFX/9QWgKsBqHPhLCDS > r+AAnRD3kbkImG3rVaBN6d4BP2cUmqYZ > =yVLj > -----END PGP SIGNATURE----- > > ______________________________________________ > 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. >
Just 'cos it's bent doesn't mean you need nls. With your data, lm fits (suspicously!) well... y<-c(0.000,0.004,0.008,0.016,0.024,0.032,0.044,0.064,0.072,0.088,0.108,0.140 ,0.156,0.180,0.208,0.236,0.264,0.296,0.320,0.360,0.408,0.444,0.472,0.524 ,0.576) x<-c(100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500 ,1600,1700,1800,1900,2000,2100,2200,2300,2400,2500) plot(x,y) lines(x, predict(lm(y~I(x^2))))>>> "Nathan S. Watson-Haigh" <nathan.watson-haigh at csiro.au> 01/12/092:19 AM >>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I have the following data:> y[1] 0.000 0.004 0.008 0.016 0.024 0.032 0.044 0.064 0.072 0.088 0.108 0.140 [13] 0.156 0.180 0.208 0.236 0.264 0.296 0.320 0.360 0.408 0.444 0.472 0.524 [25] 0.576> x[1] 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 [16] 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 I'd like to plot the points and calculate a curved line of best fit. I know I need to use nls(), but I'm unsure how to begin....any pointers? Cheers, Nathan - -- - -------------------------------------------------------- Dr. Nathan S. Watson-Haigh OCE Post Doctoral Fellow CSIRO Livestock Industries Queensland Bioscience Precinct St Lucia, QLD 4067 Australia Tel: +61 (0)7 3214 2922 Fax: +61 (0)7 3214 2900 Web: http://www.csiro.au/people/Nathan.Watson-Haigh.html - -------------------------------------------------------- -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAklqqJsACgkQ9gTv6QYzVL4gCgCgy4qShoFX/9QWgKsBqHPhLCDS r+AAnRD3kbkImG3rVaBN6d4BP2cUmqYZ =yVLj -----END PGP SIGNATURE----- ______________________________________________ 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. ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 S Ellison wrote:> Just 'cos it's bent doesn't mean you need nls.Sorry, my bad! :o(> With your data, lm fits (suspicously!) well...Nothing suspicious....just benchmarking some functions with different sized inputs! Thanks for the help! Nathan> > y<-c(0.000,0.004,0.008,0.016,0.024,0.032,0.044,0.064,0.072,0.088,0.108,0.140 > ,0.156,0.180,0.208,0.236,0.264,0.296,0.320,0.360,0.408,0.444,0.472,0.524 > ,0.576) > x<-c(100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500 > ,1600,1700,1800,1900,2000,2100,2200,2300,2400,2500) > plot(x,y) > lines(x, predict(lm(y~I(x^2)))) > > >>>> "Nathan S. Watson-Haigh" <nathan.watson-haigh at csiro.au> 01/12/09 > 2:19 AM >>> > I have the following data: > >> y > [1] 0.000 0.004 0.008 0.016 0.024 0.032 0.044 0.064 0.072 0.088 0.108 > 0.140 > [13] 0.156 0.180 0.208 0.236 0.264 0.296 0.320 0.360 0.408 0.444 0.472 > 0.524 > [25] 0.576 >> x > [1] 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 > 1400 1500 > [16] 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500 > > I'd like to plot the points and calculate a curved line of best fit. I > know I need to use nls(), but > I'm unsure how to begin....any pointers? > > Cheers, > Nathan > >______________________________________________ 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. ******************************************************************* This email and any attachments are confidential. Any use, copying or disclosure other than by the intended recipient is unauthorised. If you have received this message in error, please notify the sender immediately via +44(0)20 8943 7000 or notify postmaster at lgc.co.uk and delete this message and any copies from your computer and network. LGC Limited. Registered in England 2991879. Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK - -- - -------------------------------------------------------- Dr. Nathan S. Watson-Haigh OCE Post Doctoral Fellow CSIRO Livestock Industries Queensland Bioscience Precinct St Lucia, QLD 4067 Australia Tel: +61 (0)7 3214 2922 Fax: +61 (0)7 3214 2900 Web: http://www.csiro.au/people/Nathan.Watson-Haigh.html - -------------------------------------------------------- -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAklqxy0ACgkQ9gTv6QYzVL76HwCeIQlVwHX53uPJ8YHMq9djNUuR ATsAn1otbhcmjUZDxe8iatQMzo+7fv8v =Jra2 -----END PGP SIGNATURE-----