On Tue, 27 Feb 2007 06:59:51 -0800 (PST), Stephen Tucker wrote:

ST> Hi Tim,
ST> 
ST> I believe fitdistr() in the MASS package is the function you are looking
ST> for. (example given in help page)...
ST> 
ST> Best regards,
ST> ST
ST> 
ST> --- Tim Bergsma <[EMAIL PROTECTED]> wrote:
ST> 
ST> > Hi.
ST> > 
ST> > I have a vector of quantiles and a vector of probabilites that, when 
ST> > plotted, look very like the gamma cumulative distribution function.  I 
ST> > can guess some shape and scale parameters that give a similar result, 
ST> > but I'd rather let the parameters be estimated.  Is there a direct way 
ST> > to do this in R?
ST> > 
ST> > Thanks,
ST> > 
ST> > Tim.
ST> > 
ST> > week <- c(0,5,6,7,9,11,14,19,39)
ST> > fraction <- c
ST> > (0,0.23279,0.41093,0.58198,0.77935,0.88057,0.94231,0.98583,1) weeks <-
ST> > 1:160/4 plot(weeks, pgamma(weeks,shape=6,scale=1.15),type="l")
ST> > points(week,fraction,col="red")
ST> > 

you can decide a "distance" criterion and select the paramers which
minimize that distance, something like
 
  criterion  <- function(param, week, fraction){
                  cdf <- pgamma(week, param[1], param[2])
                  p <- diff(cdf)
                  sum((diff(fraction)-p)^2/p) # or some other function
                  }
              
and then minimize this criterion with respect to the parameters
using optim() or nlminb().

You cannot use fitdistr() because it requires the individual sample values.
In fact you cannot even use MLE for grouped data or X^2, since the sample
size is not  known (at least not reported), hence we do not have the absolute 
frequencies. If the sample size was known, then the problem would change.
  
-- 
Adelchi Azzalini  <[EMAIL PROTECTED]>
Dipart.Scienze Statistiche, Università di Padova, Italia
tel. +39 049 8274147,  http://azzalini.stat.unipd.it/

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to