[R] Return level plots

R. Michael Weylandt michael.weylandt at gmail.com
Fri Sep 21 21:04:51 CEST 2012


On Fri, Sep 21, 2012 at 3:17 PM, MichelleNCSU <mlcipull at ncsu.edu> wrote:
> Hello,
>
> First of all, let me apologize that my statistics background is modest at
> best.
>
> I am doing some extreme value analysis on model output (WRF) which have the
> following dimensions:
>
> speed(time,lat,lon)
>
> I am trying to fit the GPD (gpd.fit) to each point (time,lat,lon) to get a
> return level plot with values at each grid point.  (Map with return level by
> location.)
>
> Here is some code I tried, following similar structure to languages I'm more
> familiar with, but it isn't working.
>
> Y = as.matrix(time,lat,lon)
>
>  for (t in 1:67)
> + for (j in 1:106)
> + for (i in 1:193)
> + fit(t,j,i)<-gpd.fit(speed(t,j,i), threshold=17,ydat = Y)

On first blush, your problem seems to be a case of MATLAB-itis ;-)

R subsetting is done with square brackets (like x[3,4] or so), with
parentheses being reserved for grouping and function calls.

Moving ahead, you're really going to want to use braces for your loops
to clarify scope (see basically every programmer's guide ever)"

for(t in 1:67){
    for(j in 1:106){
        for(i in 1:193){
            fit[t,j,i] <- gpd.fit(speed[t,j,i], threshold = 17, ydat = Y)
        }
    }
}

Isn't that clearer?

Finally, you should see if the function gpd.fit() is (in R speak)
vectorized: if so, you will be able to drop the explicit loops and
make things much much faster.

Cheers,
Michael

PS -- Just a heads up: most of us don't read R help through Nabble (R
help is really a mailing list) so it would make us all much happier if
you could explicitly include context in any follow up questions.

>
> I receive errors at this point, and cant figure out how to get individual
> fits at each grid point.
>
> Thanks,
>
> Michelle
>
>




More information about the R-help mailing list