Xavier Barron
2006-Jul-18 16:06 UTC
[R] How can I extract information from list which class is nls
Hello! I work with : R : Copyright 2006, The R Foundation for Statistical Computing Version 2.3.1 (2006-06-01) On Windows XP Professional (Version 2002) SP2. At this moment I use the function "nls" combined with a selfStar model (SSmicmen, related to Michaelis-Menten equation, and provided by the "stats" package). When I realise the following operation (cf. p 59 of the "An Introduction to R" manual, http://www.r-project.org/, for more details):> fit<-nls(y~SSmicmen(x, Vm, K), df) > summary(fit)I obtain the values of Vm and K. The object "fit" is a list of the class "nls". However I cannot identify the objects which are inside of "fit" and which contain the values of Vm and K. Actually, I would like to extract these values to introduce them into new objects but I don't know how?! Maybe, somebody could help me to solve this problem. It would be very helpful for me. Best regards, Xavier
Petr Pikal
2006-Jul-18 16:35 UTC
[R] How can I extract information from list which class is nls
Hi your fit is an object (list) and you could use some functions like summary or coef to extract usefull information from it or you can call its components on your own.> DNase1 <- subset(DNase, Run == 1) > > ## using a selfStart model > fm1DNase1 <- nls(density ~ SSlogis(log(conc), Asym, xmid, scal),DNase1)> summary(fm1DNase1)Formula: density ~ SSlogis(log(conc), Asym, xmid, scal) Parameters: Estimate Std. Error t value Pr(>|t|) Asym 2.34518 0.07815 30.01 2.17e-13 *** xmid 1.48309 0.08135 18.23 1.22e-10 *** scal 1.04146 0.03227 32.27 8.51e-14 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.01919 on 13 degrees of freedom> coef(fm1DNase1)Asym xmid scal 2.345180 1.483090 1.041455> coef(fm1DNase1)[1]Asym 2.34518>HTH Petr On 18 Jul 2006 at 18:06, Xavier Barron wrote: Date sent: Tue, 18 Jul 2006 18:06:00 +0200 (CEST) From: Xavier Barron <xbarron at yahoo.com> To: r-help at stat.math.ethz.ch Subject: [R] How can I extract information from list which class is nls> Hello! > > I work with : > R : Copyright 2006, The R Foundation for > Statistical Computing > Version 2.3.1 (2006-06-01) > On Windows XP Professional (Version 2002) SP2. > > At this moment I use the function "nls" combined > with a selfStar model (SSmicmen, related to > Michaelis-Menten equation, and provided by the > "stats" package). > > When I realise the following operation (cf. p 59 > of the "An Introduction to R" manual, > http://www.r-project.org/, for more details): > > > fit<-nls(y~SSmicmen(x, Vm, K), df) > > summary(fit) > > I obtain the values of Vm and K. The object "fit" > is a list of the class "nls". However I cannot > identify the objects which are inside of "fit" > and which contain the values of Vm and K. > > Actually, I would like to extract these values to > introduce them into new objects but I don't know > how?! > > Maybe, somebody could help me to solve this > problem. It would be very helpful for me. > > Best regards, > > Xavier > > ______________________________________________ > R-help at stat.math.ethz.ch 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.Petr Pikal petr.pikal at precheza.cz
Schatzi
2011-Apr-26 18:21 UTC
[R] How can I extract information from list which class is nls
How do I extract the standard error of the parameter estimates? Also, if I would like to add two parameters together (x+y), can I use this equation to calculate the new standard error?: x = parameter 1 y = parameter 2 xSE = SE parameter 1 ySE = SE parameter 2 NewSE=(x+y)*sqrt((xSE/x)^2+(ySE/y)^2) -- View this message in context: http://r.789695.n4.nabble.com/How-can-I-extract-information-from-list-which-class-is-nls-tp804151p3476154.html Sent from the R help mailing list archive at Nabble.com.
Joshua Wiley
2011-Apr-26 22:11 UTC
[R] How can I extract information from list which class is nls
Hi, One way would be: summary(nls.object)[["coefficients"]][, "Std. Error"] If you have a hankering to do it yourself rather than go through the summary formula, the code here will get you there: getAnywhere("summary.nls") If you are going to be doing it a lot, creating a little function might be nice: se.coef.nls <- function(model) { summary(model)[["coeffficients"]][, "Std. Error"] } se.coef.nls(yourmodel) I have been doing something along those lines for a number of models. Sadly, there is not a consistent name always given to the parameter or coefficients table, so it will not quite be one size fits all, but generally using str(), you can figure out what the names of what you want are so it is not much trouble to get out. str(summary(yourmodel)) Cheers, Josh On Tue, Apr 26, 2011 at 11:21 AM, Schatzi <adele_thompson at cargill.com> wrote:> How do I extract the standard error of the parameter estimates? > > Also, if I would like to add two parameters together (x+y), can I use this > equation to calculate the new standard error?: > x = parameter 1 > y = parameter 2 > xSE = SE parameter 1 > ySE = SE parameter 2 > > NewSE=(x+y)*sqrt((xSE/x)^2+(ySE/y)^2) > > > > -- > View this message in context: http://r.789695.n4.nabble.com/How-can-I-extract-information-from-list-which-class-is-nls-tp804151p3476154.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. >-- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/
Gabor Grothendieck
2011-Apr-27 02:25 UTC
[R] How can I extract information from list which class is nls
On Tue, Apr 26, 2011 at 2:21 PM, Schatzi <adele_thompson at cargill.com> wrote:> How do I extract the standard error of the parameter estimates? > > Also, if I would like to add two parameters together (x+y), can I use this > equation to calculate the new standard error?: > x = parameter 1 > y = parameter 2 > xSE = SE parameter 1 > ySE = SE parameter 2 > > NewSE=(x+y)*sqrt((xSE/x)^2+(ySE/y)^2)Try taking the square roots of their variance:> example(nls) > sqrt(diag(vcov(fm1DNase1)))Asym xmid scal 0.07815395 0.08135321 0.03227080> > # it gives the same result as another solution > # offered on this thread > coef(summary(fm1DNase1))[, "Std. Error"]Asym xmid scal 0.07815395 0.08135321 0.03227080 -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com