I just started coding in R and I have a question about applying Chi-square test to a dataset by 2 columns at a time.
I would like to do a paired analysis (Tumor and Normal sample come from the same patient, so Primary Tumor 1 and Normal Tissue 1 comes from the same patient). I would like to see differences in the distribution between tumour and normal sample from the same patient and apply to all 50 patients.
I tried Chi-square goodness of fit previously, with expected probability I calculated from taking average from all normal samples.
The code I used is:
apply(mydata, 2, chisq.test, p=myprobability)
This time, I want to conduct Pearson's Chi-square test (not goodness of fit) to tumour and its matched normal tissue.
So, I would like to run Chi-square test by two columns: Primary Tumor 1 + Normal 1 ... Then next, Primary Tumor 2 + Normal 2
and get a table of Chi-square statistics and p-values. (In this case, I would have to use adjusted p-values right? because I ran it on 50 sets of samples?)
As a reproductible example...
mydata <-
structure(list(Tumor1 = c(17, 28, 80, 63, 20,
10), Normal1 = c(18, 27, 89, 62, 24,
11), Tumor2 = c(25, 40, 80, 65, 23,
11), Normal2 = c(27, 29, 100, 72, 34,
6)), class = "data.frame",
row.names = c("trim3", "trim2", "trim1", "add1", "add2",
"add3"))
head(mydata)
Tumor1 Normal1 Tumor2 Normal2
trim3 17 18 25 27
trim2 28 27 40 29
trim1 80 89 80 100
add1 63 62 65 72
add2 20 24 23 34
add3 10 11 11 6
I tried to use apply function like I did for goodness of fit, but I could not get it to work.
Thank you
dput(head(data.cstest))
? This will print out a copy-and-pasteable version of your dataset. An image is difficult to work with for potential answerers. – thelatemail