# [R] fit a gamma pdf using Residual Sum-of-Squares

Matthew Dowle mdowle at mdowle.plus.com
Mon Mar 8 18:25:09 CET 2010

```Thanks for making it quickly reproducible - I was able to see that message
in English within a few seconds.
The start has x=86, but the data is also called x.  Remove x=86 from start
and you get a different error.
P.S. - please do include the R version information. It saves time for us,
and we like it if you save us time.

"vincent laperriere" <vincent_laperriere at yahoo.fr> wrote in message
news:883644.16455.qm at web24106.mail.ird.yahoo.com...
Hi all,

I would like to fit a gamma pdf to my data using the method of RSS (Residual
Sum-of-Squares). Here are the data:

x <- c(86,  90,  94,  98, 102, 106, 110, 114, 118, 122, 126, 130, 134, 138,
142, 146, 150, 154, 158, 162, 166, 170, 174)
y <- c(2, 5, 10, 17, 26, 60, 94, 128, 137, 128, 77, 68, 65, 60, 51, 26, 17,
9, 5, 2, 3, 7, 3)

I have typed the following code, using nls method:

fit <- nls(y ~ (1/((s^a)*gamma(a))*x^(a-1)*exp(-x/s)), start = c(s=3, a=75,
x=86))

But I have the following message error (sorry, this is in German):

Fehler in qr(.swts * attr(rhs, "gradient")) :
Dimensionen [Produkt 3] passen nicht zur Länge des Objektes [23]
Zusätzlich: Warnmeldung:
In .swts * attr(rhs, "gradient") : Länge des längeren Objektes
ist kein Vielfaches der Länge des kürzeren Objektes

Could anyone help me with the code?
I would greatly appreciate it.
Sincerely yours,
Vincent Laperrière.

[[alternative HTML version deleted]]

--------------------------------------------------------------------------------

>

```