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

NAME

6       trend2d  - Fit a [weighted] [robust] polynomial model for z = f(x,y) to
7       xyz[w] data.
8

SYNOPSIS

10       trend2d -Fxyzmrw -Nn_model[r] [ xyz[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       trend2d reads x,y,z [and w] values from the first three [four]  columns
16       on  standard  input  [or  xyz[w]file]  and  fits a regression model z =
17       f(x,y) + e by [weighted] least squares.  The fit may be made robust  by
18       iterative  reweighting  of  the data.  The user may also search for the
19       number of terms in f(x,y) which significantly reduce the variance in z.
20       n_model  may be in [1,10] to fit a model of the following form (similar
21       to grdtrend):
22
23       m1 + m2*x + m3*y + m4*x*y + m5*x*x + m6*y*y +  m7*x*x*x  +  m8*x*x*y  +
24       m9*x*y*y + m10*y*y*y.
25
26       The user must specify -Nn_model, the number of model parameters to use;
27       thus, -N4 fits a bilinear trend, -N6 a quadratic surface,  and  so  on.
28       Optionally,  append  r to perform a robust fit.  In this case, the pro‐
29       gram will iteratively reweight the data based on a robust  scale  esti‐
30       mate, in order to converge to a solution insensitive to outliers.  This
31       may be handy when separating a "regional" field from a "residual" which
32       should  have non-zero mean, such as a local mountain on a regional sur‐
33       face.
34
35       -F     Specify up to six letters from the set {x y z  m  r  w}  in  any
36              order to create columns of ASCII [or binary] output.  x = x, y =
37              y, z = z, m = model f(x,y), r = residual z - m, w = weight  used
38              in fitting.
39
40       -N     Specify  the number of terms in the model, n_model, and append r
41              to do a robust fit.  E.g., a robust bilinear model is -N4r.
42

OPTIONS

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

REMARKS

104       The domain of x and y will be shifted and scaled to  [-1,  1]  and  the
105       basis  functions  are  built  from Chebyshev polynomials.  These have a
106       numerical advantage in the form of the matrix which  must  be  inverted
107       and allow more accurate solutions.  In many applications of trend2d the
108       user has data located approximately along a line in the x,y plane which
109       makes  an angle with the x axis (such as data collected along a road or
110       ship track).  In this case the accuracy could be improved by a rotation
111       of the x,y axes.  trend2d does not search for such a rotation; instead,
112       it may find that the matrix problem has deficient rank.   However,  the
113       solution  is  computed  using  the generalized inverse and should still
114       work out OK.  The user should check the results graphically if  trend2d
115       shows  deficient  rank.   NOTE: The model parameters listed with -V are
116       Chebyshev coefficients; they are not numerically equivalent to the  m#s
117       in the equation described above.  The description above is to allow the
118       user to match -N with the order of the polynomial surface.  For  evalu‐
119       ating Chebyshev polynomials, see grdmath.
120
121       The -Nn_modelr (robust) and -I (iterative) options evaluate the signif‐
122       icance of the improvement in model misfit Chi-Squared  by  an  F  test.
123       The default confidence limit is set at 0.51; it can be changed with the
124       -I option.  The user may be surprised to find that in  most  cases  the
125       reduction  in  variance achieved by increasing the number of terms in a
126       model is not significant at a very  high  degree  of  confidence.   For
127       example,  with 120 degrees of freedom, Chi-Squared must decrease by 26%
128       or more to be significant at the 95% confidence level.  If you want  to
129       keep  iterating  as  long  as  Chi-Squared  is  decreasing,  set confi‐
130       dence_level to zero.
131
132       A low confidence limit (such as the default value of 0.51) is needed to
133       make  the  robust  method  work.  This method iteratively reweights the
134       data to reduce the influence of outliers.  The weight is based  on  the
135       Median  Absolute  Deviation and a formula from Huber [1964], and is 95%
136       efficient when the model residuals have an outlier-free normal  distri‐
137       bution.   This  means  that  the  influence of outliers is reduced only
138       slightly at each iteration; consequently the reduction  in  Chi-Squared
139       is  not  very  significant.  If the procedure needs a few iterations to
140       successfully attenuate their effect, the significance level  of  the  F
141       test must be kept low.
142

ASCII FORMAT PRECISION

144       The ASCII output formats of numerical data are controlled by parameters
145       in your .gmtdefaults4  file.   Longitude  and  latitude  are  formatted
146       according  to  OUTPUT_DEGREE_FORMAT, whereas other values are formatted
147       according to D_FORMAT.  Be aware that the format in effect can lead  to
148       loss  of  precision  in  the output, which can lead to various problems
149       downstream.  If you find the output is not written with  enough  preci‐
150       sion, consider switching to binary output (-bo if available) or specify
151       more decimals using the D_FORMAT setting.
152

EXAMPLES

154       To remove a planar trend from data.xyz by ordinary least squares, use:
155
156       trend2d data.xyz -Fxyr -N2 > detrended_data.xyz
157
158       To make the above planar trend robust with respect to outliers, use:
159
160       trend2d data.xzy -Fxyr -N2r > detrended_data.xyz
161
162       To find out how many terms (up to 10) in a robust interpolant are  sig‐
163       nificant in fitting data.xyz, use:
164
165       trend2d data.xyz -N10r -I -V
166

SEE ALSO

168       GMT(1), grdmath(1), grdtrend(1), trend1d(1)
169

REFERENCES

171       Huber,  P.  J.,  1964,  Robust estimation of a location parameter, Ann.
172       Math. Stat., 35, 73-101.
173
174       Menke, W., 1989, Geophysical Data Analysis:  Discrete  Inverse  Theory,
175       Revised Edition, Academic Press, San Diego.
176
177
178
179GMT 4.3.1                         15 May 2008                       TREND2D(1)
Impressum