File: marginal.R

package info (click to toggle)
r-cran-mutoss 0.1-13-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,560 kB
  • sloc: sh: 13; makefile: 2
file content (273 lines) | stat: -rw-r--r-- 13,291 bytes parent folder | download | duplicates (3)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# TODO: Add comment
# 
# Author: wiebke
###############################################################################


#### one sample model ####

onesamp.model <- function() {
	return(list(model=list(typ="onesamp")))
}

mutoss.onesamp.model <- function() { return(new(Class="MutossMethod",
					label="One-sample test",
					callFunction="onesamp.model",
					output=c("model"),
					info="<h2>One sample model</h2>
							<p>The input for this one sample model is a data matrix whose columns represent the samples and the rows represent the multiple endpoints. 
							E.g. for genomics this would be a gene matrix, where each row gives the expression for a single gene.</p> 
							<p> For the next steps you have the following choices:</p>
							<p> Either marginal hypotheses tests (if robust Wilcoxon otherwise t-test) could be performed on each row of the 
							data matrix to obtain raw p-values which then need to be adjusted for multiplicity to control a chosen error rate.</p>
							<p> Or resampling based methods could be performed based on Dudoit and van der Laan (2007) to obtain adjusted p-values which control the 
							FWER. Afterwards it is possible to use augmentation procedures to get adjusted p-values for control of FDR, FDX or gFWER.</p> 
							<h3>Reference:</h3>
							<ul>
							<li>Dudoit, S. and van der Laan, M.J. (2007). <i>Mulitple Testing Procedures and Applications to Genomics.</i> Springer Series in Statistics.</li>
							</ul>",
					parameters=list(
					)
			)) }

onesamp.marginal <- function(data, robust, alternative, psi0) {
	result <- NULL
	if (robust) {
		result <- apply(data, 1, function(x) {wilcox.test(x, alternative=alternative, mu=psi0)$p.value} )
	} else {
		result <- apply(data, 1, function(x) {t.test(x ,alternative=alternative, mu=psi0)$p.value} )
	}
	return(list(pValues=result))
}

mutoss.onesamp.marginal.model <- function(model) {
	return("typ" %in% names(model) && model$typ == "onesamp")
}


mutoss.onesamp.marginal <- function() { return(new(Class="MutossMethod",
					label="One-sample test",
					callFunction="onesamp.marginal",
					output=c("pValues"),
					info="<h2>Marginal one sample test.</h2>
							<p>The robust version uses the Wilcoxon-Mann-Whitney test, otherwise a t-test will be performed.</p> 
							<h3>Reference:</h3>
							<ul>
							<li>Wilcoxon, F. (1945). <i>Individual Comparisons by Ranking Methods.</i> Biometrics Bulletin 1:80-83.</li>\n\
							<li>Mann, H. and Whitney, D. (1947). <i>On a test of whether one of two random variables is stochastically larger 
							than the other.</i> Annals of Mathematical Statistics 18:50-60</li>\n\
							<li>Student (1908).<i>The probable error of a mean.</i> Biometrika, 6(1):1-25.</li>\n 
							</ul>",
					parameters=list(
							data=list(type="ANY"),
							robust=list(type="logical", label="Robust statistic"),
							alternative=list(type="character", label="Alternative", choices=c("two.sided", "less", "greater")),
							psi0=list(type="numeric", label="Hypothesized null value", default=0)
					)
			)) }



#### two sample model ####


twosamp.model <- function(classlabel) {
	classlabel <- as.vector(classlabel)
	return(list(model=list(typ="twosamp", classlabel=classlabel)))
}

mutoss.twosamp.model <- function() { return(new(Class="MutossMethod",
					label="Two sample test",
					callFunction="twosamp.model",
					output=c("model"),
					info="<h2>Two sample model</h2>
							<p>The input for this one sample model is a data matrix whose columns represent the samples and the rows represent the multiple endpoints. 
							E.g. for genomics this would be a gene matrix, where each row gives the expression for a single gene.</p> 
							<p> Furthermore, a classlabel needs to be provided to distinguish the two sample groups.
							<p> For the next steps you have the following choices:</p>
							<p> Either marginal hypotheses tests (if robust Wilcoxon otherwise t-test) could be performed on each row of the 
							data matrix to obtain raw p-values which then need to be adjusted for multiplicity to control a chosen error rate.</p>
							<p> Or resampling based methods could be performed based on Dudoit and van der Laan (2007) to obtain adjusted p-values which control the 
							FWER. Afterwards it is possible to use augmentation procedures to get adjusted p-values for control of FDR, FDX or gFWER.</p> 
							<h3>Reference:</h3>
							<ul>
							<li>Dudoit, S. and van der Laan, M.J. (2007). <i>Mulitple Testing Procedures and Applications to Genomics.</i> Springer Series in Statistics.</li>
							</ul>",
					parameters=list(
							classlabel=list(type="RObject", label="classlabel")
					)
			)) }

