0

I want to estimate the parameters of a GEV (generalized extreme value) distribution using the method of weighted least squares. I use R, and I found a function called nls which I think might be used for this purpose. It asks for a formula and an optional dataset. I guess the GEV formula and annual maxima series should in here, but I am not sure how. Has anyone used nls and has any idea on how to do this?

#Vector of ranged annual maxima
x <- c(21,24,29,32,32,34,35,35,35,36,37,37,38,40,40,41,43,47,47,52)
w <- c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2)
data <- list(x=x,w=w)
nls(y ~ exp(-(1+((x-location)/scale))^(-1/shape)),data=data, weights=w,start=list(location=5,scale=2,shape=0.10))                 

The error says that y is missing. y is what we get when we optimize the GEV parameters, so that y becomes as close to x as possible for all x's (also depending on the weights). So y is unknown until we have estimated the GEV parameters...

  • 1
    Yes, `nls` is heavily used by a lot of people. Give us [a reproducible example](http://stackoverflow.com/a/5963610/1412059) and we can help you. – Roland Jun 17 '13 at 09:50
  • I added an example, although it is not very useful since my problem is that I don't know how to formulate the code. – user1820508 Jun 18 '13 at 09:00
  • What is `x`? The `data` parameter expects a data.frame containing `am`, `x`, and `w`. You need to give starting values to `nls`, e.g., `start=list(location=...,scale=...,shape=...`. It's your job to find these starting values. – Roland Jun 18 '13 at 09:37
  • x is actually am when I think about it. I updated the question and code. – user1820508 Jun 18 '13 at 13:11
  • You need both x and y values for regression. – Roland Jun 18 '13 at 13:14

1 Answers1

0

As @Roland commented, you need to have two variables to do a regression. In this case, you only have one: the observed values for the GEV. As such you don't actually want to fit the distribution using nls, but some other algorithm, for example maximum likelihood. See the package evd which has functions to deal with GEVs including fitting them from data.

Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
  • thank you. I have fitted GEV to the data using both maximum likelihood and probability weighted moments. The reason why I wanted to use nls is that I wanted to try a method called "weighted least squares", which I can't find enough information about to program from scratch. – user1820508 Jun 20 '13 at 11:01