I am trying to perform goodness of fit test using R. I am using this website http://wiener.math.csi.cuny.edu/Statistics/R/simpleR/stat013.html for help. However, I am unable to carry out the test successfully. My code follows. It is taken from the website just mentioned. freq=c(22,21,22,27,22,36) # frequencies obtained after rolling the dice 150 times. prob=c(1,1,1,1,1,1)/6 # specify expected frequency for each category. chisq.test(freq,p=prob) # I do not know what this line means. I just followed instructions on the website. The erorr I receive is "erorr in chisq.test(freq,p=prob)/6 probabilities must sum to 1" I am very new to R, so any help would be appreciated. Faiz. [[alternative HTML version deleted]]
Bernardo Rangel Tura
2010-Feb-14 08:48 UTC
[R] Problem in performing goodness of fit test in R.
On Sun, 2010-02-14 at 12:42 +0500, Faiz Rasool wrote:> I am trying to perform goodness of fit test using R. I am using this website http://wiener.math.csi.cuny.edu/Statistics/R/simpleR/stat013.html for help. However, I am unable to carry out the test successfully. My code follows. It is taken from the website just mentioned. > freq=c(22,21,22,27,22,36) # frequencies obtained after rolling the dice 150 times. > prob=c(1,1,1,1,1,1)/6 # specify expected frequency for each category. > chisq.test(freq,p=prob) # I do not know what this line means. I just followed instructions on the website. > The erorr I receive is "erorr in chisq.test(freq,p=prob)/6 probabilities must sum to 1" > > I am very new to R, so any help would be appreciated. > Faiz.Faiz, Well ... In my computer( Phenom X4 9650, runing Ubuntu 9.10 and R 2.10.1) the script work> freq=c(22,21,22,27,22,36) # frequencies obtained after rolling thedice 150 times.> prob=c(1,1,1,1,1,1)/6 # specify expected frequency for each category. > chisq.test(freq,p=prob) # I do not know what this line meansChi-squared test for given probabilities data: freq X-squared = 6.72, df = 5, p-value = 0.2423 About the third line You must read ?chisq.test for better know the command, but you execute one chi-square test with uniform probability distribution -- Bernardo Rangel Tura, M.D,MPH,Ph.D National Institute of Cardiology Brazil
On 14-Feb-10 07:42:12, Faiz Rasool wrote:> I am trying to perform goodness of fit test using R. I am using this > website > http://wiener.math.csi.cuny.edu/Statistics/R/simpleR/stat013.html > for help. However, I am unable to carry out the test successfully. My > code follows. It is taken from the website just mentioned. >freq=c(22,21,22,27,22,36) # frequencies obtained after # rolling the dice 150 times. prob=c(1,1,1,1,1,1)/6 # specify expected frequency for each category. chisq.test(freq,p=prob) # I do not know what this line means. # I just followed instructions on the website.> > The erorr I receive is "erorr in chisq.test(freq,p=prob)/6 > probabilities must sum to 1" > > I am very new to R, so any help would be appreciated. > Faiz.I suspect that you must have made an error in entering the commands into R. Prime suspect: You did not have 6 1's in p -- for example you may have put prob=c(1,1,1,1,1)/6 (with only five). I copied your code (as trivially reformatted above) straight into R using copy&paste with the mouse, with results: freq=c(22,21,22,27,22,36) # frequencies obtained after # rolling the dice 150 times. prob=c(1,1,1,1,1,1)/6 # specify expected frequency for each category. chisq.test(freq,p=prob) # I do not know what this line means. # Chi-squared test for given probabilities # data: freq # X-squared = 6.72, df = 5, p-value = 0.2423 # I just followed instructions on the website. So it worked as it should work. Therefore something went wrong when you entered the code. Check your input! Hoping this helps, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 14-Feb-10 Time: 09:02:01 ------------------------------ XFMail ------------------------------
Dear Faiz, On Sat, Feb 13, 2010 at 11:42 PM, Faiz Rasool <faiz7r@gmail.com> wrote:> The erorr I receive is "erorr in chisq.test(freq,p=prob)/6 probabilities > must sum to 1"This error message seems a little off. It looks like the entire chi squared test was divided by 6. Notice that the /6 occurs *after* the closing parenthesis for the test. As others have noted, it is probably an input problem, but here is another sample of code you could try. ## all of the data is entered directly into the function. x is the data, p are the probabilities. ## the biggest difference is rather than dividing by 6 to make the probabilities sum to 1, the argument "rescale.p=T" will make sure that they sum to 1 chisq.test(x=c(22,21,22,27,22,36), p=c(1,1,1,1,1,1), rescale.p=T) Chi-squared test for given probabilities data: c(22, 21, 22, 27, 22, 36) X-squared = 6.72, df = 5, p-value = 0.2423> > I am very new to R, so any help would be appreciated. > Faiz. >Best of luck to you! I have found the list to be very helpful and informative. Joshua -- Joshua Wiley Senior in Psychology University of California, Riverside http://www.joshuawiley.com/ [[alternative HTML version deleted]]
Good that you got it to work somehow! Faiz: can you report the result, exactly as returned by R, of sum(c(1,1,1,1,1,1)/6) - 1 ?? On my Linux with R version 2.10.0 (2009-10-26) this gives 0. (And, by the way, did you really mean to say you were using "R 2.1.01"? Was this a typing error for "R 2.10.1"?) Ted. On 14-Feb-10 09:26:00, Faiz Rasool wrote:> Hi all, > > Following Denis's code, I am able to carry out goodness of fit test. > > However the responses I have received, indicate that the code I > mentioned in > a prior email was not incorrect. inclusion of rep(1,6)/6 made a > difference > for me. I am using windows xp and R 2.1.01. Does difference of > operating > system makes a difference? As without rep(1,6)/6 R would not carry out > chisq.test on my computer. The code I got it to work follows. > >> freq=c(22,21,22,27,22,36)#frequencies obtained after rolling the dice >> 150 >> times. >> prob=rep(1,6)/6#change made after Dennis's suggestion. >> chisq.test(freq,p=prob)#no error message received now. > > Chi-squared test for given probabilities > > data: freq > X-squared = 6.72, df = 5, p-value = 0.2423 > > thanks everyone, > Faiz. > > ----- Original Message ----- > From: "Ted Harding" <Ted.Harding at manchester.ac.uk> > To: <R-help at r-project.org> > Cc: "Faiz Rasool" <faiz7r at gmail.com> > Sent: Sunday, February 14, 2010 2:02 PM > Subject: RE: [R] Problem in performing goodness of fit test in R. > > >> On 14-Feb-10 07:42:12, Faiz Rasool wrote: >>> I am trying to perform goodness of fit test using R. I am using this >>> website >>> http://wiener.math.csi.cuny.edu/Statistics/R/simpleR/stat013.html >>> for help. However, I am unable to carry out the test successfully. My >>> code follows. It is taken from the website just mentioned. >>> >> freq=c(22,21,22,27,22,36) # frequencies obtained after >> # rolling the dice 150 times. >> prob=c(1,1,1,1,1,1)/6 # specify expected frequency for each category. >> chisq.test(freq,p=prob) # I do not know what this line means. >> # I just followed instructions on the >> # website. >>> >>> The erorr I receive is "erorr in chisq.test(freq,p=prob)/6 >>> probabilities must sum to 1" >>> >>> I am very new to R, so any help would be appreciated. >>> Faiz. >> >> I suspect that you must have made an error in entering the commands >> into R. Prime suspect: You did not have 6 1's in p -- for example >> you may have put >> >> prob=c(1,1,1,1,1)/6 >> >> (with only five). I copied your code (as trivially reformatted above) >> straight into R using copy&paste with the mouse, with results: >> >> freq=c(22,21,22,27,22,36) # frequencies obtained after >> # rolling the dice 150 times. >> prob=c(1,1,1,1,1,1)/6 # specify expected frequency for each category. >> chisq.test(freq,p=prob) # I do not know what this line means. >> >> # Chi-squared test for given probabilities >> # data: freq >> # X-squared = 6.72, df = 5, p-value = 0.2423 >> # I just followed instructions on the >> # website. >> >> So it worked as it should work. Therefore something went wrong >> when you entered the code. Check your input! >> >> Hoping this helps, >> Ted. >> >> -------------------------------------------------------------------- >> E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> >> Fax-to-email: +44 (0)870 094 0861 >> Date: 14-Feb-10 Time: 09:02:01 >> ------------------------------ XFMail ------------------------------ >-------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 14-Feb-10 Time: 10:53:34 ------------------------------ XFMail ------------------------------
Possibly Parallel Threads
- Two questions, first about contingency tables, and second about table () and data.frame (), from a visually impaired user.
- How to Save the residuals of an LM object greater or less than a certin value to an R object?
- couple of how-to-do it in R questions regarding corelations and mean and SD of likert items
- questions about performing Robust multiple regression using bootstrap
- Reading results of commands in Microsoft Word typed in the terminal window, A question from a Blind R user.