Dear All, I run the goodness of fit test using goodfit() in vcd package. The result is as follow: Goodness-of-fit test for poisson distribution X^2 df P(> X^2) Pearson 1.053348 2 0.5905661 Warning message: In summary.goodfit(gf) : Chi-squared approximation may be incorrect I want to save the the test statistics(X^2), df, and p-value. How can I save the result. Actually, I want to make a table. In addition, there is warning message "In summary.goodfit(gf) : Chi-squared approximation may be incorrect". How can I interpret this result. Have a nice day. -- View this message in context: http://n4.nabble.com/How-can-I-save-the-result-for-goodness-of-fit-test-tp1595429p1595429.html Sent from the R help mailing list archive at Nabble.com.
Hi pinusan, If it is possible, please add the code you used and output so to help people here help you. In general, take the object you got, put it inside "str" and see where you statistic is (but for us to write the code, it would help if you where to add it to your massage) Best, Tal ----------------Contact Details:------------------------------------------------------- Contact me: Tal.Galili@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- On Tue, Mar 16, 2010 at 9:31 PM, pinusan <anhong@msu.edu> wrote:> > Dear All, > I run the goodness of fit test using goodfit() in vcd package. > The result is as follow: > > Goodness-of-fit test for poisson distribution > > X^2 df P(> X^2) > Pearson 1.053348 2 0.5905661 > Warning message: > In summary.goodfit(gf) : Chi-squared approximation may be incorrect > > I want to save the the test statistics(X^2), df, and p-value. How can I > save > the result. Actually, I want to make a table. > > In addition, there is warning message "In summary.goodfit(gf) : Chi-squared > approximation may be incorrect". > How can I interpret this result. > > Have a nice day. > > -- > View this message in context: > http://n4.nabble.com/How-can-I-save-the-result-for-goodness-of-fit-test-tp1595429p1595429.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Michael Friendly
2010-Mar-17 13:22 UTC
[R] How can I save the result for goodness of fit test
pinusan wrote:> Dear All, > I run the goodness of fit test using goodfit() in vcd package. > The result is as follow: > > Goodness-of-fit test for poisson distribution > > X^2 df P(> X^2) > Pearson 1.053348 2 0.5905661 > Warning message: > In summary.goodfit(gf) : Chi-squared approximation may be incorrect > > I want to save the the test statistics(X^2), df, and p-value. How can I save > the result. Actually, I want to make a table.The usual general answer to this question is to read the documentation, and look for the Value section. ?goodfit gives Value A list of class "goodfit" with elements: observed observed frequencies. count corresponding counts. fitted expected frequencies (fitted by ML). type a character string indicating the distribution fitted. method a character string indicating the fitting method (can be either "ML", "MinChisq" or "fixed" if the parameters were specified). df degrees of freedom. par a named list of the (estimated) distribution parameters. So, the quantities you want are not returned in the resulting object. But, they *are* returned from the summary method that you used to print the result. [That isn't documented, so perhaps that could be added.] So, the 2nd general answer to your question is to use str() on the result of the summary() function. > ## Simulated data examples: > dummy <- rnbinom(200, size = 1.5, prob = 0.8) > gf <- goodfit(dummy, type = "nbinomial", method = "MinChisq") > summary(gf) Goodness-of-fit test for nbinomial distribution X^2 df P(> X^2) Pearson 0.5865029 1 0.4437746 Warning message: In summary.goodfit(gf) : Chi-squared approximation may be incorrect > result <- summary(gf) Goodness-of-fit test for nbinomial distribution X^2 df P(> X^2) Pearson 0.5865029 1 0.4437746 Warning message: In summary.goodfit(gf) : Chi-squared approximation may be incorrect > str(result) num [1, 1:3] 0.587 1 0.444 - attr(*, "dimnames")=List of 2 ..$ : chr "Pearson" ..$ : chr [1:3] "X^2" "df" "P(> X^2)" > > result X^2 df P(> X^2) Pearson 0.5865029 1 0.4437746 > So, there you go!> In addition, there is warning message "In summary.goodfit(gf) : Chi-squared > approximation may be incorrect". > How can I interpret this result. >Read the Details section> Have a nice day. >-- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Street http://www.math.yorku.ca/SCS/friendly.html Toronto, ONT M3J 1P3 CANADA