twosamp.marginal <- function(data, model, robust, alternative, psi0, equalvar) {
	label <- as.numeric(as.factor(model$classlabel))
	result <- NULL
	if (robust) {
		result <- apply(data, 1, function(x) {wilcox.test(x=x[ ,label==1], y=x[label==2], alternative=alternative, mu=psi0)$p.value} )
	} else {
		result <- apply(data, 1, function(x) {t.test(x=x[ ,label==1], y=x[label==2], alternative=alternative, mu=psi0, equal.var=equalvar)$p.value} )
	}
	return(list(pValues=result))
}

mutoss.twosamp.marginal.model <- function(model) {
	return("typ" %in% names(model) && model$typ == "twosamp")
}

mutoss.twosamp.marginal <- function() { return(new(Class="MutossMethod",
					label="Two sample test",
					callFunction="twosamp.marginal",
					output=c("pValues"),
					info="<h2></h2>
							<p>The robust version uses the Wilcoxon-Mann-Whitney test, otherwise a two-sample t-test will be performed.</p> 
							<h3>Reference:</h3>
							<ul>
							<li>Wilcoxon, F. (1945). <i>Individual Comparisons by Ranking Methods.</i> Biometrics Bulletin 1:80-83.</li>\n\
							<li>Mann, H. and Whitney, D. (1947). <i>On a test of whether one of two random variables is stochastically larger 
							than the other.</i> Annals of Mathematical Statistics 18:50-60</li>\n
							</ul>",
					parameters=list(
							data=list(type="ANY"),
							model=list(type="ANY"),
							robust=list(type="logical", label="Robust statistic"),
							alternative=list(type="character", label="Alternative", choices=c("two.sided", "less", "greater")),
							psi0=list(type="numeric", label="Hypothesized null value", default=0),
							equalvar=list(type="logical", label="Equal variance")
					)
			)) }


### paired sample model ###

paired.model <- function(classlabel) {
	classlabel <- as.vector(classlabel)
	return(list(model=list(typ="pairedsamp", classlabel=classlabel)))
}

mutoss.paired.model <- function() { return(new(Class="MutossMethod",
					label="Paired sample test",
					callFunction="paired.model",
					output=c("model"),
					info="<h2>Paired sample test</h2>
							<p>The robust version uses the Wilcoxon signed rank test, otherwise a paired t-test will be performed.</p> 
							<p>The input for this paired sample model is a data matrix whose columns represent the samples and the rows represent the multiple endpoints. 
							E.g. for genomics this would be a gene matrix, where each row gives the expression for a single gene.</p> 
							<p> Furthermore, a classlabel needs to be provided to distinguish the two paired groups. The arrangement of group indices does not matter, as long
							as the columns are arranged in the same corresponding order between groups. For example, if group 1 is code as 0 and group 2 is 
							coded as 1, for 3 pairs of data, it does not matter if the classlabel is coded as (0,0,0,1,1,1) or (1,1,1,0,0,0) or (0,1,0,1,0,1)
							or (1,0,1,0,1,0), the paired differences between groups will be calculated as group2 - group1. 
							</p>
							<p> For the next steps you have the following choices:</p>
							<p> Either marginal hypotheses tests (if robust Wilcoxon otherwise t-test) could be performed on each row of the 
							data matrix to obtain raw p-values which then need to be adjusted for multiplicity to control a chosen error rate.</p>
							<p> Or resampling based methods could be performed based on Dudoit and van der Laan (2007) to obtain adjusted p-values which control the 
							FWER. Afterwards it is possible to use augmentation procedures to get adjusted p-values for control of FDR, FDX or gFWER.</p> 
							
							
							<h3>Reference:</h3>
							<ul>
							<li>Dudoit, S. and van der Laan, M.J. (2007). <i>Mulitple Testing Procedures and Applications to Genomics.</i> Springer Series in Statistics.</li>
							</ul>",
					parameters=list(
							classlabel=list(type="RObject", label="classlabel")
					)
			)) }

paired.marginal <- function(data, model, robust, alternative, psi0, equalvar) {
	label <- as.numeric(as.factor(model$classlabel))
	result <- NULL
	if (robust) {
		result <- apply(data, 1, function(x) {wilcox.test(x=x[label==1], y=x[label==2], alternative=alternative, mu=psi0, paired=TRUE, var.equal=equalvar)$p.value} )
	} else {
		result <- apply(data, 1, function(x) {t.test(x=x[label==1], y=x[label==2], alternative=alternative, mu=psi0, paired=TRUE, var.equal=equalvar)$p.value} )
	}
	return(list(pValues=result))
}

