File: 5C-TwoSampleTests.Rd

package info (click to toggle)
fbasics 240.10067-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,676 kB
  • ctags: 760
  • sloc: fortran: 5,589; sh: 22; makefile: 1
file content (380 lines) | stat: -rw-r--r-- 11,314 bytes parent folder | download
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
\name{TwoSampleTests}

\alias{TwoSampleTests}

% two sample tests:

\alias{ks2Test}

\alias{locationTest}
%\alias{.tTest}
%\alias{.kw2Test}

\alias{varianceTest}
%\alias{.varfTest}
%\alias{.bartlett2Test}
%\alias{.fligner2Test}

\alias{scaleTest}
%\alias{.ansariTest}
%\alias{.moodTest}

\alias{correlationTest}
\alias{.pearsonTest}
\alias{.kendallTest}
\alias{.spearmanTest}

% Distribution

\alias{dansariw}
\alias{pansariw}
\alias{qansariw}


\title{Two Sample Tests}


\description{
    
    A collection and description of functions for 
    two sample statistical tests. The functions allow 
    to test for distributional equivalence, for difference
    in location, variance and scale, and for correlations.
    \cr
      
    Distributional Equivalence:
    
    \tabular{ll}{
    \code{ks2Test} \tab Two sample Kolmogorov--Smirnov test.}
    
    Difference in Locations:
    
    \tabular{ll}{ 
    \code{locationTest} \tab The location test suite, \cr
    \code{.tTest} \tab The t test, \cr
    \code{.kw2Test} \tab the Kruskal--Wallis test. } 
    
    Difference in Variance:
    
    \tabular{ll}{ 
    \code{varianceTest} \tab The variance test suite, \cr
    \code{.varfTest} \tab The variance F test, \cr
    \code{.bartlett2Test} \tab the Bartlett test, \cr
    \code{.fligner2Test} \tab the Fligner--Killeen test.}
     
    Difference in Scale:
    
    \tabular{ll}{
    \code{scaleTest} \tab The scale test suite, \cr
    \code{.ansariTest} \tab  The Ansari--Bradley test, \cr
    \code{.moodTest} \tab the Mood test.}
    
    Correlations:
    
    \tabular{ll}{
    \code{correlationTest} \tab The correlation test suite, \cr
    \code{.pearsonTest} \tab Pearson's coefficient, \cr
    \code{.kendallTest} \tab Kendall's rho, \cr
    \code{.spearmanTest} \tab Spearman's rho.}
   
    
    Test Distributions:
    
    \tabular{ll}{       
    \code{dansariw} \tab Returns density of the Ansari W statistic, \cr
    \code{pansariw} \tab Returns probabilities of the Ansari W statistic, \cr
    \code{qansariw} \tab Returns quantiles of the Ansari W statistic. } 
     
}


\usage{
ks2Test(x, y, title = NULL, description = NULL)

locationTest(x, y, method = c("t", "kw2"), title = NULL, 
    description = NULL) 
%tTest(x, y, title = NULL, description = NULL) 
%kw2Test(x, y, title = NULL, description = NULL)

varianceTest(x, y, method = c("varf", "bartlett", "fligner"), title = NULL, 
    description = NULL)
%varfTest(x, y, title = NULL, description = NULL)
%bartlett2Test(x, y, title = NULL, description = NULL)
%fligner2Test(x, y, title = NULL, description = NULL)

scaleTest(x, y, method = c("ansari", "mood"), title = NULL, 
    description = NULL)
%ansariTest(x, y, title = NULL, description = NULL)
%moodTest(x, y, title = NULL, description = NULL)

correlationTest(x, y, method = c("pearson", "kendall", "spearman"), title = NULL, 
    description = NULL)
%pearsonTest(x, y, title = NULL, description = NULL)
%kendallTest(x, y, title = NULL, description = NULL)
%spearmanTest(x, y, title = NULL, description = NULL)

dansariw(x = NULL, m, n = m)
pansariw(q = NULL, m, n = m)
qansariw(p, m, n = m)
}


\arguments{
  
    \item{description}{
        optional description string, or a vector of character strings.
        }
    \item{m, n}{
        [*ansariw] - \cr
        } 
    \item{method}{
        a character string naming which test should be applied.
        } 
    \item{p}{
        [qansariw] - \cr
        a numeric vector of quantiles.
        }
    \item{q}{
        [pansariw] - \cr
        a numeric vector of quantiles.
        }
    \item{title}{
        an optional title string, if not specified the inputs data 
        name is deparsed.
        }
    \item{x, y}{
        a numeric vector of data values.
        \cr
        [bartlett2Test][fligner2Test][kw2Test] - \cr
        here \code{x} is a list, where each element is either a vector
        or an object of class \code{timeSeries}. \code{y} is only used
        for the two--sample test situation, where \code{x} and \code{y}
        are two vectors or objects of class \code{timeSeries}.
        \cr
        [dansariw] - \cr
        a numeric vector of quantiles.
        }
       
}


\value{

    In contrast to R's output report from S3 objects of class \code{"htest"}
    a different output report is produced. The classical tests presented
    here return an S4 object of class \code{"fHTEST"}. The object contains
    the following slots:
    
    \item{@call}{
        the function call.  
        }
    \item{@data}{
        the data as specified by the input argument(s).
        }
    \item{@test}{
        a list whose elements contail the results from the statistical
        test. The information provided is similar to a list object of
        class{"htest"}.
        }
    \item{@title}{
        a character string with the name of the test. This can be 
        overwritten specifying a user defined input argument.
        }
    \item{@description}{
        a character string with an optional user defined description. 
        By default just the current date when the test was applied will
        be returned.
        }
    
    
    The slot \code{@test} returns an object of class \code{"list"} 
    containing (at least) the following elements:

    \item{statistic}{
        the value(s) of the test statistic.
        }
    \item{p.value}{
        the p-value(s) of the test.
        }
    \item{parameters}{
        a numeric value or vector of parameters.
        }
    \item{estimate}{
        a numeric value or vector of sample estimates.
        }
    \item{conf.int}{
        a numeric two row vector or matrix of 95% confidence levels.
        }
    \item{method}{
        a character string indicating what type of test was performed.
        }
    \item{data.name}{
        a character string giving the name(s) of the data.
        }
        
    %The meaning of the elements of the \code{@test} slot is the following:
    
    %\code{ks2Test} 
    %\cr
    %returns the values for the \code{D}, \code{D^-} and \code{D^+} 
    %statistic and the corresponding p-values for the 'two-sided', 'less' 
    %and 'greater' alternatives.  
    
}


\details{
    
    The tests may be of interest for many financial 
    and economic applications, especially for the 
    comparison of two time series. The tests are grouped 
    according to their functionalities.
    \cr
    
    
    \bold{Distributional Equivalence:}
    \cr\cr  
    The test \code{ks2Test} performs a Kolmogorov--Smirnov two sample test 
    that the two data samples \code{x} and \code{y} come from the same 
    distribution, not necessarily a normal distribution. That means that 
    it is not specified what that common distribution is. 
    \cr
    
    \bold{Differences in Location:}
    \cr\cr  
    The function \code{tTest} can be used to determine if the two sample 
    means are equal for unpaired data sets. Two variants are used,
    assuming equal or unequal variances. 
  
    The function \code{kw2Test} performs a Kruskal-Wallis rank sum 
    test of the null hypothesis that the central tendencies or medians of 
    two samples are the same. The alternative is that they differ. 
    Note, that it is not assumed that the two samples are drawn from the 
    same distribution. It is also worth to know that the test assumes 
    that the variables under consideration have underlying continuous 
    distributions.
    \cr

    \bold{Differences in Variances:}
    \cr\cr    
    The function \code{varfTest} can be used to compare variances of two 
    normal samples performing an F test. The null hypothesis is that 
    the ratio of the variances of the populations from which they were 
    drawn is equal to one. 
    
    The function \code{bartlett2Test} performs the Bartlett's test of the 
    null hypothesis that the variances in each of the samples are the 
    same. This fact of equal variances across samples is also called 
    \emph{homogeneity of variances}. Note, that Bartlett's test is 
    sensitive to departures from normality. That is, if the samples 
    come from non-normal distributions, then Bartlett's test may simply 
    be testing for non-normality. The Levene test (not yet implemented)
    is an alternative to the Bartlett test that is less sensitive to 
    departures from normality. 
    
    The function \code{fligner2Test} performs the Fligner-Killeen test of 
    the null that the variances in each of the two samples are the same. 
    \cr
    
    \bold{Differences in Scale:}
    \cr\cr  
    The function \code{ansariTest} performs the Ansari--Bradley two--sample 
    test for a difference in scale parameters. Note, that we have completely 
    reimplemented this test based on the statistcs and p-values computed 
    from algorithm AS 93. The test returns for any sizes of the series 
    \code{x} and \code{y} the exact p value together with its asymptotic 
    limit. The test procedure is not limited to sizes shorter of length 50 
    as this is the case for the function \code{ansari.Test} implemented in 
    R's \code{stats} package. For the test statistics the following
    functions are available: \code{dansariw}, \code{pansariw}, and 
    \code{qansariw}.
    
    The function code{moodTest}, is another test which performs a 
    two--sample test for a difference in scale parameters. The underlying 
    model is that the two samples are drawn from \emph{f(x-l)} and 
    \emph{f((x-l)/s)/s}, respectively, where \emph{l} is a common 
    location parameter and \emph{s} is a scale parameter. The null 
    hypothesis is \emph{s=1}. 
    \cr
    
    
    \bold{Correlations:}
    \cr\cr  
    The function \code{correlationTest} tests for association 
    between paired samples, using Pearson's product moment 
    correlation coefficient, 
    
    The function \code{kendallTest} performs Kendall's tau test
    
    The function \code{spearmanTest} performs Spearman's rho test.
    
}

\note{

    Some of the test implementations are selected from \R's \code{ctest} 
    package.  
       
}


\references{

Conover, W. J. (1971);
    \emph{Practical nonparametric statistics},
    New York: John Wiley & Sons.

Durbin J. (1961); 
    \emph{Some Methods of Constructing Exact Tests},
    Biometrika 48, 41--55. 

Durbin,J. (1973);
    \emph{Distribution Theory Based on the Sample Distribution Function},
    SIAM, Philadelphia.

Lehmann E.L. (1986); 
    \emph{Testing Statistical Hypotheses}, 
    John Wiley and Sons, New York.
    
Moore, D.S. (1986);
    \emph{Tests of the chi-squared type}, 
    In: D'Agostino, R.B. and Stephens, M.A., eds., 
    Goodness-of-Fit Techniques, Marcel Dekker, New York. 

}


\author{

    R-core team for the tests from \R's ctest package,\cr
    Diethelm Wuertz for the Rmetrics \R-port.
    
}


\examples{
## SOURCE("fBasics.5C-TwoSampleTests")

## x, y -
   x = rnorm(50)
   y = rnorm(50)
  
## ks2Test - 
   ks2Test(x, y)
   
## locationTest | .tTest | .kw2Test - 
   locationTest(x, y)
   
## varianceTest | .varfTest, .bartlett2Test | .fligner2Test -
   varianceTest(x, y)

## scaleTest | .ansariTest | .moodTest -
   scaleTest(x, y)
   
## correlationTest | .pearsonTest | .kendallTest | .spearmanTest -
   correlationTest(x, y)
}


\keyword{htest}