Hi, I have a question about how to get the residuals and estimations of the parameters in my program. For example, x<-c(1,2,3,4,5,6) y<-c(2.9, 1.24, 1.71, 2.989358, 1.455979, 1.4) nls(y ~ a+sin(b*x),start=list(a=2.2,b=1.8),trace=TRUE) I can get the estimation of a, b and residuals from the output but I need them to be vectors in order to do futhur calculations in a program. Is there any options for this function nls similar to lm$coefficients and lm$residuals which I can get vectors of estimation and residuals? Thanks very much for your help Chung
Assign the nls() output to an object and then use coef() and resid(), just as you do with lm(). Andy> From: Chung Chang > > Hi, > I have a question about how to get the residuals and estimations > of the parameters in my program. > For example, > x<-c(1,2,3,4,5,6) > y<-c(2.9, 1.24, 1.71, 2.989358, 1.455979, 1.4) > nls(y ~ a+sin(b*x),start=list(a=2.2,b=1.8),trace=TRUE) > I can get the estimation of a, b and residuals from the output but I > need them to be vectors in order to do futhur calculations in a > program. Is there any options for this function nls similar to > lm$coefficients and lm$residuals which I can get vectors of > estimation and residuals? > Thanks very much for your help > > Chung > > ______________________________________________ > 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 > >
as.vector(coef(nlsobj)) as.vector(resid(nlsobj)) On Wed, 2 Feb 2005, Chung Chang wrote:> Hi, > I have a question about how to get the residuals and estimations > of the parameters in my program. > For example, > x<-c(1,2,3,4,5,6) > y<-c(2.9, 1.24, 1.71, 2.989358, 1.455979, 1.4) > nls(y ~ a+sin(b*x),start=list(a=2.2,b=1.8),trace=TRUE) > I can get the estimation of a, b and residuals from the output but I > need them to be vectors in order to do futhur calculations in a > program. Is there any options for this function nls similar to > lm$coefficients and lm$residuals which I can get vectors of > estimation and residuals? > Thanks very much for your help > > Chung > > ______________________________________________ > 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 >