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'. 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 ) #print( summary( res ) ) -- View this message in context: http://r.789695.n4.nabble.com/ecdf-to-nls-how-to-transform-data-tp3671754p3671754.html Sent from the R help mailing list archive at Nabble.com.
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
On Jul 16, 2011, at 14:17 , 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'. > What should I do now?Consider using fitdistr() from the MASS package. What you're trying to do is just wrong!> > 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 ) )Ouch!!!! Do teach yourself what exp() means. I believe that wants to be exp( - exp( - ( x - mue ) / beta ) ) notice that fitdistr() needs the density, though. I.e. the derivative of the above with respect to x. -- Peter Dalgaard Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com