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

Greg Snow Greg.Snow at imail.org
Wed Dec 21 21:19:38 CET 2011


This looks like a hierarchical Bayes type problem.  There are a few packages that do Bayes estimation or link to external tools (like openbugs) to do this.  You would just set up each of the relationships like you define below, y is a function of a(k), b(k), x and e where e comes from a normal distribution with mean 0 and variance sigma2, then a(k) is the relationship that you show along with something similar for b(k), then you just need prior distributions for alpha, beta, (and the same for b(k)), and sigma2 and let it run.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Lorenzo Isella
> Sent: Wednesday, December 21, 2011 8:59 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] How to Fit a Set of Lines Parametrized by a Number
> 
> 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
> 
> ______________________________________________
> R-help at r-project.org 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.



More information about the R-help mailing list