1TREND2D(1)                            GMT                           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 [ table ]  -Fxyzmrw  -Nn_model[+r] [ xyz[w]file ]  [   -Ccondi‐
11       tion_number  ]  [   -I[confidence_level]  ]  [  -V[level] ] [  -W ] [ [
12       -bbinary ] [ -dnodata ] [ -eregexp ]  [  -fflags  ]  [  -hheaders  ]  [
13       -iflags ] [ -:[i|o] ]
14
15       Note:  No  space  is allowed between the option flag and the associated
16       arguments.
17

DESCRIPTION

19       trend2d reads x,y,z [and w] values from the first three [four]  columns
20       on  standard  input  [or  xyz[w]file]  and  fits a regression model z =
21       f(x,y) + e by [weighted] least squares. The fit may be made  robust  by
22       iterative  reweighting  of  the  data. The user may also search for the
23       number of terms in f(x,y) which significantly reduce the variance in z.
24       n_model  may be in [1,10] to fit a model of the following form (similar
25       to grdtrend):
26          m1 + m2*x + m3*y + m4*x*y + m5*x*x + m6*y*y + m7*x*x*x + m8*x*x*y  +
27          m9*x*y*y + m10*y*y*y.
28
29       The user must specify -Nn_model, the number of model parameters to use;
30       thus, -N4 fits a bilinear trend, -N6 a quadratic surface,  and  so  on.
31       Optionally,  append  +r to perform a robust fit. In this case, the pro‐
32       gram will iteratively reweight the data based on a robust  scale  esti‐
33       mate,  in order to converge to a solution insensitive to outliers. This
34       may be handy when separating a "regional" field from a "residual" which
35       should  have non-zero mean, such as a local mountain on a regional sur‐
36       face.
37

REQUIRED ARGUMENTS

39       -Fxyzmrw
40              Specify up to six letters from the set {x y z  m  r  w}  in  any
41              order  to create columns of ASCII [or binary] output. x = x, y =
42              y, z = z, m = model f(x,y), r = residual z - m, w = weight  used
43              in fitting.
44
45       -Nn_model[+r]
46              Specify the number of terms in the model, n_model, and append +r
47              to do a robust fit. E.g., a robust bilinear model is -N4+r.
48

OPTIONAL ARGUMENTS

50       table  One or more ASCII [or binary, see -bi]  files  containing  x,y,z
51              [w]  values  in  the first 3 [4] columns. If no files are speci‐
52              fied, trend2d will read from standard input.
53
54       -Ccondition_number
55              Set the maximum allowed condition number for  the  matrix  solu‐
56              tion.  trend2d fits a damped least squares model, retaining only
57              that part of the eigenvalue spectrum such that the ratio of  the
58              largest  eigenvalue  to  the smallest eigenvalue is condition_#.
59              [Default: condition_# = 1.0e06. ].
60
61       -I[confidence_level]
62              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[level] (more ...)
70              Select verbosity level [c].
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       -bi[ncols][t] (more ...)
77              Select  native  binary  input. [Default is 3 (or 4 if -W is set)
78              input columns].
79
80       -bo[ncols][type] (more ...)
81              Select native binary output. [Default is 1-6 columns as  set  by
82              -F].
83
84       -d[i|o]nodata (more ...)
85              Replace  input  columns  that  equal  nodata with NaN and do the
86              reverse on output.
87
88       -e[~]"pattern" | -e[~]/regexp/[i] (more ...)
89              Only accept data records that match the given pattern.
90
91       -f[i|o]colinfo (more ...)
92              Specify data types of input and/or output columns.
93
94       -h[i|o][n][+c][+d][+rremark][+rtitle] (more ...)
95              Skip or produce header record(s).
96
97       -icols[+l][+sscale][+ooffset][,...] (more ...)
98              Select input columns and transformations (0 is first column).
99
100       -:[i|o] (more ...)
101              Swap 1st and 2nd column on input and/or output.
102
103       -^ or just -
104              Print a short message about the  syntax  of  the  command,  then
105              exits (NOTE: on Windows just use -).
106
107       -+ or just +
108              Print  an extensive usage (help) message, including the explana‐
109              tion of any module-specific  option  (but  not  the  GMT  common
110              options), then exits.
111
112       -? or no arguments
113              Print a complete usage (help) message, including the explanation
114              of all options, then exits.
115

REMARKS

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

ASCII FORMAT PRECISION

157       The ASCII output formats of numerical data are controlled by parameters
158       in your gmt.conf file. Longitude and latitude are  formatted  according
159       to   FORMAT_GEO_OUT,  absolute  time  is  under  the  control  of  FOR‐
160       MAT_DATE_OUT and FORMAT_CLOCK_OUT, whereas general floating point  val‐
161       ues are formatted according to FORMAT_FLOAT_OUT. Be aware that the for‐
162       mat in effect can lead to loss of precision in ASCII output, which  can
163       lead  to  various  problems  downstream.  If you find the output is not
164       written with enough precision, consider switching to binary output (-bo
165       if  available) or specify more decimals using the FORMAT_FLOAT_OUT set‐
166       ting.
167

EXAMPLES

169       To remove a planar trend from data.xyz by ordinary least squares, use:
170
171              gmt trend2d data.xyz -Fxyr -N2 > detrended_data.xyz
172
173       To make the above planar trend robust with respect to outliers, use:
174
175              gmt trend2d data.xzy -Fxyr -N2+r > detrended_data.xyz
176
177       To find out how many terms (up to 10 in a robust interpolant  are  sig‐
178       nificant in fitting data.xyz, use:
179
180              gmt trend2d data.xyz -N10+r -I -V
181

SEE ALSO

183       gmt, grdmath, grdtrend, trend1d
184

REFERENCES

186       Huber,  P.  J.,  1964,  Robust estimation of a location parameter, Ann.
187       Math. Stat., 35, 73-101.
188
189       Menke, W., 1989, Geophysical Data Analysis:  Discrete  Inverse  Theory,
190       Revised Edition, Academic Press, San Diego.
191
193       2019, P. Wessel, W. H. F. Smith, R. Scharroo, J. Luis, and F. Wobbe
194
195
196
197
1985.4.5                            Feb 24, 2019                       TREND2D(1)
Impressum