Chi-Square Inspection and R language Realization _ card square test and R language implementation

Source: Internet
Author: User
The chi-square test is the deviation between the actual observed value and the theoretical inference value of the statistical sample. The deviation between the actual observation value and the theoretical inference value determines the size of the card square value, the larger the card square value is, the more it does not conform; the smaller the value of the card, the smaller the deviation, the more consistent, if two values are exactly equal, the card square value is 0, Indicates that the theoretical value is in full conformity. Note: The card side test is for the classification variable. (1) put forward the original hypothesis: H0: The distribution function of the total x is f (x). If the overall distribution is discrete, the assumption is H0: The distribution law of the total X is P{x=xi}=pi, i=1,2, ... (2) Dividing the range of total X into K-disjoint a1,a2,a3,...,ak, such as the Desirable a1= (a0,a1],a2= (a1,a2],...,ak= (Ak-1,ak), where A0 desirable-∞,ak desirable +∞, and the division of intervals depending on the specific circumstances, But to make each small interval contains the number of samples is not less than 5, and the interval number k not too big nor too small. (3) The number of the sample values of AI that falls into the first small interval is recorded as FI, which becomes the group frequency (true Value), and the sum of the frequencies of all groups is equal to the F1+F2+...+FK of the sample size n. (4) When the H0 is true, according to the assumption of the overall theoretical distribution, can calculate the value of the total X into the first small section ai probability pi, so, the NPI is falling into the first small interval AI sample value of the theoretical frequency (theoretical value). (5) When the H0 is true, the frequency fi/n of the sample value falling into the first small interval ai and the probability pi should be very close, when the H0 is not true, fi/n and pi differ greatly. Based on this idea, Pearson introduces the following test statistic =k, and obeys the k-1 distribution of the DOF under the condition of 0 hypothesis.


Determine whether there are significant differences among enthusiasts for 5 brands of beer: > X<-c (210, 312, 170, 85, 223)
> Chisq.test (X)--card-side inspection
Chi-squared test for given probabilities
Data:x
x-squared = 136.49, df = 4, P-value < 2.2e-16


The larger the P value, the stronger the evidence that supports the original hypothesis, given the significant level alpha, and the rejection of the original hypothesis when the P value is less than alpha.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.