How can I extract information from list which class is nls

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

How can I extract information from list which class is nls

Xavier Barron-2
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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How can I extract information from list which class is nls

PIKAL Petr
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 <[hidden email]>
To:             [hidden email]
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
>
> ______________________________________________
> [hidden email] 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
[hidden email]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How can I extract information from list which class is nls

Schatzi
How do I extract the standard error of the parameter estimates using nls?

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)

In theory, practice and theory are the same. In practice, they are not - Albert Einstein
Reply | Threaded
Open this post in threaded view
|

Re: How can I extract information from list which class is nls

Joshua Wiley-2
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 <[hidden email]> 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.
>
> ______________________________________________
> [hidden email] 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/

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How can I extract information from list which class is nls

Peter Ehlers
On 2011-04-26 15:11, Joshua Wiley wrote:

> 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.

I would generally use the coef() extractor function if
it's available (and it is for nls()). ?nls has an example:

   coef(summary(fm1DNase1))

which is a matrix from which you can get the SEs:

   coef(summary(fm1DNase1))[,"Std. Error"]

or

   coef(summary(fm1DNase1))[, 2]

Schatzi,
As to your other question about 'adding two parameters', that
doesn't make sense to me. Can you provide a sensible example?
In any case you would no doubt have to look at the covariance
matrix of the parameter estimates (with vcov()).

Peter Ehlers

>
> str(summary(yourmodel))
>
> Cheers,
>
> Josh
>
> On Tue, Apr 26, 2011 at 11:21 AM, Schatzi<[hidden email]>  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.
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>
>
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How can I extract information from list which class is nls

Joshua Wiley-2
> I would generally use the coef() extractor function if
> it's available (and it is for nls()). ?nls has an example:
>
>  coef(summary(fm1DNase1))

I knew about coef() on model objects, but I did not know it had
methods for their summaries.  What wonderful information!

Josh

>
> which is a matrix from which you can get the SEs:
>
>  coef(summary(fm1DNase1))[,"Std. Error"]
>
> or
>
>  coef(summary(fm1DNase1))[, 2]
>
> Schatzi,
> As to your other question about 'adding two parameters', that
> doesn't make sense to me. Can you provide a sensible example?
> In any case you would no doubt have to look at the covariance
> matrix of the parameter estimates (with vcov()).
>
> Peter Ehlers

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How can I extract information from list which class is nls

Gabor Grothendieck
In reply to this post by Schatzi
On Tue, Apr 26, 2011 at 2:21 PM, Schatzi <[hidden email]> 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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

RE: How can I extract information from list which class is nls

Schatzi
This post was updated on .
Here is more information on the equation. It is a growth function:

Growth = a + b*(1-exp(-k*time))

where a, b and k are parameters. I wanted to test the difference in total growth between treatments and the parameters a + b represent total growth. Thus, I figured that I could add the parameters and the SE to test the treatment differences. I also need the rate constant k and the initial values a and their treatment differences.
I found the equation with which to combine the standard errors posted on this website:

<http://sci.tech-archive.net/Archive/sci.math/2004-07/4780.html>

This book was referenced: Kendall & Stuart's Advanced Theory of Statistics

Thanks for all you your help.
Adele
In theory, practice and theory are the same. In practice, they are not - Albert Einstein
Reply | Threaded
Open this post in threaded view
|

Re: How can I extract information from list which class is nls

David Winsemius

On Apr 27, 2011, at 9:28 AM, Schatzi wrote:

> Here is more information on the equation. It is a growth function:
>
> Growth = a + b*(1-exp(-k*time))
>
> where a, b and k are parameters. I wanted to test the difference in  
> total growth between treatments and the parameters a + b represent  
> total growth. Thus, I figured that I could add the parameters and  
> the SE to test the treatment differences. I also need the rate  
> constant k and the initial values a and their treatment differences.
> I found the equation I posted on this website:
> http://sci.tech-archive.net/Archive/sci.math/2004-07/4780.html
> This book was referenced: Kendall & Stuart's Advanced Theory of  
> Statistics

You should look at the vignettes and examples in the `fda` package.  
fda == Functional Data Analysis and the authors have a book that adds  
further background.

http://ego.psych.mcgill.ca/misc/fda/ex-growth-a2.html

You might also try:
RSiteSearch("growth curve")

--
David.

>
> Thanks for all you your help.
> Adele
>
>
> From: [hidden email] [mailto:[hidden email]
> ]
> Sent: Tuesday, April 26, 2011 09:29 PM
> To: Thompson, Adele - [hidden email]
> Subject: Re: How can I extract information from list which class is  
> nls
>
> On Tue, Apr 26, 2011 at 2:21 PM, Schatzi <[hidden email]</user/
> SendEmail.jtp?type=node&node=3477116&i=0&by-user=t>> 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
>
> ______________________________________________
> [hidden email]</user/SendEmail.jtp?type=node&node=3477116&i=1&by-
> user=t> 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.
>
> ________________________________
> If you reply to this email, your message will be added to the  
> discussion below:
> http://r.789695.n4.nabble.com/How-can-I-extract-information-from-list-which-class-is-nls-tp804151p3477116.html
> To unsubscribe from How can I extract information from list which  
> class is nls, click here<
> >.
>
>
> -----
> In theory, practice and theory are the same. In practice, they are  
> not - Albert Einstein
> --
> View this message in context:
http://r.789695.n4.nabble.com/How-can-I-extract-information-from-list-which-class-is-nls-tp804151p3478123.html
> Sent from the R help mailing list archive at Nabble.com.
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

RE: How can I extract information from list which class is nls

Schatzi

It is not a human growth curve. The parameter estimates are about:

a = .5

b = 7

k = 1

It is not a sigmoidal curve as there is never a concave segment.

 

From: [hidden email] [mailto:[hidden email]]
Sent: Wednesday, April 27, 2011 09:15 AM
To: Thompson, Adele - [hidden email]
Subject: Re: How can I extract information from list which class is nls

 


On Apr 27, 2011, at 9:28 AM, Schatzi wrote:


> Here is more information on the equation. It is a growth function:
>
> Growth = a + b*(1-exp(-k*time))
>
> where a, b and k are parameters. I wanted to test the difference in  
> total growth between treatments and the parameters a + b represent  
> total growth. Thus, I figured that I could add the parameters and  
> the SE to test the treatment differences. I also need the rate  
> constant k and the initial values a and their treatment differences.
> I found the equation I posted on this website:
> http://sci.tech-archive.net/Archive/sci.math/2004-07/4780.html
> This book was referenced: Kendall & Stuart's Advanced Theory of  
> Statistics

You should look at the vignettes and examples in the `fda` package.  
fda == Functional Data Analysis and the authors have a book that adds  
further background.

http://ego.psych.mcgill.ca/misc/fda/ex-growth-a2.html

You might also try:
RSiteSearch("growth curve")

--
David.


To unsubscribe from How can I extract information from list which class is nls, click here.

In theory, practice and theory are the same. In practice, they are not - Albert Einstein