mutoss.paired.marginal <- function() { return(new(Class="MutossMethod",
					label="Paired sample test",
					callFunction="paired.marginal",
					output=c("pValues"),
					info="<h2></h2>
							<p>The robust version uses the Wilcoxon test, otherwise a paired t-test will be performed.</p> 
							<p>A vector of classlabels needs to be provided to distinguish the two paired groups. The arrangement of group indices does not matter, as long
							as the columns are arranged in the same corresponding order between groups. For example, if group 1 is code as 0 and group 2 is 
							coded as 1, for 3 pairs of data, it does not matter if the classlabel is coded as (0,0,0,1,1,1) or (1,1,1,0,0,0) or (0,1,0,1,0,1)
							or (1,0,1,0,1,0), the paired differences between groups will be calculated as group2 - group1. </p>
							<p>You could either choose a valid R object to load as classlabels or you could provide it manually by inserting e.g. c(0,1,0,1,0,1) or rep(c(0,1), each=5) or rep(c(0,1), 5). </p>",
					parameters=list(
							data=list(type="ANY"),
							model=list(type="ANY"),
							robust=list(type="logical", label="Robust statistic"),
							alternative=list(type="character", label="Alternative", choices=c("two.sided", "less", "greater")),
							psi0=list(type="numeric", label="Hypothesized null value", default=0),
							equalvar=list(type="logical", label="Equal variance")
					)
			)) }

mutoss.paired.marginal.model <- function(model) {
	return("typ" %in% names(model) && model$typ == "pairedsamp")
}

### f test model ###


ftest.model <- function(classlabel) {
	classlabel <- as.vector(classlabel)
	return(list(model=list(typ="ftest", classlabel=classlabel)))
}

mutoss.ftest.model <- function() { return(new(Class="MutossMethod",
					label="F test",
					callFunction="ftest.model",
					output=c("model"),
					info="<h2>F test</h2>
							<p>The input for this F test model is a data matrix whose columns represent the samples and the rows represent the multiple endpoints. 
							E.g. for genomics this would be a gene matrix, where each row gives the expression for a single gene.</p> 
							<p> Furthermore, a classlabel needs to be provided to distinguish k sample groups.</p>
							<p> For the next steps you have the following choices:</p>
							<p> Either marginal hypotheses tests (if robust Kruskal-Wallis test, otherwise F-test) could be performed on each row of the 
							data matrix to obtain raw p-values which then need to be adjusted for multiplicity to control a chosen error rate.</p>
							<p> Or resampling based methods could be performed based on Dudoit and van der Laan (2007) to obtain adjusted p-values which control the 
							FWER. Afterwards it is possible to use augmentation procedures to get adjusted p-values for control of FDR, FDX or gFWER.</p> 
							<h3>Reference:</h3>
							<ul>
							<li>Dudoit, S. and van der Laan, M.J. (2007). <i>Mulitple Testing Procedures and Applications to Genomics.</i> Springer Series in Statistics.</li>
							</ul>",
					parameters=list(
							classlabel=list(type="RObject", label="classlabel")
					)
			)) }

ftest.marginal <- function(data, model, robust) {
	label <- as.numeric(as.factor(model$classlabel))
	result <- NULL
	if (robust) {
		result <- apply(data, 1, function(x) {kruskal.test(x=x, g=label)$p.value} )
	} else {
		result <- apply(data, 1, function(x) { out=x
					anova(lm( out ~ label ))$'Pr(>F)'[1]} )	
	}	
	return(list(pValues=result))
}

mutoss.ftest.marginal <- function() { return(new(Class="MutossMethod",
					label="F test",
					callFunction="ftest.marginal",
					output=c("pValues"),
					info="<h2></h2>
							<p>Robust = Kruskal-Wallis test. Otherwise F-test.</p> 
							<p></p>
							<h3>Reference:</h3>
							<ul>
							<li>Kruskal, W.H. und Wallis, W.A. (1952). <i>Use of ranks in one-criterion variance analysis.</i> JASA, 47:583-621</li>
							</ul>",
					parameters=list(
							data=list(type="ANY"),
							model=list(type="ANY"),
							robust=list(type="logical", label="Robust statistic")
					)
			)) }

mutoss.ftest.marginal.model <- function(model) {
	return("typ" %in% names(model) && model$typ == "ftest")
}