趋势documentation

趋势根据最小二乘计算数据系列的线性趋势。数据不需要及时间隔。

也可以看看detrend3.

Back to Climate Data Tools Contents.

Contents

Syntax

tr =趋势(y)tr =趋势(y,fs)tr =趋势(y,t)tr =趋势(...,'dim',dim)tr =趋势(...,'omitnan')[tr,p] =趋势(...)[tr,p] =趋势(...,corroptions)

Description

tr =趋势(y)calculates the linear trend per sample ofy.

tr = trend(y,Fs)指定抽样率FS. For example, to obtain a trend per year from data collected at monthly resolution, setFSequal to 12. This syntax assumes all values in y are equally spaced in time.

tr = trend(y,t)specifies a vectort相对于趋势的计算。t的每个元素对应于测量y, and when this syntax is used, times do不是need to be equally spaced. Units of the trend are (units y)/units(t) so if the units oftare in days (such asdatenum),乘以365.25,每年获得趋势。

tr =趋势(...,'dim',昏暗)沿着wh指定尺寸ich the trend is calculated. By default, ifyis a 1D array, the trend is calculated along the first nonsingleton dimension of y; if y is a 2D matrix, the trend is calcaulated down the rows (dimension 1) ofy; ifyis a 3D matrix, the trend is calculated down dimension 3.

tr = trend(...,'omitnan')solves the least squares trend, even where not all values ofy是有限的。如果许多网格单元包含一些但不是全部NAN,则此选项可能会有些慢。使用时要注意'omitnan'选项:the trend is calculated only over the timespan in which finite data exist. Therefore, for example, if some grid cells contain finite data only for one year of a 10 year record, it is possible that the apparent "10 year" trend reported by the trend function could actually be an aliased signal. Accordingly, the'omitnan'只有在整个时间记录中均匀地均匀地散射NAN时,才应使用选项。

[tr,p] = trend(...)returns the p-value of statistical significance of the trend. (Requires the Statistics Toolbox)

[tr,p] =趋势(...,柯罗替体)specifies any optional Name-Value pair arguments accpted by the corr function. For example,'Type','Kendall'specifies computing Kendall's tau correlation coefficient.

Example 1: 1D Array

Here's a time series sampled at 12 times per year:

FS = 12;%采样率(每年12个样本)t =(2000:1/fs:2007)';% time vector sampled at Fs per unit timey = 40*t + 123*rand(size(t)) - 8e4;% forced trend of 40 units y per second情节(t,y)xlabel'time'ylabel“一些变量”

很容易与该图上的趋势线覆盖polyplot像这样:

holdpolyplot(t,y,1)

...but what's the numerical value of that trend? In other words, how steep is the slope? When we definedy, we specified that it should be 40*t (plus some random noise and an offset), so the trend should be about 40:

趋势(y)
ans = 3.2710

这种趋势甚至接近40个!那是因为如果我们不指定采样频率或时间向量,则趋势功能给出了趋势y每个样品。每年指定12个样本的采样率:

趋势(Y,FS)
ANS = 39.2522

...and that's the value close to 40 that we were expecting. It's not exactly 40 because we intentionally added noise, but it's about 40, as expected.

You may have noticed by now that the trend can be calculated any of three ways, and each will give the same answer. You can multiply the trend by the sampling rate, or you can specify the sampling rate in the趋势function, or you can specify the corresponding time vectort, and they'll all give the same answer:

[trend(y)*Fs trend(y,Fs) trend(y,t)]
ANS = 39.252239.2522 39.2522

示例2:2D数据

如果您有一堆与同一时间一致的测量值趋势function can calculate all the trends at once, in a computationally efficient manner. Consider these four time series built from theyarray we defined in example 1:

%[y y+400非常嘈杂的噪声];A = [y y+400 y+200*randn(size(y)) 100*rand(size(y))]; figure plot(t,A) legend('column 1',“第2列”,'column 3','column 4',...'location',“西北”)XLABEL'time'ylabel“一些变量”axistight盒子off% removes ugly frame from axeslegend盒子off% removes ugly frame from legend

The trends of each column can be computed like this:

趋势(A,t)
ANS = 39.2522 39.2522 56.5252 2.6557

That's what we expected: About 40 units/year for columns 1 and 2, which are the same data aside from the offset; somewhat of a trend for column 3, and not much of a trend for the noise-only column 4.

Are any of these trends statistically significant?使用可选的第二功能输出来查看:

[tr,p] = trend(A,t)
tr = 39.2522 39.2522 56.5252 2.6557 p = 0.0000 0.0000 0.0000 0.0732

The p values for the first three columns indicate statistical significance, but the fourth column tells us that any trend measured there is probably junk.

What if your data go across columns through time instead of down rows? Just specify the dimension:

[tr,p] = trend(A',t,'dim',2)
tr = 39.2522 39.2522 56.5252 2.6557 p = 0.0000 0.0000 0.0000 0.0732

Example 3: A 3D dataset

Here's a sample dataset that goes down at a rate of -pi per time slice. Useexpand3to create the sample dataset, and then add a bunch of noise to keep things interesting:

% 60x80 grid that goes down -pi in each frame:Y = expand3(ones(60,80),-pi*(1:100));% Add a bunch of noise and an offset:y = y + 10*randn(size(y)) + 900;

Here's the trend inY:

imagesc(trend(Y)) colorbar

一开始可能看起来像是噪音,但这只是我们故意在那里发出的噪音。请注意配色栏刻度 - 所有值的所有值都完全如预期的那样围绕负PI。

示例4a:海面温度

Load the sample pacific_sst.mat dataset, which contains monthly gridded sea surface temperature data, and calculate trends.

加载pacific_sst[tr,p] =趋势(SST,12);图ImageScn(LON,LAT,TR)CB = COLORBAR;Ylabel(CB,'SST trend \circC yr^{-1}') cmocean('balance','pivot')%在中间设置为零的结肠

标记统计显着性的区域。首先,这意味着定义统计意义。假设p值小于0.01的所有内容具有统计学意义:

StatisticallySignificant = p<0.01;

确定重要区域点画功能。一个小捕获是点画insists on gridded inputs, so we'll have to turn thoselatlonarrays into grids withmeshgrid:

[Lon,Lat] = meshgrid(lon,lat); hold点画(Lon,Lat,StatisticallySignificant) text(-85,60,“哈德逊湾”,'vert','top','horiz','center','fontangle',“斜体”)

示例4b:“ omitnan”选项

敏锐的观察者可能已经注意到,在上面的图中,哈德逊湾的趋势是不确定的。但是,我们确实有很多好数据!看看SST数据集中有限测量的总数:

figure imagescn(lon,lat,sum(isfinite(sst),3)) cb = colorbar; ylabel(cb,'sum of finite sst measurements') caxis([650 802])

在上图中,我们看到哈德逊湾有600多个良好的SST测量值,尽管这不是整个802个月的记录,但计算最小二乘趋势也应该很多。在这种情况下,我们可以使用'omitnan'选项:

[tr,p] =趋势(SST,12,'omitnan');图ImageScn(LON,LAT,TR)CB = COLORBAR;Ylabel(CB,'SST trend \circC yr^{-1}') cmocean('balance','pivot')%在中间设置为零的结肠hold点画(Lon,Lat,p<0.01)%标志着统计学意义的领域

Above we see that there has been a warming trend in Hudson Bay, and it is statistically significant.

Author Info

此功能是Climate Data Toolbox for Matlab. The function and supporting documentation were written by Chad A. Greene of the University of Texas at Austin.