[R] how to fit a curve of form Y = X^Z
m_olshansky at yahoo.com
Wed Jun 18 00:42:38 CEST 2008
I see two possibilities:
1) Taking logarithm yields log(Y) = log(X)*Z and this is the regular linear regression with intercept = 0, and in this case Z = Sum(log(Xi)*log(Yi))/Sum(log(Xi)^2). This is very simple but not necessarily what you want (but this solution can be used as a starting point for the next one).
2) Let f(Z) = Sum((Yi-Xi^Z)^2) and use nonlinear optimization (see ?nls, ?nlm, ?optim, etc.). Note that you can compute the first two derivatives analytically.
--- On Wed, 18/6/08, Avril Coghlan <alc at sanger.ac.uk> wrote:
> From: Avril Coghlan <alc at sanger.ac.uk>
> Subject: [R] how to fit a curve of form Y = X^Z
> To: "R mailing list" <r-help at r-project.org>
> Received: Wednesday, 18 June, 2008, 12:16 AM
> I have a question about R, and will be very grateful for
> any help.
> I have two variables X and Y, and think that Y is related
> to X by a function of the form : Y = X^Z, where Z is <
> However, I'm not sure how to find the best-fit equation
> fit my data to a curve of this form using R. Have you any
> Avril Coghlan
> Wellcome Trust Sanger Institute,
> Cambridge, UK
> The Wellcome Trust Sanger Institute is operated by Genome
> Limited, a charity registered in England with number
> 1021457 and a
> company registered in England with number 2742969, whose
> office is 215 Euston Road, London, NW1 2BE.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained,
> reproducible code.
More information about the R-help