Thanks very much William, That's exactly what I need! It is so excellent to do it by a group-separation by [] syntax.
Thanks again! Best regards, Jianling On 9 September 2015 at 11:15, William Dunlap <wdun...@tibco.com> wrote: > You can put all your data in one data.frame along with a column called, say, > 'group' that says which group each row is in. Then use the [] syntax in > nls's > formula argument to get group-specific estimates for some of the parameters. > E.g., in the following there is a global parameter 'b' and a group-specific > parameter > 'p'. > >> d <- transform(data.frame(x=seq(0,1,len=17), >> group=rep(c("A","B","B","C"),len=17)), y = round(1/(1.4+x^ifelse(group=="A", >> 2.3, ifelse(group=="B",3.1, 3.5))),2)) >> str(d) > 'data.frame': 17 obs. of 3 variables: > $ x : num 0 0.0625 0.125 0.1875 0.25 ... > $ group: Factor w/ 3 levels "A","B","C": 1 2 2 3 1 2 2 3 1 2 ... > $ y : num 0.71 0.71 0.71 0.71 0.69 0.7 0.69 0.69 0.62 0.64 ... >> nls(y~1/(b+x^p[group]), data=d, start=list(b=1, >> p=rep(3,length(levels(d$group))))) > Nonlinear regression model > model: y ~ 1/(b + x^p[group]) > data: d > b p1 p2 p3 > 1.406 2.276 3.186 3.601 > residual sum-of-squares: 9.537e-05 > > Number of iterations to convergence: 5 > Achieved convergence tolerance: 4.536e-06 > > (See the references listed in help(nls) to learn more about the statistical > issues.) > > > Bill Dunlap > TIBCO Software > wdunlap tibco.com > > On Wed, Sep 9, 2015 at 9:28 AM, Jianling Fan <fanjianl...@gmail.com> wrote: >> >> Hi, Bert >> >> Thanks for your reply. >> >> I am fitting a logistic does response model with 3 parameters as : >> y=a/(1+(x/x0)b), I have many sets of data. I can fit each of them for >> the model. but I want them shared the parameter x0 and b, but varied >> for each a. >> >> I don't think it is a statistics problem. It is a typical global >> curve fitting problem with shared parameters. And I know how to do it >> by many other software. But since I am trying to use R, I am wondering >> is there any package or method to do it in R? >> >> Thanks! >> >> Jianling >> >> >> On 9 September 2015 at 10:16, Bert Gunter <bgunter.4...@gmail.com> wrote: >> > Jianling: >> > >> > 1. What models are you trying to fit? Details matter, and it is >> > impossible to give a good answer without specifics. >> > >> > 2. In general terms, to do this one combines all the data and allows >> > for "appropriate" changes in the model parameters for the different >> > groups. For example, different intercepts, rate constants, etc. This >> > is where the specifics matter. >> > >> > 3. This is really more a statistics than an R question, and you would >> > probably do better to pursue these issues either with a local >> > statistical resource or on a statistics site, like >> > stats.stackexchange.com. >> > >> > Cheers, >> > Bert >> > Bert Gunter >> > >> > "Data is not information. Information is not knowledge. And knowledge >> > is certainly not wisdom." >> > -- Clifford Stoll >> > >> > >> > On Wed, Sep 9, 2015 at 9:04 AM, Jianling Fan <fanjianl...@gmail.com> >> > wrote: >> >> Hello all, >> >> >> >> I am trying to fit my data to a nls model. I have many sets of data >> >> and each can fit well for the curve. but I want to fit them at once by >> >> sharing 2 of 3 parameters of the model. I know it is a typical global >> >> curve fitting problem, but I don't know how to do it by R? >> >> >> >> Does anyone know any package for this?? >> >> >> >> Thanks a lot! >> >> >> >> >> >> Julian >> >> >> >> ______________________________________________ >> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> >> 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. >> >> >> >> -- >> Jianling Fan >> 樊建凌 >> >> ______________________________________________ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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. > > -- Jianling Fan 樊建凌 ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.