Hye every one, My question will certainly seem stupid as I am quite a beginner in R. I would like to trace a curve which fits these two vectors: x<-c( 2,3,4,5,6,7,8,10 ) y<-c( 20, 12, 8, 6, 5, 4.5, 4, 3.8) It seems to follow a non linear model. Could anyone help me because I could'nt find the answer I am looking for in the FAQs. In advance thank you for your time. G. Lefebvre -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hi, ----- Original Message ----- From: "gregory lefebvre" <greggory.lefebvre at univ-rouen.fr> To: <r-help at stat.math.ethz.ch> Sent: Wednesday, May 22, 2002 10:21 PM Subject: [R] fitting non linear data> Hye every one, > > My question will certainly seem stupid as I am quite a beginner in R.There are no stupid questions...:-)> I would like to trace a curve which fits these two vectors: > x<-c( 2,3,4,5,6,7,8,10 ) > y<-c( 20, 12, 8, 6, 5, 4.5, 4, 3.8) > > It seems to follow a non linear model. > > Could anyone help me because I could'nt find the answer I am looking for > in the FAQs.Take a look at: library(help=MASS) library(help=nls) In particular, the nls (non-linear regression) package. The MASS book (Modern Applied Statistics with Splus) by Ripley and Venables is a very good book to start. In Chapter 8 (of the 3rd Edition), there are quite an extensive explanations of how you can do non-linear models in R/Splus. MASS and nls packages are installed with R, you can open $R_HOME/library/MASS/scripts3/ch08.R to look at ALL the R codes for that chapter on non-linear models. Cheers, Ko-Kang Wang ------------------------------------------------ Ko-Kang Kevin Wang Post Graduate PGDipSci Student Department of Statistics University of Auckland New Zealand www.stat.auckand.ac.nz/~kwan022 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On 05/22/02 12:21, gregory lefebvre wrote:>I would like to trace a curve which fits these two vectors: > x<-c( 2,3,4,5,6,7,8,10 ) > y<-c( 20, 12, 8, 6, 5, 4.5, 4, 3.8)The library nls (not included in the base) is one way to fit nonlinear models. You need to have some idea of the kind of function you want to fit. Without any idea of what these data are, I thought an exponential function might do the trick, and I took wild (and very wrong, because I forgot the minus sign for B) guesses at the starting parameters:> nls(y~A*exp(B*x),start=list(A=20,B=1))Nonlinear regression model model: y ~ A * exp(B * x) data: parent.frame A B 35.6929652 -0.3290034 residual sum-of-squares: 16.28236 Warning: In my experience nls does not always converge on a solution (although it did this time). Sometimes you need to fool around with the starting parameters and other parameters, and sometimes even then it won't work. An alternative is optim(), which seems to converge on a solution all the time (in my experience) but which requires more study before you can use it. -- Jonathan Baron, Professor of Psychology, University of Pennsylvania Home page: http://www.sas.upenn.edu/~baron -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Gregory, Please have a look at the library nls (it comes with the base distribution of R). You'll find a good example in http://cran.r-project.org/doc/manuals/R-intro.pdf (pp 62 is for nonlinear least squares). You can use that document and the rest of the manuals at http://cran.r-project.org/ to guide yourself up through R. best regards, IOsu ----- Original Message ----- From: "gregory lefebvre" <greggory.lefebvre at univ-rouen.fr> To: <r-help at stat.math.ethz.ch> Sent: Wednesday, May 22, 2002 11:21 AM Subject: [R] fitting non linear data> Hye every one, > > My question will certainly seem stupid as I am quite a beginner in R. > > I would like to trace a curve which fits these two vectors: > x<-c( 2,3,4,5,6,7,8,10 ) > y<-c( 20, 12, 8, 6, 5, 4.5, 4, 3.8) > > It seems to follow a non linear model. > > Could anyone help me because I could'nt find the answer I am looking for > in the FAQs. > > In advance thank you for your time. > > G. Lefebvre > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-> r-help mailing list -- Readhttp://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html> Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch >_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._> > -- > This message has been scanned for viruses by the DIT > Computer Centre MailScanner Service, and is > believed to be clean. >-- This message has been scanned for viruses by the DIT Computer Centre MailScanner Service, and is believed to be clean. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
To factor in model uncertainty you might bootstrap a semiparametric regression. The Hmisc library areg.boot function, using the default method of avas, develops a semiparametric additive model and uses the bootstrap for confidence bands for the transformations on predictor and response variables. As an example I tried f <- areg.boot(I(y) ~ x) # don't transform y, optimally transform x # The default y ~ x shows a lot of uncertainty in transformation of y for # large y f avas Additive Regression Model areg.boot(x = I(y) ~ x) n= 8 p= 1 Apparent R2 on transformed Y scale: 0.886 Bootstrap validated R2 : 0.683 Coefficients of standardized transformations: Intercept x -1.503799e-16 1.087857e+00 summary(f) summary.areg.boot(obj = f) Estimates based on 100 resamples Values to which predictors are set when estimating effects of other predictors: I(y) x 5.5 5.5 Estimates of differences of effects on Median Y (from first X value), and bootstrap standard errors of these differences. Settings for X are shown as row headings. Predictor: x x Differences S.E Lower 0.95 Upper 0.95 Z Pr(|Z|) 3.75 0.000000 NA NA NA NA NA 5.50 -4.614057 1.268541 -7.100353 -2.127762 -3.637294 0.0002755177 7.25 -7.144868 2.030195 -11.123978 -3.165758 -3.519300 0.0004326864 plot(f) # see attached I had to fix a small bug in the function to make this work. In the plot, confidence bands are in black, individual bootstrap estimates are in red. Frank Harrell On Wed, 22 May 2002 12:21:45 +0200 gregory lefebvre <greggory.lefebvre at univ-rouen.fr> wrote:> Hye every one, > > My question will certainly seem stupid as I am quite a beginner in R. > > I would like to trace a curve which fits these two vectors: > x<-c( 2,3,4,5,6,7,8,10 ) > y<-c( 20, 12, 8, 6, 5, 4.5, 4, 3.8) > > It seems to follow a non linear model. > > Could anyone help me because I could'nt find the answer I am looking for > in the FAQs. > > In advance thank you for your time. > > G. Lefebvre > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-- Frank E Harrell Jr Prof. of Biostatistics & Statistics Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences U. Virginia School of Medicine http://hesweb1.med.virginia.edu/biostat -------------- next part -------------- A non-text attachment was scrubbed... Name: z.png Type: image/png Size: 11010 bytes Desc: not available Url : https://stat.ethz.ch/pipermail/r-help/attachments/20020522/85c3e3f3/z.png