R21: Goodness of Fit Tests on Contingency Tables Do not round at all. We'll use R to perform goodness of fit tests on th

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

R21: Goodness of Fit Tests on Contingency Tables Do not round at all. We'll use R to perform goodness of fit tests on th

Post by answerhappygod »

R21 Goodness Of Fit Tests On Contingency Tables Do Not Round At All We Ll Use R To Perform Goodness Of Fit Tests On Th 1
R21 Goodness Of Fit Tests On Contingency Tables Do Not Round At All We Ll Use R To Perform Goodness Of Fit Tests On Th 1 (268.49 KiB) Viewed 31 times
R21: Goodness of Fit Tests on Contingency Tables Do not round at all. We'll use R to perform goodness of fit tests on the contingency tables we looked at in Assignment 20, and on the video about the Titanic. 1. First we'll look at the TB deaths table from A20. To enter the data we'll use the following command: TB<-matrix(c(8365,131,513,155), nrow=2,ncol=2,byrow=TRUE) Notice when we input large numbers, such as 8365, we do not use any commas inside the number. If we had typed 8,365 then would have interpreted that as two different numbers. Then we'll name the rows and columns with this command: dimnames(TB)<-list(c("white", "non-white"),c("NYC","Richmond")) Now type TB to see if you get the same table. Notice the totals do not appear. The totals will get computed in R when they are needed, but we don't need to show them (it's possible to format tables with the totals showing, but we won't do that here). 2. Now to do the goodness of fit test, simply type: chisq.test(TB) What test statistic and p-value do you get? Do the observed data fit the expected? That is, were "whites" and "non-whites” distributed proportionally in the deaths due to TB in these two cities? 3. Now modify the commands we used above to create a new matrix, called 'Total Pop' for the other contingency table in A20. Once you've created the table, do a goodness of fit test. What test statistic and p-value do you get? Do the observed data fit the expected? That is, were "whites" and "non-whites" distributed proportionally in the total population in these two cities? 4. Finally, we'll use R to do a goodness of fit test on the Titanic data we saw in a video. We had the following table: Observed Crew First Second Third Totals Survived 212 202 118 178 710 Died 673 123 167 528 1491 Totals 885 325 285 706 2201 You may want to try entering the data yourself into R. Since this is larger than a 2 by 2 table, there are some differences to what we've done above. So, I'll also give you the commands here: titanic<-matrix(c(212,202,118,178,673,123,167,528),nrow=2,ncol=4, byrow=TRUE) dimnames(titanic)<-list(c("Survived","Died”),c("Crew", "First", "Second”, “Third")) Notice that I named the data 'titanic', and I chose to not capitalize it. That's because there's a preloaded data set in R called 'Titanic'. It has a different structure for the data than the one I'm choosing to use, and also has slight different numbers (there were discrepancies in the passenger list that leads to some uncertainty in the data). For our work, I want you to use the numbers in the table above, which matches the video. Now perform the goodness of fit test. What test statistic do you get? What p-value do you get? Do the observed data fit the expected? That is, was chance of survival distributed proportionally across Titanic ticket classes? In the video, we got a test statistic of 187. The difference is due to the fact that in video when we created the table of expected values, we rounded to the nearest integer. But when R did the calculation, it did not round the expected values, but kept their decimal parts.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply