1TREND1D(1)                   Generic Mapping Tools                  TREND1D(1)
2
3
4

NAME

6       trend1d - Fit a [weighted] [robust] polynomial [or Fourier] model for y
7       = f(x) to xy[w] data.
8

SYNOPSIS

10       trend1d -Fxymrw -N[f]n_model[r] [ xy[w]file ] [ -Ccondition_number ]  [
11       -H[i][nrec]  ]  [  -I[confidence_level]  ]  [ -V ] [ -W ] [ -:[i|o] ] [
12       -b[i|o][s|S|d|D[ncol]|c[var1/...]] ] [ -f[i|o]colinfo ]
13

DESCRIPTION

15       trend1d reads x,y [and w] values from the first two [three] columns  on
16       standard  input [or xy[w]file] and fits a regression model y = f(x) + e
17       by [weighted] least squares.  The functional form of f(x) may be chosen
18       as  polynomial  or Fourier, and the fit may be made robust by iterative
19       reweighting of the data.  The user may also search for  the  number  of
20       terms in f(x) which significantly reduce the variance in y.
21

REQUIRED ARGUMENTS

23       -F     Specify up to five letters from the set {x y m r w} in any order
24              to create columns of ASCII [or binary] output.  x = x, y = y,  m
25              = model f(x), r = residual y - m, w = weight used in fitting.
26
27       -N     Specify  the  number  of terms in the model, n_model, whether to
28              fit a Fourier (-Nf) or polynomial [Default] model, and append  r
29              to do a robust fit.  E.g., a robust quadratic model is -N3r.
30

OPTIONS

32       xy[w]file
33              ASCII  [or binary, see -b] file containing x,y [w] values in the
34              first 2 [3] columns.  If no file is specified, trend1d will read
35              from standard input.
36
37       -C     Set  the  maximum  allowed condition number for the matrix solu‐
38              tion.  trend1d fits a damped least squares model, retaining only
39              that  part of the eigenvalue spectrum such that the ratio of the
40              largest eigenvalue to the smallest  eigenvalue  is  condition_#.
41              [Default:  condition_# = 1.0e06. ].
42
43       -H     Input file(s) has header record(s).  If used, the default number
44              of header records is N_HEADER_RECS.  Use -Hi if only input  data
45              should  have  header  records  [Default  will  write  out header
46              records if the input data have  them].  Blank  lines  and  lines
47              starting with # are always skipped.
48
49       -I     Iteratively increase the number of model parameters, starting at
50              one, until n_model is reached or the reduction  in  variance  of
51              the model is not significant at the confidence_level level.  You
52              may set -I only, without an attached number; in  this  case  the
53              fit  will  be iterative with a default confidence level of 0.51.
54              Or choose your own level between 0 and 1.  See remarks section.
55
56       -V     Selects verbose mode, which will send progress reports to stderr
57              [Default runs "silently"].
58
59       -W     Weights  are  supplied  in  input column 3.  Do a weighted least
60              squares fit [or start with these weights when doing  the  itera‐
61              tive robust fit].  [Default reads only the first 2 columns.]
62
63       -:     Toggles  between  (longitude,latitude)  and (latitude,longitude)
64              input and/or output.  [Default is (longitude,latitude)].  Append
65              i  to  select  input  only or o to select output only.  [Default
66              affects both].
67
68       -bi    Selects binary input.  Append s for single precision [Default is
69              d  (double)].   Uppercase  S  or  D  will  force  byte-swapping.
70              Optionally, append ncol, the number of columns  in  your  binary
71              input  file if it exceeds the columns needed by the program.  Or
72              append c  if  the  input  file  is  netCDF.  Optionally,  append
73              var1/var2/...  to specify the variables to be read.  [Default is
74              2 (or 3 if -W is set) columns].
75
76       -bo    Selects binary output.  Append s for single  precision  [Default
77              is  d  (double)].   Uppercase  S  or D will force byte-swapping.
78              Optionally, append ncol, the number of desired columns  in  your
79              binary output file.  [Default is 1-5 columns as given by -F].
80
81       -f     Special  formatting of input and/or output columns (time or geo‐
82              graphical data).  Specify i or o to  make  this  apply  only  to
83              input  or  output  [Default  applies to both].  Give one or more
84              columns (or column ranges) separated by commas.  Append T (abso‐
85              lute  calendar time), t (relative time in chosen TIME_UNIT since
86              TIME_EPOCH), x (longitude), y (latitude), or f (floating  point)
87              to  each  column or column range item.  Shorthand -f[i|o]g means
88              -f[i|o]0x,1y (geographic coordinates).
89

ASCII FORMAT PRECISION

91       The ASCII output formats of numerical data are controlled by parameters
92       in  your  .gmtdefaults4  file.   Longitude  and  latitude are formatted
93       according to OUTPUT_DEGREE_FORMAT, whereas other values  are  formatted
94       according  to D_FORMAT.  Be aware that the format in effect can lead to
95       loss of precision in the output, which can  lead  to  various  problems
96       downstream.   If  you find the output is not written with enough preci‐
97       sion, consider switching to binary output (-bo if available) or specify
98       more decimals using the D_FORMAT setting.
99

REMARKS

101       If  a  Fourier  model  is selected, the domain of x will be shifted and
102       scaled to [-pi, pi] and the basis functions used  will  be  1,  cos(x),
103       sin(x),  cos(2x), sin(2x), ...   If a polynomial model is selected, the
104       domain of x will be shifted and scaled to [-1, 1] and the  basis  func‐
105       tions  will be Chebyshev polynomials.  These have a numerical advantage
106       in the form of the matrix which must be inverted and allow  more  accu‐
107       rate  solutions.   The Chebyshev polynomial of degree n has n+1 extrema
108       in [-1, 1], at all of which its value is either -1  or  +1.   Therefore
109       the magnitude of the polynomial model coefficients can be directly com‐
110       pared.  NOTE: The stable model coefficients are Chebyshev coefficients.
111       The  corresponding  polynomial  coefficients in a + bx + cxx + ...  are
112       also given in Verbose mode but users must realize  that  they  are  NOT
113       stable beyond degree 7 or 8. See Numerical Recipes for more discussion.
114       For evaluating Chebyshev polynomials, see gmtmath.
115
116       The -Nr (robust) and -I (iterative) options evaluate  the  significance
117       of  the  improvement  in  model  misfit  Chi-Squared by an F test.  The
118       default confidence limit is set at 0.51; it can be changed with the  -I
119       option.   The  user  may  be  surprised  to find that in most cases the
120       reduction in variance achieved by increasing the number of terms  in  a
121       model  is  not  significant  at  a very high degree of confidence.  For
122       example, with 120 degrees of freedom, Chi-Squared must decrease by  26%
123       or  more to be significant at the 95% confidence level.  If you want to
124       keep iterating  as  long  as  Chi-Squared  is  decreasing,  set  confi‐
125       dence_level to zero.
126
127       A low confidence limit (such as the default value of 0.51) is needed to
128       make the robust method work.  This  method  iteratively  reweights  the
129       data  to  reduce the influence of outliers.  The weight is based on the
130       Median Absolute Deviation and a formula from Huber [1964], and  is  95%
131       efficient  when the model residuals have an outlier-free normal distri‐
132       bution.  This means that the influence  of  outliers  is  reduced  only
133       slightly  at  each iteration; consequently the reduction in Chi-Squared
134       is not very significant.  If the procedure needs a  few  iterations  to
135       successfully  attenuate  their  effect, the significance level of the F
136       test must be kept low.
137

EXAMPLES

139       To remove a linear trend from data.xy by ordinary least squares, use:
140
141       trend1d data.xy -Fxr -N2 > detrended_data.xy
142
143       To make the above linear trend robust with respect to outliers, use:
144
145       trend1d data.xy -Fxr -N2r > detrended_data.xy
146
147       To find out how many terms (up to 20, say) in a robust  Fourier  inter‐
148       polant are significant in fitting data.xy, use:
149
150       trend1d data.xy -Nf20r -I -V
151

SEE ALSO

153       GMT(1), gmtmath(1), grdtrend(1), trend2d(1)
154

REFERENCES

156       Huber,  P.  J.,  1964,  Robust estimation of a location parameter, Ann.
157       Math. Stat., 35, 73-101.
158
159       Menke, W., 1989, Geophysical Data Analysis:  Discrete  Inverse  Theory,
160       Revised Edition, Academic Press, San Diego.
161
162
163
164GMT 4.5.6                         10 Mar 2011                       TREND1D(1)
Impressum