Hi,
I have a number of genes (columns) for which I want to examine pairwise
associations of genotypes (each row is an individual)...For example (see
data below), I would like to compare M1 to M2, M2 to M3, and M1 to M3 (i.e.
does ac from M1 tend to be found with bc from M2 more often than expected.)
Down stream I will be performing chi square tests for each pair.
But I am looking for a way to set all pairs of genes (order doesn't matter,
so with 3 genes, there are 3 comparisons, 4 genes=6 comparisons) in a new
data.frame or matrix so that I can then test each pair with a chi-square
test in a loop.
Below is some sample data of the form I will be using.
> lets<-c("ab","ac","bc","bd")
> epi<-data.frame(cbind("M1"= c(sample(lets,10,
replace=TRUE)),"M2"=c(sample(lets,10,replace=TRUE)), "M3"=c(sample(lets,10,
replace=TRUE))))
> print(epi)
M1 M2 M3
1 ac bc bd
2 ac ac bd
3 bd bd bd
4 ab ac bd
5 ac bc bd
6 bd bd bc
7 ab ac ab
8 bc bd ab
9 bd ab ac
10 bc bc bd
I tried a for loop to set each column against the others, but get errors for
undefined columns selected:
for(i in 1:3) {
k=i+1
j=k
for(j in k:4){
epi3=cbind("A"=epi[,i],"B"=epi[,j])
print(epi3)
}
}
Im sure this is a simple fix...any ideas?
Louis
[[alternative HTML version deleted]]