.\" Man page generated from reStructuredText. . .TH "TREND1D" "1gmt" "Jan 10, 2019" "5.4.5" "GMT" .SH NAME trend1d \- Fit a [weighted] [robust] polynomial [and/or Fourier] model for y = f(x) to xy[w] data . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .SH SYNOPSIS .sp \fBtrend1d\fP [ \fItable\fP ] \fB\-F\fP\fBxymrw|p|P|c\fP \fB\-N\fP\fIparams\fP [ \fIxy[w]file\fP ] [ \fB\-C\fP\fIcondition_number\fP ] [ \fB\-I\fP[\fIconfidence_level\fP] ] [ \fB\-V\fP[\fIlevel\fP] ] [ \fB\-W\fP ] [ \fB\-b\fPbinary ] [ \fB\-d\fPnodata ] [ \fB\-e\fPregexp ] [ \fB\-f\fPflags ] [ \fB\-h\fPheaders ] [ \fB\-i\fPflags ] [ \fB\-:\fP[\fBi\fP|\fBo\fP] ] .sp \fBNote:\fP No space is allowed between the option flag and the associated arguments. .SH DESCRIPTION .sp \fBtrend1d\fP reads x,y [and w] values from the first two [three] columns on standard input [or \fIfile\fP] and fits a regression model y = f(x) + e by [weighted] least squares. The functional form of f(x) may be chosen as polynomial or Fourier or a mix of the two, and the fit may be made robust by iterative reweighting of the data. The user may also search for the number of terms in f(x) which significantly reduce the variance in y. .SH REQUIRED ARGUMENTS .INDENT 0.0 .TP \fB\-F\fP\fBxymrw|p|P|c\fP Specify up to five letters from the set {\fBx y m r w\fP} in any order to create columns of ASCII [or binary] output. \fBx\fP = x, \fBy\fP = y, \fBm\fP = model f(x), \fBr\fP = residual y \- \fBm\fP, \fBw\fP = weight used in fitting. Alternatively, choose just the single selection \fBp\fP to output a record with the polynomial model coefficients, \fBP\fP for the normalized polynomial model coefficients, or \fBc\fP for the normalized Chebyshev model coefficients. .UNINDENT .INDENT 0.0 .TP \fB\-N\fP[\fBp\fP|\fBP\fP|\fBf\fP|\fBF\fP|\fBc\fP|\fBC\fP|\fBs\fP|\fBS\fP|\fBx\fP]\fIn\fP[,...][\fB+l\fP\fIlength\fP][\fB+o\fP\fIorigin\fP][\fB+r\fP] Specify the components of the (possibly mixed) model. Append one or more comma\-separated model components. Each component is of the form \fBT\fP\fIn\fP, where \fBT\fP indicates the basis function and \fIn\fP indicates the polynomial degree or how many terms in the Fourier series we want to include. Choose \fBT\fP from \fBp\fP (polynomial with intercept and powers of x up to degree \fIn\fP), \fBP\fP (just the single term \fIx^n\fP), \fBf\fP (Fourier series with \fIn\fP terms), \fBc\fP (Cosine series with \fIn\fP terms), \fBs\fP (sine series with \fIn\fP terms), \fBF\fP (single Fourier component of order \fIn\fP), \fBC\fP (single cosine component of order \fIn\fP), and \fBS\fP (single sine component of order \fIn\fP). By default the \fIx\fP\-origin and fundamental period is set to the mid\-point and data range, respectively. Change this using the \fB+o\fP\fIorigin\fP and \fB+l\fP\fIlength\fP modifiers. We normalize \fIx\fP before evaluating the basis functions. Basically, the trigonometric bases all use the normalized x\(aq = (2*pi*(x\-\fIorigin\fP)/\fIlength\fP) while the polynomials use x\(aq = 2*(x\-x_mid)/(xmax \- xmin) for stability. Finally, append \fB+r\fP for a robust solution [Default gives a least squares fit]. Use \fB\-V\fP to see a plain\-text representation of the y(x) model specified in \fB\-N\fP\&. .UNINDENT .SH OPTIONAL ARGUMENTS .INDENT 0.0 .TP .B \fItable\fP One or more ASCII [or binary, see \fB\-bi\fP] files containing x,y [w] values in the first 2 [3] columns. If no files are specified, \fBtrend1d\fP will read from standard input. .UNINDENT .INDENT 0.0 .TP \fB\-C\fP\fIcondition_number\fP Set the maximum allowed condition number for the matrix solution. \fBtrend1d\fP fits a damped least squares model, retaining only that part of the eigenvalue spectrum such that the ratio of the largest eigenvalue to the smallest eigenvalue is \fIcondition_#\fP\&. [Default: \fIcondition_#\fP = 1.0e06. ]. .UNINDENT .INDENT 0.0 .TP \fB\-I\fP[\fIconfidence_level\fP] Iteratively increase the number of model parameters, starting at one, until \fIn_model\fP is reached or the reduction in variance of the model is not significant at the \fIconfidence_level\fP level. You may set \fB\-I\fP only, without an attached number; in this case the fit will be iterative with a default confidence level of 0.51. Or choose your own level between 0 and 1. See remarks section. Note that the model terms are added in the order they were given in \fB\-N\fP so you should place the most important terms first. .UNINDENT .INDENT 0.0 .TP \fB\-V\fP[\fIlevel\fP] (more ...) Select verbosity level [c]. .UNINDENT .INDENT 0.0 .TP \fB\-W\fP Weights are supplied in input column 3. Do a weighted least squares fit [or start with these weights when doing the iterative robust fit]. [Default reads only the first 2 columns.] .UNINDENT .INDENT 0.0 .TP \fB\-bi\fP[\fIncols\fP][\fBt\fP] (more ...) Select native binary input. [Default is 2 (or 3 if \fB\-W\fP is set) columns]. .UNINDENT .INDENT 0.0 .TP \fB\-bo\fP[\fIncols\fP][\fItype\fP] (more ...) Select native binary output. [Default is 1\-5 columns as given by \fB\-F\fP]. .UNINDENT .INDENT 0.0 .TP \fB\-d\fP[\fBi\fP|\fBo\fP]\fInodata\fP (more ...) Replace input columns that equal \fInodata\fP with NaN and do the reverse on output. .UNINDENT .INDENT 0.0 .TP \fB\-e\fP[\fB~\fP]\fI"pattern"\fP \fB|\fP \fB\-e\fP[\fB~\fP]/\fIregexp\fP/[\fBi\fP] (more ...) Only accept data records that match the given pattern. .UNINDENT .INDENT 0.0 .TP \fB\-f\fP[\fBi\fP|\fBo\fP]\fIcolinfo\fP (more ...) Specify data types of input and/or output columns. .UNINDENT .INDENT 0.0 .TP \fB\-h\fP[\fBi\fP|\fBo\fP][\fIn\fP][\fB+c\fP][\fB+d\fP][\fB+r\fP\fIremark\fP][\fB+r\fP\fItitle\fP] (more ...) Skip or produce header record(s). .UNINDENT .INDENT 0.0 .TP \fB\-i\fP\fIcols\fP[\fB+l\fP][\fB+s\fP\fIscale\fP][\fB+o\fP\fIoffset\fP][,\fI\&...\fP] (more ...) Select input columns and transformations (0 is first column). .UNINDENT .INDENT 0.0 .TP \fB\-:\fP[\fBi\fP|\fBo\fP] (more ...) Swap 1st and 2nd column on input and/or output. .UNINDENT .INDENT 0.0 .TP \fB\-^\fP or just \fB\-\fP Print a short message about the syntax of the command, then exits (NOTE: on Windows just use \fB\-\fP). .TP \fB\-+\fP or just \fB+\fP Print an extensive usage (help) message, including the explanation of any module\-specific option (but not the GMT common options), then exits. .TP \fB\-?\fP or no arguments Print a complete usage (help) message, including the explanation of all options, then exits. .UNINDENT .SH ASCII FORMAT PRECISION .sp The ASCII output formats of numerical data are controlled by parameters in your gmt.conf file. Longitude and latitude are formatted according to FORMAT_GEO_OUT, absolute time is under the control of FORMAT_DATE_OUT and FORMAT_CLOCK_OUT, whereas general floating point values are formatted according to FORMAT_FLOAT_OUT\&. Be aware that the format in effect can lead to loss of precision in ASCII output, which can lead to various problems downstream. If you find the output is not written with enough precision, consider switching to binary output (\fB\-bo\fP if available) or specify more decimals using the FORMAT_FLOAT_OUT setting. .SH REMARKS .sp If a polynomial model is included, then the domain of x will be shifted and scaled to [\-1, 1] and the basis functions will be Chebyshev polynomials provided the polygon is of full order (otherwise we stay with powers of x). The Chebyshev polynomials have a numerical advantage in the form of the matrix which must be inverted and allow more accurate solutions. The Chebyshev polynomial of degree n has n+1 extrema in [\-1, 1], at all of which its value is either \-1 or +1. Therefore the magnitude of the polynomial model coefficients can be directly compared. NOTE: The stable model coefficients are Chebyshev coefficients. The corresponding polynomial coefficients in a + bx + cxx + ... are also given in Verbose mode but users must realize that they are NOT stable beyond degree 7 or 8. See Numerical Recipes for more discussion. For evaluating Chebyshev polynomials, see gmtmath\&. .sp The \fB\-N\fP\&...\fB+r\fP (robust) and \fB\-I\fP (iterative) options evaluate the significance of the improvement in model misfit Chi\-Squared by an F test. The default confidence limit is set at 0.51; it can be changed with the \fB\-I\fP option. The user may be surprised to find that in most cases the reduction in variance achieved by increasing the number of terms in a model is not significant at a very high degree of confidence. For example, with 120 degrees of freedom, Chi\-Squared must decrease by 26% or more to be significant at the 95% confidence level. If you want to keep iterating as long as Chi\-Squared is decreasing, set \fIconfidence_level\fP to zero. .sp A low confidence limit (such as the default value of 0.51) is needed to make the robust method work. This method iteratively reweights the data to reduce the influence of outliers. The weight is based on the Median Absolute Deviation and a formula from Huber [1964], and is 95% efficient when the model residuals have an outlier\-free normal distribution. This means that the influence of outliers is reduced only slightly at each iteration; consequently the reduction in Chi\-Squared is not very significant. If the procedure needs a few iterations to successfully attenuate their effect, the significance level of the F test must be kept low. .SH EXAMPLES .sp To remove a linear trend from data.xy by ordinary least squares, use: .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C gmt trend1d data.xy \-Fxr \-Np1 > detrended_data.xy .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp To make the above linear trend robust with respect to outliers, use: .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C gmt trend1d data.xy \-Fxr \-Np1+r > detrended_data.xy .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp To fit the model y(x) = a + bx^2 + c * cos(2*pi*3*(x/l) + d * sin(2*pi*3*(x/l), with l the fundamental period (here l = 15), try: .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C gmt trend1d data.xy \-Fxm \-NP0,P2,F3+l15 > model.xy .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp To find out how many terms (up to 20, say in a robust Fourier interpolant are significant in fitting data.xy, use: .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C gmt trend1d data.xy \-Nf20+r \-I \-V .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .SH SEE ALSO .sp gmt, gmtmath, gmtregress, grdtrend, trend2d .SH REFERENCES .sp Huber, P. J., 1964, Robust estimation of a location parameter, \fIAnn. Math. Stat.\fP, \fB35\fP, 73\-101. .sp Menke, W., 1989, Geophysical Data Analysis: Discrete Inverse Theory, Revised Edition, Academic Press, San Diego. .SH COPYRIGHT 2019, P. Wessel, W. H. F. Smith, R. Scharroo, J. Luis, and F. Wobbe .\" Generated by docutils manpage writer. .