@@ -101,6 +101,7 @@ setMethod(f="model.apply",
101
101
stop(' must have exactly two levels for this implmentation of t-statistic' )
102
102
}
103
103
104
+ estimate_name = ' estimate'
104
105
if (M $ paired ){
105
106
# check that we have a pair for each sample,
106
107
# if not then remove
@@ -150,19 +151,44 @@ setMethod(f="model.apply",
150
151
D = predicted(FF )
151
152
152
153
# check equal numbers per class. if not equal then exclude.
153
- out = FF $ count [,1 ]!= FF $ count [,2 ]
154
- D $ data = D $ data [,! out ]
154
+ IN = rownames(FF $ count )[(FF $ count [,1 ]== FF $ count [,2 ]) & (FF $ count [,1 ]> 2 ) & (FF $ count [,2 ]> 2 )]
155
+ D $ data = D $ data [,IN ]
156
+ D $ variable_meta = D $ variable_meta [IN ,]
157
+
158
+ estimate_name = ' estimate.mean of the differences'
155
159
}
156
160
157
161
158
162
159
163
X = D $ data
160
164
y = D $ sample_meta [[M $ factor_names ]]
161
165
162
- output = apply(X ,2 ,function (x ) {
163
- a = unlist(t.test(x [y == L [1 ]],x [y == L [2 ]],paired = M $ paired )[c(" statistic" ," p.value" ," parameter" ,' conf.int' ,' estimate' )])
166
+ output = lapply(X ,function (x ) {
167
+ a = tryCatch({
168
+ g = unlist(t.test(x [y == L [1 ]],x [y == L [2 ]],paired = M $ paired )[c(" statistic" ," p.value" ," parameter" ,' conf.int' ,' estimate' )])
169
+ return (g )
170
+ },warning = function (w ) {
171
+ g = NA
172
+ return (g )
173
+ }, error = function (e ) {
174
+ g = NA
175
+ return (g )
176
+ }
177
+ )
164
178
})
165
179
180
+ # replace na with vector of na the correct length/names
181
+ na = which(is.na(output ))
182
+
183
+ if (length(na )> 0 ) {
184
+ notna = which(! is.na(output ))
185
+ torep = output [[notna [1 ]]] # the first output that worked as expected
186
+ torep [1 : length(torep )]= NA # populate with NA
187
+ output [na ]= rep(list (torep ),length(na ))
188
+
189
+ }
190
+
191
+ output = as.data.frame(output )
166
192
temp = data.frame (row.names = CN ) # make sure we get result for all features, even if NA
167
193
output = merge(temp ,as.data.frame(t(output ),stringsAsFactors = FALSE ),by = 0 ,all = TRUE ,sort = FALSE )
168
194
rownames(output )= output $ Row.names
0 commit comments