-
Notifications
You must be signed in to change notification settings - Fork 2
Modified t test (modTtest3d)
Modified student t-test for autocorrelated data
using equivalent sample size. The method is based on
Zwiers and von Storch, J. Clim 1995, p. 336-351.
For small sample sizes (<=30) a lookup table test is
used (also described in above publication). This function only works for 3d [lon,lat,time] data.
modTtest3d(x, ...)
modTtest3d(x, y = NULL, alternative = c("two.sided", "less", "greater"), mu = 0, paired = FALSE, var.equal = TRUE, conf.level = 0.95, timevals=NULL, ...)
modTtest3d(formula, data, subset, na.action, ...)
- x: a (non-empty) numeric array of data values with dimensions longitude, latitude, time where time is autocorrelated AR(1)
- y: an optional (non-empty) numeric array of data values with dimensions longitude, latitude, time where time is autocorrelated AR(1)
- alternative: a character string specifying the alternative
hypothesis, must be one of
"two.sided"
(default),"greater"
or"less"
. You can specify just the initial letter. - mu: a number indicating the true value of the mean (or difference in means if you are performing a two sample test).
- paired: a logical indicating whether you want a paired test.
- var.equal: a logical variable indicating whether to treat the two variances as being equal. If
TRUE
then the pooled variance is used to estimate the variance, ifFALSE
a warning is issued because the method assumes equal variances. - conf.level: confidence level of the interval.
- timevals: an optional number of time values in the x (y) timeseries. If provided the function checks for correct dimensions.
- formula: a formula of the form
lhs ~ rhs
wherelhs
is a numeric variable giving the data values andrhs
a factor with two levels giving the corresponding groups. - data: an optional matrix or data frame (or similar: see
model.frame
) containing the variables in the formulaformula
. By default the variables are taken fromenvironment(formula)
. - subset: an optional vector specifying a subset of observations to be used.
- na.action: a function which indicates what should happen when the data contain
NA
s. Defaults togetOption("na.action")
. } - ...: further arguments to be passed to or from methods, not used at the moment.
Performs a modified t-test using the equivalent sample size in case of autocorrelation in the data (Zwiers and von Storch, 1995). When the sample size is too small (<= 30) to obtain robust results a look-up table test is performed.
Either one sample or two sample tests can be performed, the function needs timeseries of at least 12, otherwise the lookup table test fails. The lookup table test also is not suited for negative correlations <=-0.3. For negative autocorrelations and sample sizes larger than 30 a standard student t-test is performed.
The formula interface is only applicable for the 2-sample tests.
alternative = "greater" is the alternative that x
has a larger mean than y
.
If paired is TRUE
then both x and y must be specified and they must be the same length. Missing values are silently removed (in pairs if paired is TRUE
).
If the input data are effectively constant (compared to the larger of the two means) an error is generated.
A list with class htest
containing the following components:
- statistic: the value of the t-statistic.
- parameter: the degrees of freedom for the t-statistic. Is NA for the lookup table test
- p.value: the p-value for the test. Is NA for the lookup table test
- conf.int: a confidence interval for the mean appropriate to the specified alternative hypothesis
- estimate: the estimated mean or difference in means depending on whether it was a one-sample test or a two-sample test.
- null.value: the specified hypothesized value of the mean or mean difference depending on whether it was a one-sample test or a two-sample test
- alternative: a character string describing the alternative hypothesis
- method: a character string indicating what type of t-test was performed
- data.name: a character string giving the name(s) of the data
Zwiers and von Storch, 1995, Taking serial correlation into account in tests of the mean, J. Clim,8, p. 336--351.
Ruth Lorenz
t.test
x<-array(NA,dim=c(20,50,31))
y<-array(NA,dim=c(20,50,31))
for (lon in 1:20){
for (lat in 1:50){
#create timeseries with AR(1) correlation
x[lon,lat,]<-arima.sim(list(ar = 0.3),n=31,rand.gen=rnorm,sd=0.1,mean=0)
y[lon,lat,]<-arima.sim(list(ar = 0.3),n=31,rand.gen=rnorm,sd=0.1,mean=0)
}
}
test3d<-modTtest3d(x,y,alternative = c("two.sided"),conf.level=0.95)
print(test3d)