[R] ecdf() to nls() - how to transform data?

David Winsemius dwinsemius at comcast.net
Sat Jul 16 16:01:02 CEST 2011


On Jul 16, 2011, at 8:17 AM, Jochen1980 wrote:

> Hi,
>
> I am using ecdf-function and want to use the ecdf()-data-points for  
> nls() as
> data-parameter.
> nls() expects 'list' or 'environment' as a data-type,  
> knots(ecdf(mydata))
> gives me 'numeric'.

If you put them into 'df' with appropriate name and add an appropriate  
'y' value you should get success. See below. And perhaps you should  
plot your ecdf so you can figure out what you y-values should be.

> What should I do now?
>
> Thanks in advance - Jochen
>
> Here is the code:
> #################################################
> # --- Fit ---
> # Gumbel-Dist-Function, cumulative,
> http://en.wikipedia.org/wiki/Gumbel_distribution
> #               ( - ( x - mue ) / beta )
> #          ( -e )^
> # F(x) = e^
> # formula for fitting-function
> # formula: y ~ I( exp(1) ^ ( - exp(1) ) ^ ( - ( x - mue ) / beta ) )
> # data: ecdf( hgd$V1 )
> # start: list( mue=0.1, beta=0.025 )
> gpfunction <- ecdf( hgd$V1 )
> gplistrange <- seq( 0.0, 1, by=0.001 )
> gplist <- gpfunction( gplistrange )
> print( gplist )
> print( class( gplist ) )
> print("---")
> #res <- nls( y ~ I( exp(1) ^ ( - exp(1) ) ^ ( - ( x - mue ) /  
> beta ) ), df,
> list( mue=0.1, beta=0.025 ), trace=TRUE )

This may or may not work. I didn't try it because I was pretty sure  
that the I() was unnecessary and I knew that exp(1)^(.) was just a  
convoluted way of doing exp(.), so it can be considerably simplified:

The 'df' object needs to be constructed so that the variables inside  
the function match column names in df, so you need df to have columns  
'y' and 'x'.

Try it out with a function like rgamma. Generate a random sample,  
rgamma(100, shape=2), apply ecdf, construct a 'df' argument and use  
nls to solve for y ~ pgamma(knots, shape). Then substitute in your  
(hopefully) simplified Gumbel function.


> #print( summary( res ) )



David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list