.\" Man page generated from reStructuredText. . .TH "GMTREGRESS" "1gmt" "Sep 07, 2019" "6.0.0rc4" "GMT" .SH NAME gmtregress \- Linear regression of 1-D data sets . .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 \fBgmt regress\fP [ \fItable\fP ] [ \fB\-A\fP\fImin\fP/\fImax\fP/\fIinc\fP ] [ \fB\-C\fP\fIlevel\fP ] [ \fB\-E\fP\fBx\fP|\fBy\fP|\fBo\fP|\fBr\fP ] [ \fB\-F\fP\fIflags\fP ] [ \fB\-N\fP\fB1\fP|\fB2\fP|\fBr\fP|\fBw\fP ] [ \fB\-S\fP[\fBr\fP] ] [ \fB\-T\fP[\fImin/max\fP/]\fIinc\fP[\fBn\fP] | \fB\-T\fP\fIfile\fP|\fIlist\fP ] [ \fB\-W\fP[\fBw\fP][\fBx\fP][\fBy\fP][\fBr\fP] ] [ \fB\-V\fP[\fIlevel\fP] ] [ \fB\-a\fPflags ] [ \fB\-b\fPbinary ] [ \fB\-d\fPnodata ] [ \fB\-e\fPregexp ] [ \fB\-g\fPgaps ] [ \fB\-h\fPheaders ] [ \fB\-i\fPflags ] [ \fB\-o\fPflags ] [ \fB\-\-PAR\fP=\fIvalue\fP ] .sp \fBNote:\fP No space is allowed between the option flag and the associated arguments. .SH DESCRIPTION .sp \fBregress\fP reads one or more data tables [or \fIstdin\fP] and determines the best linear regression model \fIy\fP = \fIa\fP + \fIb\fP* \fIx\fP for each segment using the chosen parameters. The user may specify which data and model components should be reported. By default, the model will be evaluated at the input points, but alternatively you can specify an equidistant range over which to evaluate the model, or turn off evaluation completely. Instead of determining the best fit we can perform a scan of all possible regression lines (for a range of slope angles) and examine how the chosen misfit measure varies with slope. This is particularly useful when analyzing data with many outliers. Note: If you actually need to work with log10 of \fIx\fP or \fIy\fP you can accomplish that transformation during read by using the \fB\-i\fP option. .SH REQUIRED ARGUMENTS .sp None .SH OPTIONAL ARGUMENTS .INDENT 0.0 .TP .B \fItable\fP One or more ASCII (or binary, see \fB\-bi\fP[\fIncols\fP][\fItype\fP]) data table file(s) holding a number of data columns. If no tables are given then we read from standard input. The first two columns are expected to contain the required \fIx\fP and \fIy\fP data. Depending on your \fB\-W\fP and \fB\-E\fP settings we may expect an additional 1\-3 columns with error estimates of one of both of the data coordinates, and even their correlation. .UNINDENT .INDENT 0.0 .TP \fB\-A\fP\fImin\fP/\fImax\fP/\fIinc\fP Instead of determining a best\-fit regression we explore the full range of regressions. Examine all possible regression lines with slope angles between \fImin\fP and \fImax\fP, using steps of \fIinc\fP degrees [\-90/+90/1]. For each slope the optimum intercept is determined based on your regression type (\fB\-E\fP) and misfit norm (\fB\-N\fP) settings. For each segment we report the four columns \fIangle\fP, \fIE\fP, \fIslope\fP, \fIintercept\fP, for the range of specified angles. The best model parameters within this range are written into the segment header and reported in verbose mode (\fB\-V\fP). .UNINDENT .INDENT 0.0 .TP \fB\-C\fP\fIlevel\fP Set the confidence level (in %) to use for the optional calculation of confidence bands on the regression [95]. This is only used if \fB\-F\fP includes the output column \fBc\fP\&. .UNINDENT .INDENT 0.0 .TP \fB\-Ex\fP|\fBy\fP|\fBo\fP|\fBr\fP Type of linear regression, i.e., select the type of misfit we should calculate. Choose from \fBx\fP (regress \fIx\fP on \fIy\fP; i.e., the misfit is measured horizontally from data point to regression line), \fBy\fP (regress \fIy\fP on \fIx\fP; i.e., the misfit is measured vertically [Default]), \fBo\fP (orthogonal regression; i.e., the misfit is measured from data point orthogonally to nearest point on the line), or \fBr\fP (Reduced Major Axis regression; i.e., the misfit is the product of both vertical and horizontal misfits) [\fBy\fP]. .UNINDENT .INDENT 0.0 .TP \fB\-F\fP\fIflags\fP Append a combination of the columns you wish returned; the output order will match the order specified. Choose from \fBx\fP (observed \fIx\fP), \fBy\fP (observed \fIy\fP), \fBm\fP (model prediction), \fBr\fP (residual = data minus model), \fBc\fP (symmetrical confidence interval on the regression; see \fB\-C\fP for specifying the level), \fBz\fP (standardized residuals or so\-called \fIz\-scores\fP) and \fBw\fP (outlier weights 0 or 1; for \fB\-Nw\fP these are the Reweighted Least Squares weights) [\fBxymrczw\fP]. As an alternative to evaluating the model, just give \fB\-Fp\fP and we instead write a single record with the model parameters \fInpoints xmean ymean angle misfit slope intercept sigma_slope sigma_intercept\fP\&. .UNINDENT .INDENT 0.0 .TP \fB\-N1\fP|\fB2\fP|\fBr\fP|\fBw\fP Selects the norm to use for the misfit calculation. Choose among \fB1\fP (L\-1 measure; the mean of the absolute residuals), \fB2\fP (Least\-squares; the mean of the squared residuals), \fBr\fP (LMS; The least median of the squared residuals), or \fBw\fP (RLS; Reweighted Least Squares: the mean of the squared residuals after outliers identified via LMS have been removed) [Default is \fB2\fP]. Traditional regression uses L\-2 while L\-1 and in particular LMS are more robust in how they handle outliers. As alluded to, RLS implies an initial LMS regression which is then used to identify outliers in the data, assign these a zero weight, and then redo the regression using a L\-2 norm. .UNINDENT .INDENT 0.0 .TP \fB\-S\fP[\fBr\fP] Restricts which records will be output. By default all data records will be output in the format specified by \fB\-F\fP\&. Use \fB\-S\fP to exclude data points identified as outliers by the regression. Alternatively, use \fB\-Sr\fP to reverse this and only output the outlier records. .UNINDENT .INDENT 0.0 .TP \fB\-T\fP[\fImin/max\fP/]\fIinc\fP[\fBn\fP] | \fB\-T\fP\fIfile\fP|\fIlist\fP Evaluate the best\-fit regression model at the equidistant points implied by the arguments. If only \fB\-T\fP\fIinc\fP is given instead we will reset \fImin\fP and \fImax\fP to the extreme \fIx\fP\-values for each segment. To skip the model evaluation entirely, simply provide \fB\-T\fP0. For details on array creation, see \fI\%Generate 1D Array\fP\&. .UNINDENT .INDENT 0.0 .TP \fB\-W\fP[\fBw\fP][\fBx\fP][\fBy\fP][\fBr\fP] Specifies weighted regression and which weights will be provided. Append \fBx\fP if giving 1\-sigma uncertainties in the \fIx\fP\-observations, \fBy\fP if giving 1\-sigma uncertainties in \fIy\fP, and \fBr\fP if giving correlations between \fIx\fP and \fIy\fP observations, in the order these columns appear in the input (after the two required and leading \fIx\fP, \fIy\fP columns). Giving both \fBx\fP and \fBy\fP (and optionally \fBr\fP) implies an orthogonal regression, otherwise giving \fBx\fP requires \fB\-Ex\fP and \fBy\fP requires \fB\-Ey\fP\&. We convert uncertainties in \fIx\fP and \fIy\fP to regression weights via the relationship weight = 1/sigma. Use \fB\-Ww\fP if the we should interpret the input columns to have precomputed weights instead. Note: residuals with respect to the regression line will be scaled by the given weights. Most norms will then square this weighted residual (\fB\-N1\fP is the only exception). .UNINDENT .INDENT 0.0 .TP \fB\-V\fP[\fIlevel\fP] (more ...) Select verbosity level [c]. .UNINDENT .INDENT 0.0 .TP \fB\-a\fP\fIcol\fP=\fIname\fP[\fI\&...\fP] (more ...) Set aspatial column associations \fIcol\fP=\fIname\fP\&. .UNINDENT .INDENT 0.0 .TP \fB\-bi\fP[\fIncols\fP][\fBt\fP] (more ...) Select native binary format for primary input. .UNINDENT .INDENT 0.0 .TP \fB\-bo\fP[\fIncols\fP][\fItype\fP] (more ...) Select native binary output. [Default is same as input]. .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\-g\fP[\fBa\fP]\fBx\fP|\fBy\fP|\fBd\fP|\fBX\fP|\fBY\fP|\fBD\fP|[\fIcol\fP]\fBz\fP\fIgap\fP[\fBu\fP][\fB+n\fP|\fBp\fP] (more ...) Determine data gaps and line breaks. .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][,\fIt\fP[\fIword\fP]] (more ...) Select input columns and transformations (0 is first column, \fIt\fP is trailing text, append \fIword\fP to read one word only). .UNINDENT .INDENT 0.0 .TP \fB\-o\fP\fIcols\fP[,...][\fIt\fP[\fIword\fP]] (more ...) Select output columns (0 is first column; \fIt\fP is trailing text, append \fIword\fP to write one word only). .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. .TP \fB\-\-PAR\fP=\fIvalue\fP Temporarily override a GMT default setting; repeatable. See /gmt.conf for parameters. .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 GENERATE 1D ARRAY .sp Make an evenly spaced coordinate array from \fImin\fP to \fImax\fP in steps of \fIinc\fP\&. Append \fB+b\fP if we should take log2 of \fImin\fP and \fImax\fP and build an equidistant log2\-array using \fIinc\fP integer increments in log2. Append \fB+l\fP if we should take log10 of \fImin\fP and \fImax\fP and build an array where \fIinc\fP can be 1 (every magnitude), 2, (1, 2, 5 times magnitude) or 3 (1\-9 times magnitude). For less than every magnitude, use a negative integer \fIinc\fP\&. Append \fB+n\fP if \fIinc\fP is meant to indicate the number of equidistant coordinates instead. Alternatively, give a \fIfile\fP with output coordinates in the first column, or provide a comma\-separated \fIlist\fP of coordinates. If you only want a \fIsingle\fP value then you must append a comma to distinguish the list from the setting of \fIinc\fP\&. .sp If the module allows you to set up an absolute time series, append a valid time unit from the list \fBy\fPear, m\fBo\fPnth, \fBw\fPeek, \fBd\fPay, \fBh\fPour, \fBm\fPinute, and \fBs\fPecond to the given increment; add \fB+t\fP to ensure time column (or use \fB\-f\fP) Note: The internal time unit is still controlled independently by TIME_UNIT\&. Some modules allow for \fB+a\fP which will paste the coordinate array to the output table. .sp Likewise, if the module allows you to set up a spatial distance series (with distance computed from the first two data columns), specify the increment as \fIinc\fP[\fIunit\fP] with a geospatial distance unit from the list \fBd\fPegree (arc), \fBm\fPinute (arc), \fBs\fPecond (arc), m\fBe\fPter, \fBf\fPoot, \fBk\fPilometer, \fBM\fPiles (statute), \fBn\fPautical miles, or s\fBu\fPrvey foot; see \fB\-j\fP for calculation mode. For Cartesian distances, you must use the special unit \fBc\fP\&. .sp Finally, if you are only providing an increment and obtain \fImin\fP and \fImax\fP from the data, then it is possible (\fImax\fP \- \fImin\fP)/\fIinc\fP is not an integer, as required. If so then \fIinc\fP will be adjusted to accordingly. Alternatively, append \fB+e\fP to keep \fIinc\fP exact and adjust \fImax\fP instead. .SH NOTE: .sp The output segment header will contain all the various statistics we compute for each segment. These are in order: N (number of points), x0 (weighted mean x), y0 (weighted mean y), angle (of line), E (misfit), slope, intercept, sigma_slope, sigma_intercept, correlation (r), coefficient of determination (R). .SH EXAMPLES .sp To do a standard least\-squares regression on the \fIx\-y\fP data in points.txt and return x, y, and model prediction with 99% confidence intervals, try .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C gmt regress points.txt \-Fxymc \-C99 > points_regressed.txt .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp To just get the slope for the above regression, try .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C slope=\(gagmt regress points.txt \-Fp \-o5\(ga .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp To do a reweighted least\-squares regression on the data rough.txt and return x, y, model prediction and the RLS weights, try .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C gmt regress rough.txt \-Fxymw > points_regressed.txt .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp To do an orthogonal least\-squares regression on the data crazy.txt but first take the logarithm of both x and y, then return x, y, model prediction and the normalized residuals (z\-scores), try .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C gmt regress crazy.txt \-Eo \-Fxymz \-i0\-1l > points_regressed.txt .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp To examine how the orthogonal LMS misfits vary with angle between 0 and 90 in steps of 0.2 degrees for the same file, try .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C gmt regress points.txt \-A0/90/0.2 \-Eo \-Nr > points_analysis.txt .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .SH REFERENCES .sp Draper, N. R., and H. Smith, 1998, \fIApplied regression analysis\fP, 3rd ed., 736 pp., John Wiley and Sons, New York. .sp Rousseeuw, P. J., and A. M. Leroy, 1987, \fIRobust regression and outlier detection\fP, 329 pp., John Wiley and Sons, New York. .sp York, D., N. M. Evensen, M. L. Martinez, and J. De Basebe Delgado, 2004, Unified equations for the slope, intercept, and standard errors of the best straight line, \fIAm. J. Phys.\fP, 72(3), 367\-375. .SH SEE ALSO .sp gmt, trend1d, trend2d .SH COPYRIGHT 2019, The GMT Team .\" Generated by docutils manpage writer. .