[R] How to Fit a Set of Lines Parametrized by a Number

Lorenzo Isella lorenzo.isella at gmail.com
Wed Dec 21 16:58:35 CET 2011


Dear All,
It is not very difficult, in R, to perform a linear fit

y=Ax+B on a single set of data.
However, imagine that you have several datasets labelled by a number
(real or integer does not matter) K. For each individual dataset, it
would make sense to resort to a linear fit, but now A and B both
depend on K.
In other words you would like to fit all your data according to

y=A(K)x+B(K).

You already have an idea of the functional dependence of A and B on K
(which involves other unknown parameters to estimate) e.g.

A(K)=alpha+beta^K, with unknown parameters alpha and beta.

How would you tackle this problem?
On top of my head, if I have N datasets, I can only think about
getting N estimates {A1,A2...AN} for the A parameter for all the N
datasets by fitting them individually.
I would then resort e.g. to a Levemberg-Marquardt algorithm to
determine the values of alpha and beta that best fit alpha+beta^K to
my set {A1,A2...AN} for the corresponding N values of K.
For B(K), I would follow exactly the same procedure.
Does anybody know any better method?
Any suggestion is welcome.
Cheers

Lorenzo



More information about the R-help mailing list