Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to calculate chi-square statistic for a distribution

24 views
Skip to first unread message

Silas Adiko

unread,
May 21, 2013, 2:45:10 PM5/21/13
to
Dear Support,

I am fitting a distribution to data and trying to perform chi-square goodness-of-fit test.

I have calculated the likelihood values and wanted to perform goodness-of-fit test

However, having read through the Help menus, I tried to run the script below but am getting error:

x=claims; [h,p,stats] = chi2gof(X,'cdf','weibull',nparams,2)

where claims is 1xn vector

I do not know where I have gone wrong and would appreciate anyone's assistance to resolve this.

Also, I needed the script to calculate chi-square test statistic for Negative Binomial distribution.

Much thanks in advance

Steven_Lord

unread,
May 21, 2013, 5:43:37 PM5/21/13
to


"Silas Adiko" <s_a...@yahoo.co.uk> wrote in message
news:kngfbm$qb4$1...@newscl01ah.mathworks.com...
> Dear Support,

This is not the official Technical Support group. If you're looking for
official support, see the instructions in my signature.

> I am fitting a distribution to data and trying to perform chi-square
> goodness-of-fit test.
>
> I have calculated the likelihood values and wanted to perform
> goodness-of-fit test
>
> However, having read through the Help menus, I tried to run the script
> below but am getting error:
>
> x=claims; [h,p,stats] = chi2gof(X,'cdf','weibull',nparams,2)
>
> where claims is 1xn vector
>
> I do not know where I have gone wrong and would appreciate anyone's
> assistance to resolve this.

What is the exact text of the error you receive when you executed that code?

My guess is that it is "Undefined function or variable 'X'." Remember that
in MATLAB, the variable x is NOT the same as the variable X.

If that is not the error you received, post the full text of the message to
the newsgroup (please do NOT email it to me directly) and someone may be
able to offer a suggestion.

*snip the other question; I don't know the answer off the top of my head*

--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tom Lane

unread,
May 21, 2013, 6:13:04 PM5/21/13
to
>> x=claims; [h,p,stats] = chi2gof(X,'cdf','weibull',nparams,2)
...
> My guess is that it is "Undefined function or variable 'X'." Remember that
> in MATLAB, the variable x is NOT the same as the variable X.

Two other things likely have caused you problems:

1. Use @wblcdf or 'wblcdf' rather than 'weibull'
2. Use 'nparams' rather than nparams

-- Tom

Silas Adiko

unread,
May 22, 2013, 7:03:09 PM5/22/13
to
"Tom Lane" <tl...@mathworks.com> wrote in message <kngrhg$6am$1...@newscl01ah.mathworks.com>...
Dear Steve and Tom.

I have carried out your suggestions but none of them worked.

Below are the scripts and the full error texts:

X=claims;
[h,p,stats] = chi2gof(X,cdf,'weibull',nparams,2)

??? Error using ==> cdf at 49
Not enough input arguments

>> [h,p,stats] = chi2gof(X,cdf,'weibull','nparams',2)
??? Error using ==> cdf at 49
Not enough input arguments

>> [h,p,stats] = chi2gof(X,@wblcdf,'weibull','nparams',2)
??? Error using ==> chi2gof at 137
Parameter name must be text.

>> [h,p,stats] = chi2gof(X,'@wblcdf','weibull','nparams',2)
??? Error using ==> chi2gof at 137
Invalid parameter name: @wblcdf.

>> [h,p,stats] = chi2gof(X,cdf,'@wblcdf','nparams',2)
??? Error using ==> cdf at 49
Not enough input arguments

>> [h,p,stats] = chi2gof(X,cdf,'wblcdf','nparams',2)
??? Error using ==> cdf at 49
Not enough input arguments

2. Also, I needed the script to calculate chi-square statistic for Negative Binomial Distribution.

I appreciate your assistance very much.

Silas

Silas Adiko

unread,
May 22, 2013, 8:35:09 PM5/22/13
to
"Silas Adiko" wrote in message <knjird$o58$1...@newscl01ah.mathworks.com>...
> "Tom Lane" <tl...@mathworks.com> wrote in message <kngrhg$6am$1...@newscl01ah.mathworks.com>...
> > >> x=claims; [h,p,stats] = chi2gof(X,'cdf','weibull',nparams,2)
> > ...
> > > My guess is that it is "Undefined function or variable 'X'." Remember that
> > > in MATLAB, the variable x is NOT the same as the variable X.
> >
> > Two other things likely have caused you problems:
> >
> > 1. Use @wblcdf or 'wblcdf' rather than 'weibull'
> > 2. Use 'nparams' rather than nparams
> >
> > -- Tom
> Hello Steve & Tom,

I am happy to inform you that I found a solution while still searching on google . The link is http://ocw.mit.edu/courses/mathematics/18-443-statistics-for-applications-fall-2006/lecture-notes/lecture11.pdf.

Thank you all very much.

Silas
0 new messages