dhaval2025
dhaval2025

Reputation: 317

chisq.test in R

test()` in Rand it gives me back the x-squared and the p-value.

Now I want to take the p-value and according to the reading proceed with my program. How can I extract the p-value from the result of the output of chisq.test()?

Upvotes: 2

Views: 1684

Answers (2)

Christian Bøhlke
Christian Bøhlke

Reputation: 779

Performing a \Chi^2 test on the vectors x and y and storing it in 'results'

results<-chisq.test(x,y)

you can then retrieve the estimated parameters as

results[1], results[3], ... or results$statistic, results$p.value, ... 

where the last part is of course the most self-describing way to do it.

Remember to cast the results to numeric values, that is

as.numeric(results[1])

HTH,

Christian

Upvotes: 3

James
James

Reputation: 66874

chisq.test(x)$p.value

You can see what an object holds using str:

str(chisq.test(x))

Upvotes: 5

Related Questions