From: Lee Sander on
Hi,
Is there a statistical test available in matlab that will tell me
if frequency of 2 elements in my binary vector do not support equal
distribution.
This is simply a chi-sequare test with expected frequency of 0.5 and
0.5--but
I am not sure how to do this in matlab.
For example,
I have a vector of length 10 containing 0's and 1's (their order does
not matter).
I would like to get a p-value for the null that each of these come
from a population
with 0.5 frequency.

many thanks
Lee
From: dpb on
Lee Sander wrote:
> Hi,
> Is there a statistical test available in matlab that will tell me
> if frequency of 2 elements in my binary vector do not support equal
> distribution.
> This is simply a chi-sequare test with expected frequency of 0.5 and
> 0.5--but
> I am not sure how to do this in matlab.
> For example,
> I have a vector of length 10 containing 0's and 1's (their order does
> not matter).
> I would like to get a p-value for the null that each of these come
> from a population
> with 0.5 frequency.
....

Sample size of 10 is likely to not have much power of detection but that
aside...

Do you have the Statistics Toolbox? If so, it has chi-square built-in.
If not, you'll have to compute the test statistic the old fashioned way.

--
From: Lee Sander on
Actually I did do the chi square test but I got a NaN p-vals

In below assume I have 5 of '0's and 20 or '1', in this case the null
should be rejected

>> bins=[0 1]; obsCounts=[5 20]; expectedCounts=repmat(sum(obsCounts)/length(obsCounts),1,length(obsCounts));
>> [h,p,st]=chi2gof(bins,'ctrs',bins,'frequency',obsCounts,'expected',expectedCounts','nparams',1)
h =
0
p =
NaN
st =
chi2stat: 9
df: 0
edges: [-0.5000 0.5000 1.5000]
O: [5 20]
E: [12.5000 12.5000]


can you tell me what I am doing wrong?
thanks

>
> Sample size of 10 is likely to not have much power of detection but that
> aside...
>
> Do you have the Statistics Toolbox?  If so, it has chi-square built-in.
> If not, you'll have to compute the test statistic the old fashioned way.
>
> --

From: dpb on
Lee Sander wrote:
> Actually I did do the chi square test but I got a NaN p-vals
>
> In below assume I have 5 of '0's and 20 or '1', in this case the null
> should be rejected
>
>>> bins=[0 1]; obsCounts=[5 20]; expectedCounts=repmat(sum(obsCounts)/length(obsCounts),1,length(obsCounts));
>>> [h,p,st]=chi2gof(bins,'ctrs',bins,'frequency',obsCounts,'expected',expectedCounts','nparams',1)
> h =
> 0
> p =
> NaN
> st =
> chi2stat: 9
> df: 0
> edges: [-0.5000 0.5000 1.5000]
> O: [5 20]
> E: [12.5000 12.5000]
>
>
> can you tell me what I am doing wrong?
....

You have _0_ DOF...

I'd approach it from computing confidence interval on the estimate of
x/n and see if upper bound of X% confidence crossed the 0.5 boundary or
not as one way.

Don't recall if there's another specific test for binomial
acceptance/rejection or not otomh...it's been too long since I've been
actively engaged, sorry...

--
From: Peter Perkins on
On 7/28/2010 8:47 AM, Lee Sander wrote:
> I would like to get a p-value for the null that each of these come
> from a population with 0.5 frequency.

Lee, I'm not sure what your populations or your ones/zeros represent.
You might use CHI2GOF and treat this as a 2x2 table. Or you could use
the confidence interval from BINOFIT. Or you could use CHI2GOF on the
vectors separately.

Hope this helps.