Chi Square Test on Certain Columns in Excel Import?

I know I can use chisq.test() to sort a table. I found an older topic that states how to do it with a table, but if I'm doing this with imported Excel data, how do I set it up for each column? I don't need each of the columns for Excel (I do need every row).

The function seems simple enough if the table is entered by hand as a matrix, but I'm NOT going to go and re-enter this all by hand.

Can you provide a reproducible example? It might make more sense than the description you provided.

I hope this works here...I can import the data into R Studio but don't know what to do from here.

Screenshots aren't helpful (read the reprex article). I assume that you want to run chi-square tests on various groups of responses?

Can you describe what you want to do better?

I was able to get an answer elsewhere on another forum that was OK with a screenshot, but thanks for the offer for help here!

Turns out I had to create a contingency table first using the column names, then run the script on that. It's too bad R's documentation online isn't very clear about this (though at least it's not as bad as Mathematica's documentation).

1 Like

Can you could provide a link to the answer from the other forum in case it is an issue for someone else?

For a a reprex (see the FAQ the goal is to provide something that can be cut and pasted, which screenshots don't provide.

Assuming the imported object is named my_data run

dput(my_data)

and cut-and paste the results into the question Or you could synthesize data

set.seed(42)
var1 <- sample(1:4,10,replace = TRUE)
var2 <- sample(1:2,10,replace = TRUE)
var3 <- sample(1:2,10,replace = TRUE)
(m <- matrix(c(var1,var2,var3), nrow = 10, ncol = 3))
#>       [,1] [,2] [,3]
#>  [1,]    1    1    1
#>  [2,]    1    2    1
#>  [3,]    1    1    1
#>  [4,]    1    2    1
#>  [5,]    2    1    1
#>  [6,]    4    1    2
#>  [7,]    2    2    1
#>  [8,]    2    2    1
#>  [9,]    1    2    1
#> [10,]    4    2    1

Created on 2023-04-16 with reprex v2.0.2

That's enough to show how it can be one with two different pairs of variables in the same matrix.

Question: assuming a longer matrix m, say 11 numeric variables, are you looking to test just the first five pairs or all 55 possible pairs?

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.