C Program For Chi-Square Test | C Programming


Chi-Square Test

        Formalizes this notion of distribution fit
       Oi represents the number of observed data values in the i-th interval.
       pi is the probability of a data value falling in the i-th interval under the hypothesized distribution.
       So we would expect to observe Ei = npi, if we have n observations

C Program For Chi-Square Test
C Program For Chi-Square Test

So the chi-squared statistic is

  
C Program For Chi-Square Test

        So the hypotheses are
       H0: the random variable, X, conforms to the distributional assumption with parameters given by the parameter estimates.
       H1: the random variable does not conform.


C Program For Chi-Square Test

#include<stdio.h>

int main()

{

    int n,i,e,calc=0,z=16.9;

    printf("Total number : ");

    scanf("%d",&n);

    int arr[n],o[10]={0,0,0,0,0,0,0,0,0,0},oo[10],ooo[10];

    printf("Enter %d number : ",n);

    for(i=0;i<n;i++)

    {

        scanf("%d",&arr[i]);

    }

    for(i=0;i<n;i++)

    {

        if(arr[i]<10)

            o[0]++;

        else if(arr[i]<20 && arr[i]>=10)

            o[1]++;

        else if(arr[i]<30 && arr[i]>=20)

            o[2]++;

        else if(arr[i]<40 && arr[i]>=30)

            o[3]++;

        else if(arr[i]<50 && arr[i]>=40)

            o[4]++;

        else if(arr[i]<60 && arr[i]>=50)

            o[5]++;

        else if(arr[i]<70 && arr[i]>=60)

            o[6]++;

        else if(arr[i]<80 && arr[i]>=70)

            o[7]++;

        else if(arr[i]<90 && arr[i]>=80)

            o[8]++;

        else

            o[9]++;

    }

    e=n/10;

    for(i=0;i<10;i++)

    {

        oo[i]=(o[i]-e)*(o[i]-e);

        ooo[i]=oo[i]/e;

        calc=calc+ooo[i];

    }

    if(calc<=z)

    printf("Null hypo accepted. The value are uniformly distributed.");

    else

    printf("Alt hypo accepted. The value are not uniformly distributed.");

    return 0;

}


Comments

Popular posts from this blog

C Program for SCAN Disk Scheduling Algorithm | C Programming

C program to Find Cartesian Product of Two Sets | C programming

C Program To Check The String Is Valid Identifier Or Not | C Programming