Dear all, I would like to compute hundreds of chisq.test ?s, and for each test output I would like to extract only the p-values. So my question is: how can I make this without making it manually? Example: # Test n?1 > chisq.test(c(220,240)) Chi-squared test for given probabilities data: c(220, 240) X-squared = 0.8696, df = 1, p-value = 0.3511 # Test n?2 > chisq.test(c(301,258)) Chi-squared test for given probabilities data: c(301, 258) X-squared = 3.3077, df = 1, p-value = 0.06896 ... # Test n?200> chisq.test(c(242,281))Chi-squared test for given probabilities data: c(242, 281) X-squared = 2.9082, df = 1, p-value = 0.08813 Desired output: Test 1 2 ... 200 p-value 0.3511 0.06896 ... 0.08813 Thanks in advance. Best regards, Jo?o Fadista
On 11-Oct-07 22:11:46, Jo?o Fadista wrote:> Dear all, > > I would like to compute hundreds of chisq.test ?s, and for each test > output I would like to extract only the p-values. So my question is: > how can I make this without making it manually??chisq.test (under "Value") tells you that one component of the output is p.value so: for(i in (1:100000)){ x <- matrix(sample((1:100),4),nrow=2) print(chisq.test(x)$p.value) } [1] 0.0009193404 [1] 8.822807e-07 [1] 0.005263787 [1] 0.3424672 [1] 5.72495e-07 [1] 5.29765e-05 [1] 0.6812334 [1] 0.0514063 [1] 8.361445e-13 [1] 0.02701781 [remaining output snipped :)] Best wishes, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 11-Oct-07 Time: 23:41:44 ------------------------------ XFMail ------------------------------