[R] Fitting Data to a Noncentral Chi-Squared Distribution using MLE

Charles C. Berry cberry at tajo.ucsd.edu
Tue Sep 11 22:35:49 CEST 2007



This is what I might do:

> y <- rchisq( 1000, df=10, ncp=2 )
> library( stats4 )
> res <- mle( function(x,z) -sum( dchisq(y, x, z , log=TRUE ) ), start=list( x=5, z=5 ) )
> coef(res)
         x         z
10.355711  1.586123
>
> ## or just to keep clear of boundary constraints:
>
> res <- mle( function(x,z) -sum(dchisq(y, exp(x), exp(z) , log=TRUE )), start=list( x=log(5), z=log(5) ) )
> exp( coef(res) )
         x         z
10.350899  1.591086
>

Chuck

p.s. Using your space key, inserting lines breaks, and indenting your code 
will make it easier to read and to pick out errors.

On Tue, 11 Sep 2007, Terence Broderick wrote:

> Hi, I have written out the log-likelihood function to fit some data I have (called ONES20) to the non-central chi-squared distribution.
>
>  >library(stats4)
>  >ll<-function(lambda,k){x<-ONES20; 25573*0.5*lambda-25573*log(2)-sum(-x/2)-log((x/lambda)^(0.25*k-0.5))-log(besselI(sqrt(lambda*x),0.5*k-1,expon.scaled=FALSE))}
>
>  > est<-mle(minuslog=ll,start=list(lambda=0.05,k=0.006))
>
>  R accepts the function definition without a problem, but gives this error when I ask for the mle of the parameters.
>
>  Error in besselI(x, nu, 1 + as.logical(expon.scaled)) :
>        Non-numeric argument to mathematical function
> In addition: Warning message:
> NaNs produced in: sqrt(x = xx)
>
>  I am also anticipating another problem in that depending on the definition of the noncentral chi-squared distribution used, the parameters I provide the optimiser to start with lambda and k, may not be acceptable as they are doubles as opposed to integers.
>
>  Does anybody have any experience with the fitting of these distributions?
>
>  Best Wishes
>
>  Terence
>
>
> audaces fortuna iuvat
>
> ---------------------------------
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901



More information about the R-help mailing list