-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterCategoryVar.R
More file actions
63 lines (45 loc) · 1.66 KB
/
InterCategoryVar.R
File metadata and controls
63 lines (45 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
##InterCategoryVar.R ##
#' @export
#'
##############################################
## Author Information ##
# * Author: E.Frolli
# * Orginization: Univeristy of Texas Marine Science Institute
# * Contact: frolli.erin@utexas.edu
# * Date: 26 Jun 2017
##############################################
## The Code ##
InterCategoryVar <-function(qPCRData,Category) {
# Matrix vals
n = nrow(qPCRData) # Number of rows
L = ncol(qPCRData) # Number of col
GeneSymbol = colnames(qPCRData) # Gene Symbols
# Category info
CategoryNum = as.numeric(summary.factor(Category)) # total number of samples for each Category
CategoryName = levels(Category) # unique Category names
CategoryL = length(CategoryNum) # total number of Categorys for dataset
# Gene Averages / Category/ sample
Zig. = matrix(0,CategoryL,L)
for(i in 1:CategoryL){
Zig.[i,] = apply(qPCRData[Category==CategoryName[i],],2,mean) # average of each gene by Category
}
# Sample Average of Genes
Zj.=apply(Zig.,2,mean)
# Category Average of Genes
Z.g=apply(Zig.,1,mean)
# Overall Average of Genes
Z..=mean(Zig.)
# Calculate difference dig = Zig. - Zj. - Z.g + Z..
dig = matrix(0,CategoryL,L)
for(i in 1:L){
for (ii in 1:CategoryL){
dig[ii,i] = Zig.[ii,i]- Zj.[i] - Z.g[ii] + Z.. # Equation on page 4 in sumplemental material for Andersen et al.
}
}
colnames(dig) = GeneSymbol
rownames(dig) = CategoryName
# Difference between the Categorys per gene: di = 2*max(abs(dig))
di = 2*apply(abs(dig),2,max)
# return these values.
return(list("dig"=dig,"di"=di))
}