[R] How to do global curve fitting in R
wdunlap at tibco.com
Wed Sep 9 19:15:11 CEST 2015
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
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
> 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))
'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,
Nonlinear regression model
model: y ~ 1/(b + x^p[group])
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
On Wed, Sep 9, 2015 at 9:28 AM, Jianling Fan <fanjianling at 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?
> On 9 September 2015 at 10:16, Bert Gunter <bgunter.4567 at 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 <fanjianling at gmail.com>
> >> 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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> and provide commented, minimal, self-contained, reproducible code.
> Jianling Fan
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help