r - Matlab test of independence -
For 1,000,000 comments, I had seen a discrete event, X, 3 times for the control group and 10 times for the test group.
I have to prepare a Chihu Square Test of Independence. How would you do this in R:
m < - rbind (c (3, 1000000-3), c (10, 1000000-10)) # [, 1] [, 2] # [1,] 99 99 7 # [2,] 10 99 99 9 chisq .test (m)
R function returns CHI-squared = 2.7692, df = 1, p-value = 0.0961.
Should I use the Matlab function to do this or should I?
This is my own implementation that I use:
Function [hNull pValue X2] = Chasquestest (O, Alpha)% # Christmas Pearson's Chi-Square Examination Freedom #% # @ Ultimate O Two Similar Events (Attributes)% # # Importance Level% for the Ultimate Alpha Testing # @ Circulation Hunnel H = 1: Null hypothesis approved (independent)% # hNull = 0: null hypothesis rejected (dependent)% # @ Return Pivotal Examination P-value (% #) Problems of survival) frequencies observed under HN ull)% # @ Returns X2 Square Value for% #% #: observed frequency% #E: expected frequency% #DOOF: degree of independence [RC] = Size (O); Dof = (r-1) * (C-1); % # E = (calculation (a = ai) * calculation (b = bi)) / n = yoga (o, 2) * sum (o, 1) / zodiac (o (:)); % # [Sum_r [sum_c ((o_ij-e_ij) ^ 2 / e_ij)]] x2 = sum (zodiac (o-e). ^ 2 ./i)); % # P-value is required to reject hnull at the importance level with dof pValue = 1 - chi2cdf (x2, dof); HNull = (PLALA> alpha); The% # x2 value is required to reject hnull at the importance level with dof% # x2table = chi2inv (1-alpha, doof); % # HNull = (X2table & gt; X2);
For example and example:
t = [3 99 99 7 7; 10 99 99 9] [HNL PVL X2] = Chasquestest (T, 0.05) hNull = 1 pVal = 0.052203 X2 = 3.7693
Note that the results are different from you because Chisq.test
? According to Chisq.test
one corrects an improvement: A logical indicates that continuous improvement is applied when calculating test stats for 2x2 Or not tables: one half is subtracted from all. O - E | Difference. Alternatively, if you have actual comments of two incidents in question, you can use that function which calculates the contingency table and chi 2 and p. -Remains the following measures:
X = Randie ([1 2], [1000 1]); Y = Randie ([1 2], [1000 1]); [Tx2 pVal] = crosstab (x, y) t = 22 9 247 257 267 x 2 = 0.087581 pyil = 0.76728
R will be equal to:
< Note: Statistics toolbox is required for both the above (MATLAB) approach
Comments
Post a Comment