@@ -97,30 +97,54 @@ setMethod(f="method.apply",
97
97
u = unique(D $ sample_meta [[M $ paired_factor ]])
98
98
out = character (0 ) # list of sample_id to remove
99
99
for (k in u ) {
100
- n = sum(D $ sample_meta [[M $ paired_factor ]]== k )
100
+ n = sum(D $ sample_meta [[M $ paired_factor ]]== k ) # number of samples (could be same class)
101
101
if (n < 2 ) {
102
102
out = c(out ,k )
103
103
}
104
+ # if we have more than 2 then we need an even number.
105
+ if (n %% 2 != 0 ) {
106
+ out = c(out ,k )
107
+ }
108
+ # check we have enough groups (must be two for ttest)
109
+ ng = length(unique(D $ sample_meta [[M $ factor_names ]][D $ sample_meta [[M $ paired_factor ]]== k ]))
110
+ if (ng != 2 ) {
111
+ out = c(out ,k )
112
+ }
104
113
105
114
}
106
115
X = X [! (D $ sample_meta [[M $ paired_factor ]] %in% out ),]
107
116
y = y [! (D $ sample_meta [[M $ paired_factor ]] %in% out )]
108
117
109
- # sort the data by sample id so that theyre in the right order for paired ttest
110
- X = apply(X ,2 ,function (x ) {
111
- a = x [y == L [1 ]]
112
- b = x [y == L [2 ]]
113
- ay = y [y == L [1 ]]
114
- by = y [y == L [2 ]]
115
- a = a [order(ay )]
116
- b = b [order(by )]
117
- return (c(a ,b ))
118
- })
119
- # also make sure the meta data is in the right order
120
- y = y [order(D $ sample_meta [[M $ paired_factor ]])]
118
+ # sort the data by sample id so that theyre in the right order for paired ttest
119
+ X = apply(X ,2 ,function (x ) {
120
+ a = x [y == L [1 ]]
121
+ b = x [y == L [2 ]]
122
+ ay = y [y == L [1 ]]
123
+ by = y [y == L [2 ]]
124
+ a = a [order(ay )]
125
+ b = b [order(by )]
126
+ return (c(a ,b ))
127
+ })
128
+ # also make sure the meta data is in the right order
129
+ y = y [order(D $ sample_meta [[M $ paired_factor ]])]
130
+
131
+ # put back into dataset object
132
+ D $ data = as.data.frame(X )
133
+ D $ sample_meta [[M $ paired_factor ]]= y
121
134
}
122
135
123
- output = apply(X ,2 ,function (x ) {a = unlist(t.test(x [y == L [1 ]],x [y == L [2 ]],paired = M $ paired )[c(" statistic" ," p.value" ," parameter" ,' conf.int' ,' estimate' )])})
136
+ # check number per class
137
+ # if less then 2 then remove
138
+ FF = filter_na_count(threshold = 2 ,factor_name = M $ factor_names )
139
+ FF = method.apply(FF ,D )
140
+ D = predicted(FF )
141
+ X = D $ data
142
+ y = D $ sample_meta [[M $ paired_factor ]]
143
+ print(FF $ count )
144
+
145
+ output = apply(X ,2 ,function (x ) {
146
+ a = unlist(t.test(x [y == L [1 ]],x [y == L [2 ]],paired = M $ paired )[c(" statistic" ," p.value" ," parameter" ,' conf.int' ,' estimate' )])
147
+ })
124
148
output = as.data.frame(t(output ),stringsAsFactors = FALSE )
125
149
output $ p.value = p.adjust(output $ p.value ,method = param.value(M ,' mtc' ))
126
150
output.value(M ,' t_statistic' )= output $ statistic.t
0 commit comments