diff --git a/toolbox/regression/FSRr.m b/toolbox/regression/FSRr.m index 24faa4400..c3473c86a 100644 --- a/toolbox/regression/FSRr.m +++ b/toolbox/regression/FSRr.m @@ -4,14 +4,14 @@ % %Link to the help function % -% FSRr uses the units not declared by outliers by FSR to produce a robust fit. +% FSRr uses the units not declared by outliers by FSR to produce a robust fit. % The units whose residuals exceeds the threshold determined by option % alpha are declared as outliers. Moreover, it is possible in option % R2th to modify the estimate of sigma2 which is used to declare % the outliers. This is useful when there is almost a perfect fit in the % data, the estimate of the error variance is very small and therefore % there is the risk of declaring as outliers very small deviations from -% the robust fit. In this case the estimate of sigma2 is corrected in +% the robust fit. In this case, the estimate of sigma2 is corrected in % order to achieve a value of R2 equal to R2th. % % @@ -47,22 +47,22 @@ % Data Types - double % % R2th : R2 threshold. Scalar. Scalar which defines the value R2 does -% have to exceed. For example if R2 based on good observations -% is 0.92 and R2th is 0.90 the estimate of the variance of the +% have to exceed. For example, if R2 based on good observations +% is 0.92 and R2th is 0.90, the estimate of the variance of the % residuals which is used to declare the outliers is adjusted % in order to have a value of R2 which is equal to 0.90. A % similar correction is applied to compute the prediction -% intervals. The default value of R2th is 1 which means that +% intervals. The default value of R2th is 1, which means that % there is no correction. % Example - 'R2th',0.99 % Data Types - double % %fullreweight: Option to declare outliers. Boolean. If fullreweight is true % (default option), the list of outliers refers to all the -% units whose residuals is above the threshold else if it is -% false the outliers are the observaions which by procedure +% units whose residuals are above the threshold; if it is +% false, the outliers are the observations which by procedure, % FSR had been declared outliers and have a residual greater -% than threshold +% than threshold. % Example - 'fullreweight',true % Data Types - double % @@ -71,7 +71,7 @@ % equal 1, it is possible to see on the screen the yX scatter % with superimposed the prediction intervals using a % confidence level 1-alpha, else no plot is shown on the -% screen +% screen. % Example - 'plotsPI',1 % Data Types - double % @@ -82,15 +82,15 @@ % out: structure which contains the following fields % % out.outliers = k x 1 vector containing the list of the units declared -% outliers by procedure FSR or NaN if the sample is -% homogeneous +% outliers by procedure FSR or NaN, if the sample is +% homogeneous. % out.beta = p-by-1 vector containing the estimated regression parameter -% by procedure FSR +% by procedure FSR. % out.outliersr = k1-by-1 vector containing the list of the units declared -% outliers after the reweighting step or NaN if the sample is -% homogeneous +% outliers after the reweighting step or NaN, if the sample is +% homogeneous. % out.betar = p-by-1 vector containing the estimated regression parameter -% after the reweighting step +% after the reweighting step. % out.rstud = n-by-2 matrix. % First column = studentized residuals; % Second column = p-values (computed using as reference @@ -366,7 +366,7 @@ p=size(X,2); % Xb = subset of X referred to good units Xb=X(ListIn,:); -% res=raw residuals for all observartions +% res=raw residuals for all observations res=y-X*beta; % resb= raw residuals for good observations resb=res(ListIn); @@ -382,7 +382,7 @@ % devtotb = total deviance referred to subset devtotb=ytildeb'*ytildeb; -% compute R2b = R squared referred to susbet; +% compute R2b = R squared referred to subset; R2b=1-numS2b/devtotb; % Correct the value of the deviance of residuals (numerator of S2) if R2 @@ -394,7 +394,7 @@ S2b=numS2b/dfe; % studres= vector which will contain squared (appropriately studentized) -% residuals for all n units. For the units non declared as outliers by FS +% residuals for all n units. For the units non declared as outliers by FS, % they will be squared studentized residuals (that is at the denominator we % have (1-h)), while for the units declared as outliers by FS, they are % deletion residuals (that is at the denominator we have (1+h)). @@ -415,7 +415,7 @@ studres2(ListIn)=((resb.^2)./(1-hi)); studres2=studres2/S2b; -% The final outliers are the units declared as outiers by FSR for which +% The final outliers are the units declared as outliers by FSR for which % observations r(ncl) is greater than the confidence threshold if fullreweight % rncl boolean vector which contains true for the unit whose diff --git a/toolbox/regression/FSRts.m b/toolbox/regression/FSRts.m index 0ddec5468..7326f6d75 100644 --- a/toolbox/regression/FSRts.m +++ b/toolbox/regression/FSRts.m @@ -14,10 +14,10 @@ % which will be used. The model structure contains the following % fields: % model.s = scalar (length of seasonal period). For monthly -% data s=12 (default), for quartely data s=4, ... +% data s=12 (default), for quarterly data s=4, ... % model.trend = scalar (order of the trend component). % trend = 1 implies linear trend with intercept (default), -% trend = 2 implies quadratic trend ... +% trend = 2 implies quadratic trend and so on. % Admissible values for trend are, 0, 1, 2 and 3. % model.seasonal = scalar (integer specifying number of % frequencies, i.e. harmonics, in the seasonal @@ -29,19 +29,19 @@ % if seasonal =2 we have: % $\beta_1 \cos( 2 \pi t/s) + \beta_2 \sin ( 2 \pi t/s) % + \beta_3 \cos(4 \pi t/s) + \beta_4 \sin (4 \pi t/s)$. -% Note that when $s$ is even the sine term disappears +% Note that when $s$ is even, the sine term disappears % for $j=s/2$ and so the maximum number of % trigonometric parameters is $s-1$. -% If seasonal is a number greater than 100 then it +% If seasonal is a number greater than 100, then it % is possible to specify how the seasonal component % grows over time. % For example, seasonal =101 implies a seasonal -% component which just uses one frequency +% component which just uses one frequency, % which grows linearly over time as follows: % $(1+\beta_3 t)\times ( \beta_1 cos( 2 \pi t/s) + % \beta_2 \sin ( 2 \pi t/s))$. % For example, seasonal =201 implies a seasonal -% component which just uses one frequency +% component which just uses one frequency, % which grows in a quadratic way over time as % follows: % $(1+\beta_3 t + \beta_4 t^2)\times( \beta_1 \cos( @@ -50,9 +50,9 @@ % model.X = matrix of size T-by-nexpl containing the % values of nexpl extra covariates which are likely % to affect y. -% model.posLS = positive integer which specifies to position +% model.posLS = positive integer which specifies the position % to include the level shift component. -% For example if model.posLS =13 then the +% For example, if model.posLS =13, then the % explanatory variable $I(t \geq 13})$ is created. % If this field is not present or if it is empty, % the level shift component is not included. @@ -60,7 +60,7 @@ % values of parameter estimates which have to be % used in the maximization procedure. If model.B is % a matrix, then initial estimates are extracted -% from the first colum of this matrix. If this +% from the first column of this matrix. If this % field is empty or if this field is not present, % the initial values to be used in the maximization % procedure are referred to the OLS parameter @@ -83,23 +83,23 @@ % nsamp : Number of subsamples which will be extracted to find the % robust estimator. Scalar. If nsamp=0 all subsets will be extracted. % They will be (n choose p). -% If the number of all possible subset is <1000 the +% If the number of all possible subset is <1000, the % default is to extract all subsets otherwise just 1000. % Example - 'nsamp',1000 % Data Types - double % % lms : Criterion to use to find the initial subset to initialize -% the search. Scalar, vector or structure. lms specifies +% the search. Scalar, vector or structure. lms specifies % the criterion to use to find the initial subset to % initialize the search (LTS with concentration steps or % subset supplied directly by the user). % The default value is 1 (Least trimmed squares % is computed to initialize the search). -% If lms is a struct it is possible to control a +% If lms is a struct, it is possible to control a % series of options for concentration steps (for more % details see function LTSts.m) % If, on the other hand, the user wants to initialize the -% search with a prespecified set of units there are two +% search with a prespecified set of units, there are two % possibilities: % 1) lms can be a vector with length greater than 1 which % contains the list of units forming the initial subset. For @@ -116,7 +116,7 @@ % % h : The number of observations that have determined the least % trimmed squares estimator. Scalar. h is an integer -% greater or equal than p but smaller then n. Generally if +% greater or equal than p, but smaller then n. Generally, if % the purpose is outlier detection h=[0.5*(n+p+1)] (default % value). h can be smaller than this threshold if the % purpose is to find subgroups of homogeneous observations. @@ -127,16 +127,16 @@ % Data Types - double % % plots : Plot on the screen. Scalar. -% If plots=1 (default) the plot of minimum deletion +% If plots=1 (default), the plot of minimum deletion % residual with envelopes based on T observations and the % scatterplot matrix with the outliers highlighted is % produced together with a two panel plot. -% The upper panel contains the orginal time series with +% The upper panel contains the original time series with % fitted values. The bottom panel will contain the plot % of robust residuals against index number. The confidence -% level which is used to draw the horizontal lines associated -% with the bands for the residuals is 0.999. -% If plots=2 the user can also monitor the intermediate +% level, which is used to draw the horizontal lines associated +% with the bands for the residuals, is 0.999. +% If plots=2, the user can also monitor the intermediate % plots based on envelope superimposition. % Else no plot is produced. % Example - 'plots',1 @@ -145,7 +145,7 @@ % init : Start of monitoring point. Scalar. % It specifies the point where to initialize the search and % start monitoring required diagnostics. If it is not -% specified it is set equal floor(0.5*(T+1)) +% specified, it is set equal floor(0.5*(T+1)). % Example - 'init',100 starts monitoring from step m=100 % Data Types - double % @@ -188,16 +188,16 @@ % coefficient of Xi in the multivariate regression and % avconst is the effect of all the other explanatory % variables different from Xi evaluated at their centroid -% (that is overline{y}'C)) +% (that is overline{y}'C)). % multivarfit = '2' -% equal to multivarfit ='1' but this time we also add the +% equal to multivarfit ='1', but this time we also add the % line based on the group of unselected observations % (i.e. the normal units). % Example - 'multivarfit','1' % Data Types - char % % labeladd : Add outlier labels in plot. Character. If this option is -% '1', we label the outliers with the +% '1', we label the outliers with the % unit row index in matrices X and y. The default value is % labeladd='', i.e. no label is added. % Example - 'labeladd','1' @@ -235,13 +235,13 @@ % strongly non normal and, thus, the general signal % detection rule based on consecutive exceedances cannot be % used. In this case bonflev can be: -% - a scalar smaller than 1 which specifies the confidence +% - a scalar smaller than 1, which specifies the confidence % level for a signal and a stopping rule based on the % comparison of the minimum MD with a -% Bonferroni bound. For example if bonflev=0.99 the +% Bonferroni bound. For example, if bonflev=0.99 the % procedure stops when the trajectory exceeds for the % first time the 99% bonferroni bound. -% - A scalar value greater than 1. In this case the +% - A scalar value greater than 1. In this case, the % procedure stops when the residual trajectory exceeds % for the first time this value. % Default value is '', which means to rely on general rules @@ -250,28 +250,28 @@ % Data Types - double % % msg : Level of output to display. Scalar. It controls whether -% to display or not messages on the screen -% If msg==1 (default) messages are displayed on the screen about -% step in which signal took place +% to display or not messages on the screen. +% If msg==1 (default), messages are displayed on the screen about +% step in which signal took place, % else no message is displayed on the screen. % Example - 'msg',1 % Data Types - double % -% bsbmfullrank : Dealing with singluar X matrix. Scalar. This option tells +% bsbmfullrank : Dealing with singular X matrix. Scalar. This option tells % how to behave in case subset at step m % (say bsbm) produces a singular X. In other words, % this options controls what to do when rank(X(bsbm,:)) is -% smaller then number of explanatory variables. If -% bsbmfullrank =1 (default) these units (whose number is +% smaller than number of explanatory variables. If +% bsbmfullrank =1 (default), these units (whose number is % say mnofullrank) are constrained to enter the search in -% the final n-mnofullrank steps else the search continues +% the final n-mnofullrank steps, else the search continues % using as estimate of beta at step m the estimate of beta % found in the previous step. % Example - 'bsbmfullrank',1 % Data Types - double % % tag : tags to the plots which are created. -% character or cell array of characters. +% Character or cell array of characters. % This option enables to add a tag to the plots which are % created. The default tag names are: % fsr_mdrplot for the plot of mdr based on all the @@ -281,7 +281,7 @@ % fsr_resuperplot for the plot of resuperimposed envelopes. The % first plot with 4 panel of resuperimposed envelopes has % tag fsr_resuperplot1, the second fsr_resuperplot2 ... -% If tag is character or a cell of characters of length 1, +% If tag is a character or a cell of characters of length 1, % it is possible to specify the tag for the plot of mdr % based on all the observations; % If tag is a cell of length 2 it is possible to control @@ -298,17 +298,17 @@ % out: structure which contains the following fields % % out.ListOut = k x 1 vector containing the list of the units declared as -% outliers or NaN if the sample is homogeneous +% outliers or NaN if the sample is homogeneous. % out.outliers = out.ListOut. This field is added for homogeneity with the % other robust estimators. % out.beta = Matrix containing estimated beta coefficients, -% standard errors, t-stat and p-values +% standard errors, t-stat and p-values. % The content of matrix out.beta is as follows: % 1st col = beta coefficients % The order of the beta coefficients is as follows: % 1) trend elements (if present). If the trend is -% of order two there are r+1 coefficients if the -% intercept is present otherwise there are just r +% of order two, there are r+1 coefficients if the +% intercept is present; otherwise, there are just r % components; % 2) linear part of seasonal component 2, 4, 6, ..., % s-2, s-1 coefficients (if present); @@ -317,12 +317,14 @@ % on the time series under study (X); % 4) non linear part of seasonal component, that is % varying amplitude. If varying amplitude is of order -% k there are k coefficients (if present); -% 5) level shift component (if present). In this case +% k, there are k coefficients (if present); +% 5) level shift component (if present). In this +% case, % there are two coefficients, the second (which is -% also the last element of vector beta) is an integer +% also the last element of vector beta) is an +% integer, % which specifies the time in which level shift takes -% place and the first (which is also the penultime +% place and the first (which is also the penultimate % element of vector beta) is a real number which % identifies the magnitude of the upward (downward) % level shift; @@ -340,11 +342,11 @@ % Exflag : Reason nlinfit stopped. Integer matrix. % (n-init+1) x 2 matrix containing information about the % result of the maximization procedure. -% If the model is non linear out.Exflag(i,2) is equal to 1 +% If the model is non linear, out.Exflag(i,2) is equal to 1 % if at step out.Exflag(i,1) the maximization procedure did not produce % warnings or the warning was different from -% "ILL Conditiioned Jacobian". For any other warning -% which is produced (for example, +% "ILL Conditioned Jacobian". For any other warning +% that is produced (for example, % "Overparameterized", "IterationLimitExceeded", % 'MATLAB:rankDeficientMatrix") out.Exflag(i,2) is equal % to -1; @@ -353,7 +355,7 @@ % REMARK: in every step the new subset is compared with the % old subset. Un contains the unit(s) present in the new % subset but not in the old one. -% Un(1,2) for example contains the unit included in step +% Un(1,2), for example, contains the unit included in step % init+1. % Un(end,2) contains the units included in the final step % of the search. @@ -362,18 +364,18 @@ % First row contains quantiles 1 99 99.9 99.99 99.999. % Second row contains the frequency distribution. % out.constr = This output is produced only if the search found at a -% certain step X is a singular matrix. In this case the +% certain step X is a singular matrix. In this case, the % search runs in a constrained mode, that is including the % units which produced a non singular matrix in the last n-constr % steps. out.constr is a vector which contains the list of % units which produced a singular X matrix % out.Exflag = Reason nlinfit stopped. Integer matrix. % (n-init+1) x 2 matrix containing information about the -% result of the maximization procedure. -% If the model is non linear out.Exflag(i,2) is equal to 1 +% result of the maximization procedure. +% If the model is non linear, out.Exflag(i,2) is equal to 1; % if at step out.Exflag(i,1) the maximization procedure did not produce % warnings or the warning was different from -% "ILL Conditiioned Jacobian". For any other warning +% "ILL Conditioned Jacobian". For any other warning % which is produced (for example, % "Overparameterized", "IterationLimitExceeded", % 'MATLAB:rankDeficientMatrix") out.Exflag(i,2) is equal @@ -456,7 +458,7 @@ % A time series of 100 observations is simulated from a model which % contains no trend, a linear time varying seasonal component with % three harmonics, no explanatory variables and a signal to noise ratio - % egual to 20 + % equal to 20. rng(1) model=struct; model.trend=[]; @@ -481,7 +483,7 @@ % A time series of 100 observations is simulated from a model which % contains no trend, a linear time varying seasonal component with % three harmonics, no explanatory variables and a signal to noise ratio - % egual to 20 + % equal to 20 rng(1) model=struct; model.trend=[]; @@ -507,7 +509,7 @@ % A time series of 100 observations is simulated from a model which % contains no trend, a linear time varying seasonal component with % three harmonics, no explanatory variables and a signal to noise ratio - % egual to 20 + % equal to 20. rng(1) model=struct; model.trend=[]; @@ -538,7 +540,7 @@ % A time series of 100 observations is simulated from a model which % contains no trend, a linear time varying seasonal component with % three harmonics, no explanatory variables and a signal to noise ratio - % egual to 20 + % equal to 20. rng(1) model=struct; model.trend=[]; @@ -558,7 +560,7 @@ model1.s=12; % monthly time series model1.seasonal=104; model1.lshift=-1; - % Automatically serch for outliers and level shift + % Automatically search for outliers and level shift out=FSRts(y,'model',model1,'msg',0); %} @@ -571,7 +573,7 @@ init=floor(0.5*(T+1)); % Set up values for default model -% Set up values for default model + modeldef =struct; modeldef.trend =1; % linear trend modeldef.s =12; % monthly time series @@ -653,7 +655,7 @@ if length(mdr)>=T/2 disp('More than half of the observations produce a singular X matrix') disp('X is badly defined') - disp('If you wish to run the procedure using for updating the values of beta of the last step in which there was full rank use option bsbmfullrank=0') + disp('If you wish to use the values of beta of the last subset in which there was full rank, use option bsbfullrank=0') out.ListOut = setdiff(seq,mdr); else disp('Bad starting point which produced a singular matrix, please restart the search from a different starting point or use option bsbmfullrank=0 ') @@ -712,12 +714,12 @@ % column it contains the value of the minimum deletion residual % monitored in each step of the search - % If mdr has just one columns then one of the following two cases took place: + % If mdr has just one column, then one of the following two cases took place: % isnan(mdr)=1 ==> in this case initial subset was not full rank % mdr has just one column ==> in this case, even if the initial % subset was full rank, the search has found at a certain step % m2*max(y) and min(yhat)<0.5*min(y) + % max(yhat)>2*max(y) and min(yhat)<0.5*min(y). % Make sure that the coefficients of posvarampl are set to 0 if % they are greater than a certain threshold if max(abs(betaout(posvarampl)))>10 @@ -685,7 +685,7 @@ % Store correctly computed b for the case of rank problem bprevious=b; - else % number of independent columns is smaller than number of parameters + else % number of independent columns is smaller than the number of parameters if bsbmfullrank Xb=Xsel(bsb,:); Xbx=Xb; @@ -793,7 +793,7 @@ % likyhat computes fitted values using vector of regression coefficients % beta0. Note that matrices Xtrendf, Xseasof, Seqf, Xf contain n-k rows. % This function is called in the very last step of the procedure when -% routine nlinfit is invoked. Please, note the difference beween likyhat +% routine nlinfit is invoked. Please, note the difference between likyhat % and lik function objyhat=likyhat(beta0,Xtrendf) @@ -829,7 +829,7 @@ if lshift >0 % \beta_(npar+1)* I(t \geq \beta_(npar+2)) where beta_(npar+1) - % is a real number and \beta_(npar+2) is a integer which + % is a real number and \beta_(npar+2) is an integer which % denotes the period in which level shift shows up yhatlshift=beta0(npar+1)*Xlshiftf; @@ -876,7 +876,7 @@ if lshift >0 % \beta_(npar+1)* I(t \geq \beta_(npar+2)) where beta_(npar+1) - % is a real number and \beta_(npar+2) is a integer which + % is a real number and \beta_(npar+2) is an integer which % denotes the period in which level shift shows up yhatlshift=beta0(npar+1)*Xlshift(bsb); else @@ -909,7 +909,7 @@ % % * func is the model function and is a valid function handle that accepts % a single input argument of the same size as theta. - % * theta is vector or matrix of parameter values. If a matrix, each row + % * theta is a vector or matrix of parameter values. If a matrix, each row % represents a different group or observation (see "Grouping Note" below) % and each column represents a different model parameter. % * DerivStep (optional) controls the finite differencing step size. It may @@ -964,7 +964,7 @@ end % When there is only one group, ensure that theta is a row vector so - % that vectoriation works properly. Also ensure that the underlying + % that vectorization works properly. Also ensure that the underlying % function is called with an input with the original size of theta. thetaOriginalSize = size(theta); theta = reshape(theta, 1, []); @@ -1006,7 +1006,7 @@ % ALS computes Alternating Least Squares estimate of beta starting from -% vector beta0. The rows which are used are those specified in global +% vector beta0. The rows, which are used, are those specified in global % variable bsb function [newbeta,exitflag,iter]=ALS(y,beta0,maxiterALS,maxtolALS) @@ -1086,7 +1086,7 @@ % exit from the loop if the new beta has singular values. In % such a case, any intermediate estimate is not reliable and we - % can just keep the initialbeta and initial scale. + % can just keep the initial beta and initial scale. if (any(isnan(newbeta))) newbeta = beta0; exitflag=-1; diff --git a/toolbox/regression/FSRtsmdr.m b/toolbox/regression/FSRtsmdr.m index 4aeac4edc..a3dffd776 100644 --- a/toolbox/regression/FSRtsmdr.m +++ b/toolbox/regression/FSRtsmdr.m @@ -9,8 +9,8 @@ % with T elements, which contains the time series. % % bsb : list of units forming the initial subset. Vector. If bsb=0 -% (default) then the procedure starts with p units randomly -% chosen else if bsb is not 0 the search will start with +% (default), then the procedure starts with p units randomly +% chosen; else if bsb is not 0, the search will start with % m0=length(bsb). p is the total number of regression % parameters which have to be estimated. % @@ -19,7 +19,7 @@ % init : Start of monitoring point. Scalar. % It specifies the point where to initialize the search and % start monitoring required diagnostics. If it is not -% specified it is set equal floor(0.5*(T+1)) +% specified it is set equal floor(0.5*(T+1)). % Example - 'init',100 starts monitoring from step m=100 % Data Types - double % @@ -27,14 +27,14 @@ % which will be used. The model structure contains the following % fields: % model.s = scalar (length of seasonal period). For monthly -% data s=12 (default), for quartely data s=4, ... +% data s=12 (default), for quarterly data s=4, ... % model.trend = scalar (order of the trend component). % trend = 1 implies linear trend with intercept (default), -% trend = 2 implies quadratic trend ... +% trend = 2 implies quadratic trend and so on. % Admissible values for trend are, 0, 1, 2 and 3. % model.seasonal = scalar (integer specifying number of % frequencies, i.e. harmonics, in the seasonal -% component. Possible values for seasonal are +% component). Possible values for seasonal are % $1, 2, ..., [s/2]$, where $[s/2]=floor(s/2)$. % For example: % if seasonal =1 (default) we have: @@ -42,10 +42,10 @@ % if seasonal =2 we have: % $\beta_1 \cos( 2 \pi t/s) + \beta_2 \sin ( 2 \pi t/s) % + \beta_3 \cos(4 \pi t/s) + \beta_4 \sin (4 \pi t/s)$. -% Note that when $s$ is even the sine term disappears +% Note that when $s$ is even, the sine term disappears % for $j=s/2$ and so the maximum number of % trigonometric parameters is $s-1$. -% If seasonal is a number greater than 100 then it +% If seasonal is a number greater than 100, then it % is possible to specify how the seasonal component % grows over time. % For example, seasonal =101 implies a seasonal @@ -63,9 +63,9 @@ % model.X = matrix of size T-by-nexpl containing the % values of nexpl extra covariates which are likely % to affect y. -% model.posLS = positive integer which specifies to position +% model.posLS = positive integer which specifies the position % to include the level shift component. -% For example if model.posLS =13 then the +% For example, if model.posLS =13 then the % explanatory variable $I(t \geq 13})$ is created. % If this field is not present or if it is empty, % the level shift component is not included. @@ -73,7 +73,7 @@ % values of parameter estimates which have to be used in the % maximization procedure. If model.B is a matrix, % then initial estimates are extracted from the -% first colum of this matrix. If this field is +% first column of this matrix. If this field is % empty or if this field is not present, the % initial values to be used in the maximization % procedure are referred to the OLS parameter @@ -85,7 +85,7 @@ % Remark: the default model is for monthly data with a linear % trend (2 parameters) + seasonal component with just one % harmonic (2 parameters), no additional explanatory -% variables and no level shift that is +% variables and no level shift that is: % model=struct; % model.s=12; % model.trend=1; @@ -93,9 +93,9 @@ % model.X=''; % model.posLS=''; % -% plots : Plot on the screen. Scalar. If equal to one a plot of -% minimum deletion residual appears on the screen with 1%, -% 50% and 99% confidence bands else (default) no plot is +% plots : Plot on the screen. Scalar. If equal to one, a plot of +% minimum deletion residual appears on the screen with 1%, +% 50% and 99% confidence bands, else (default) no plot is % shown. % Example - 'plots',1 % Data Types - double @@ -111,27 +111,27 @@ % % msg : Level of output to display. Scalar. It controls whether to % display or not messages about great interchange on the -% screen If msg==1 (default) -% messages are displayed on the screen -% else no message is displayed on the screen +% screen. If msg==1 (default), +% messages are displayed on the screen, +% else no message is displayed on the screen. % Example - 'msg',1 % Data Types - double % % constr : Constrained search. Vector. r x 1 vector which contains the % list of units which are forced to join the search in the % last r steps. The default is constr=''. No constraint is -% imposed +% imposed. % Example - 'constr',[1:10] forces the first 10 units to join -% the subset in the last 10 steps +% the subset in the last 10 steps. % Data Types - double % % bsbmfullrank :What to do in case subset at step m (say bsbm) produces a % non singular X. Scalar. % This options controls what to do when rank(X(bsbm,:)) is -% smaller then number of explanatory variables. -% If bsbmfullrank = 1 (default is 1) these units (whose number +% smaller than the number of explanatory variables. +% If bsbmfullrank = 1 (default is 1), these units (whose number % is say mnofullrank) are constrained to enter the search in -% the final n-mnofullrank steps else the search continues +% the final n-mnofullrank steps, else the search continues % using as estimate of beta at step m the estimate of beta % found in the previous step. % Example - 'bsbmfullrank',1 @@ -140,10 +140,10 @@ % bsbsteps : Save the units forming subsets. Vector. It specifies for % which steps of the fwd search it % is necessary to save the units forming subsets. If bsbsteps -% is 0 we store the units forming subset in all steps. The -% default is store the units forming subset in all steps if -% T<=5000, else to store the units forming subset at steps -% init and steps which are multiple of 100. For example, as +% is 0, we store the units forming subset in all steps. The +% default is: store the units forming subset in all steps if +% T<=5000; else to store the units forming subset at steps +% init and steps which are multiples of 100. For example, as % default, if T=753 and init=6, % units forming subset are stored for % m=init, 100, 200, 300, 400, 500 and 600. @@ -159,22 +159,22 @@ % % Output: % -% mdr: T -init x 2 matrix which contains the monitoring of minimum +% mdr: T-init x 2 matrix which contains the monitoring of minimum % deletion residual at each step of the forward search. % 1st col = fwd search index (from init to T-1). % 2nd col = minimum deletion residual. % REMARK: if in a certain step of the search matrix is % singular, this procedure checks how many observations -% produce a singular matrix. In this case mdr is a column +% produce a singular matrix. In this case, mdr is a column % vector which contains the list of units for which matrix X % is non singular. % Un: Units included in each step. Matrix. -% (T-init) x 11 Matrix which contains the unit(s) included +% (T-init) x 11: Matrix which contains the unit(s) included % in the subset at each step of the search. % REMARK: in every step the new subset is compared with the % old subset. Un contains the unit(s) present in the new % subset but not in the old one. -% Un(1,2) for example contains the unit included in step +% Un(1,2), for example, contains the unit included in step % init+1. % Un(end,2) contains the units included in the final step % of the search. @@ -192,24 +192,24 @@ % value for the other steps; % T-th row has number Tn in correspondence of the steps in % which unit T is included inside subset and a missing -% value for the other steps +% value for the other steps. % The size of matrix BB is T x (T-init+1) if option input -% bsbsteps is 0 else the size is T-by-length(bsbsteps). -% Bols: beta coefficents. Matrix. -% (T-init+1) x (p+1) matrix containing the monitoring of +% bsbsteps is 0, else the size is T-by-length(bsbsteps). +% Bols: beta coefficients. Matrix. +% (T-init+1) x (p+1): matrix containing the monitoring of % estimated beta coefficients in each step of the forward % search. % S2: S2 and R2. Matrix. -% (T-init+1) x 3 matrix containing the monitoring of S2 (2nd -% column)and R2 (third column) in each step of the forward +% (T-init+1) x 3: matrix containing the monitoring of S2 (2nd +% column) and R2 (third column) in each step of the forward % search. % Exflag : Reason nlinfit stopped. Integer matrix. -% (T-init+1) x 2 matrix containing information about the -% result of the maximization procedure. -% If the model is non linear out.Exflag(i,2) is equal to 1 -% if at step out.Exflag(i,1) the maximization procedure did not produce +% (T-init+1) x 2: matrix containing information about the +% result of the maximization procedure. +% If the model is non linear, out.Exflag(i,2) is equal to 1. +% If at step out.Exflag(i,1) the maximization procedure did not produce % warnings or the warning was different from -% "ILL Conditiioned Jacobian". For any other warning +% "ILL Conditioned Jacobian". For any other warning % which is produced (for example, % "Overparameterized", "IterationLimitExceeded", % 'MATLAB:rankDeficientMatrix") out.Exflag(i,2) is equal @@ -312,7 +312,7 @@ 118 140 166 194 201 229 278 306 336 337 405 432 ]; % Dec y=(y(:)); % Compute minimum deletion residual and analyze the units entering - % subset in each step of the fwd search (matrix Un). As is well known, + % subset in each step of the fwd search (matrix Un). As is well known, % the FS provides an ordering of the data from those most in agreement % with a suggested model (which enter the first steps) to those least in % agreement with it (which are included in the final steps). @@ -476,7 +476,7 @@ plots=options.plots; % Get model parameters -trend = model.trend; % get kind of trend +trend = model.trend; % get kind of trend s = model.s; % get periodicity of time series seasonal = model.seasonal; % get number of harmonics @@ -521,8 +521,8 @@ for j=1:seasonal Xseaso(:,2*j-1:2*j)=[cos(j*2*pi*seq/s) sin(j*2*pi*seq/s)]; end - % Remark: when s is even the sine term disapperas for j=s/2 and so the - % maximum number of trigonometric terms is s-1 + % Remark: when s is even, the sine term disappears for j=s/2 and so the + % maximum number of trigonometric terms is s-1. if seasonal==(s/2) Xseaso=Xseaso(:,1:end-1); end @@ -536,13 +536,13 @@ X=model.X; isemptyX=isempty(X); if isemptyX - % nexpl = number of potential explanatory variables + % nexpl = number of potential explanatory variables. nexpl=0; else nexpl=size(X,2); end -% Define the explanatory variable associated to the level shift component +% Define the explanatory variable associated to the level shift component. if lshift>0 % Xlshift = explanatory variable associated with % level shift Xlshift is 0 up to lsh-1 and 1 from @@ -681,13 +681,13 @@ % search. The first column of Bols contains the fwd search index Bols=[(init1:T)' NaN(T-init1+1,p)]; %initial value of beta coefficients is set to NaN -% S2 = (n-init1+1) x 3 matrix which will contain: +% S2 = (n-init1+1) x 3: matrix which will contain: % 1st col = fwd search index % 2nd col = S2= \sum e_i^2 / (m-p) % 3rd col = R^2 S2=[(init1:T)' NaN(T-init1+1,2)]; %initial value of S2 (R2) is set to NaN -% mdr = (n-init1-1) x 2 matrix which will contain min deletion residual +% mdr = (n-init1-1) x 2: matrix which will contain min deletion residual % among nobsb r_i^* mdr=[(init1:T-1)' NaN(T-init1,1)]; %initial value of mdr is set to NaN @@ -699,13 +699,14 @@ BB = NaN(T,T-init1+1); else % The number of columns of matrix BB is equal to the number of steps - % for which bsbsteps is greater or equal than init1 + % for which bsbsteps is greater or equal than init1. bsbsteps=bsbsteps(bsbsteps>=init1); BB = NaN(T,length(bsbsteps)); end % ij = index which is linked with the columns of matrix BB. During the -% search every time a subset is stored inside matrix BB ij increases by one +% search every time a subset is stored inside matrix BB ij increases by +% one. ij=1; @@ -714,7 +715,7 @@ Un = cat(2 , (init1+1:T)' , NaN(T-init1,10)); % Initialize matrix which stores in each step the integer identifying the -% reason why the algorithm terminated +% reason why the algorithm terminated. Exflag=[(ini0:T)',ones(T-ini0+1,1)]; Xb=Xsel(bsb,:); @@ -753,7 +754,7 @@ end % Note that Xsel is the X matrix of the linearized version if the - % model is non linear (that is it contains time varying amplitude) + % model is non linear (that is, it contains time varying amplitude) tmp = zscore(Xsel(bsb,2:end)); NoRankProblem=(rank(tmp) == size(Xsel,2)-1 ); @@ -819,7 +820,7 @@ invXX=covB/s2; % Now compute vector yhat for all the observations - % using input vector betaout + % using input vector betaout bsb=seq; yhat=lik(betaout); @@ -838,7 +839,7 @@ % Check whether the estimate of b which has come out is % reasonable. An estimate of b is called unreasonable if - % max(yhat)>2*max(y) and min(yhat)<0.5*min(y) + % max(yhat)>2*max(y) and min(yhat)<0.5*min(y) % Make sure that the coefficients of posvarampl are set to 0 if % they are greater than a certain threshold if max(abs(betaout(posvarampl)))>10 @@ -966,7 +967,7 @@ % ord=sortrows(r,2); [~,ord]=sort(r(:,2)); - % bsb= units forming the new subset + % bsb= units forming the new subset bsb=ord(1:(mm+1),1); yb=y(bsb); % subset of y @@ -1026,7 +1027,7 @@ % likyhat computes fitted values using vector of regression coefficients % beta0. Note that matrices Xtrendf, Xseasof, Seqf, Xf contain n-k rows. % This function is called in the very last step of the procedure when -% routine nlinfit is invoked. Please, note the difference beween likyhat +% routine nlinfit is invoked. Please, note the difference between likyhat % and lik function objyhat=likyhat(beta0,Xtrendf) @@ -1142,7 +1143,7 @@ % % * func is the model function and is a valid function handle that accepts % a single input argument of the same size as theta. - % * theta is vector or matrix of parameter values. If a matrix, each row + % * theta is vector or matrix of parameter values. If it's a matrix, each row % represents a different group or observation (see "Grouping Note" below) % and each column represents a different model parameter. % * DerivStep (optional) controls the finite differencing step size. It may @@ -1191,13 +1192,13 @@ classname = class(theta); % Handle optional arguments, starting with y0 since it will be needed to - % determine the appropriate size for a default groups. + % determine the appropriate size for a default group. if nargin < 4 || isempty(y0) y0 = func(theta); end % When there is only one group, ensure that theta is a row vector so - % that vectoriation works properly. Also ensure that the underlying + % that vectorization works properly. Also ensure that the underlying % function is called with an input with the original size of theta. thetaOriginalSize = size(theta); theta = reshape(theta, 1, []); @@ -1263,7 +1264,7 @@ % OLS to estimate coefficients of trend + expl variables + non lin coeff of % seasonal + coefficient of fixed level shift - % trlshift is the matrix of explanatory variables + % tr_expl_nls_lshift is the matrix of explanatory variables if isemptyX if lshift>0 tr_expl_nls_lshift=[Xtrend(bsb,:) bsxfun(@times,at,Seq(bsb,2:varampl+1)) Xlshift(bsb)]; @@ -1319,7 +1320,7 @@ % exit from the loop if the new beta has singular values. In % such a case, any intermediate estimate is not reliable and we - % can just keep the initialbeta and initial scale. + % can just keep the initial beta and initial scale. if (any(isnan(newbeta))) newbeta = beta0; exitflag=-1; diff --git a/toolbox/regression/GYfilt.m b/toolbox/regression/GYfilt.m index d42d9bb35..56a3d8f66 100644 --- a/toolbox/regression/GYfilt.m +++ b/toolbox/regression/GYfilt.m @@ -18,14 +18,14 @@ % Data Types - double % % centering: centering the data. Boolean. -% If centering is true input data are preliminarly centered. -% The defalt value of centering is true. +% If centering is true, input data are preliminary centered. +% The default value of centering is true. % Example - 'centering',false % Data Types - logical % % iterating: iterative procedure. Boolean. -% If Boolean is true then an iterative adaptive procedure is -% applied. The defalt value of iterating is true. +% If Boolean is true, then an iterative adaptive procedure is +% applied. The default value of iterating is true. % Example - 'iterating',false % Data Types - logical % @@ -130,7 +130,7 @@ end -% Inner fucntion gyfiltaux +% Inner function gyfiltaux function vna=gyfiltaux(v, alpha) [v,vorder] = sort(v); diff --git a/toolbox/regression/LTSts.m b/toolbox/regression/LTSts.m index 414d0876c..27f8fe401 100644 --- a/toolbox/regression/LTSts.m +++ b/toolbox/regression/LTSts.m @@ -19,14 +19,14 @@ % % % bdp : breakdown point. Scalar. It measures the fraction of outliers -% the algorithm should resist. In this case any value greater -% than 0 but smaller or equal than 0.5 will do fine. Please +% the algorithm should resist. In this case, any value greater +% than 0, but smaller or equal than 0.5, will do fine. Please % specify h or bdp, but not both. % Example - 'bdp',0.4 % Data Types - double % % conflev : Confidence level. Scalar. Scalar between 0 and 1 containing -% Confidence level which is used to declare units as +% confidence level which is used to declare units as % outliers. Usually conflev=0.95, 0.975 0.99 (individual % alpha) or 1-0.05/n, 1-0.025/n, 1-0.01/n (simultaneous % alpha). Default value is 0.975. @@ -34,7 +34,7 @@ % Data Types - double % % dispresults : Display results of final fit. Boolean. If dispresults is -% true, labels of coefficients, estimated coefficients, +% true, labels of coefficients, estimated coefficients, % standard errors, tstat and p-values are shown on the % screen in a fully formatted way. The default value of % dispresults is false. @@ -45,10 +45,10 @@ % h : The number of observations that determined the least % trimmed squares estimator. Scalar. h is an integer greater % than p (number of columns of matrix X including the -% intercept but smaller then n. If the purpose is outlier -% detection than h does not have to be smaller than +% intercept, but smaller than n. If the purpose is outlier +% detection, then h does not have to be smaller than % [0.5*(T+p+1)]. The default value of h is [0.75*T]. Note -% that if h is supplied input argument bdp is ignored. +% that if h is supplied, input argument bdp is ignored. % Example - 'h',round(n*0.75) % Data Types - double % @@ -61,22 +61,22 @@ % Data Types - boolean % % lshiftlocref: Parameters for local shift refinement. Structure. -% This option is used just if model.lshift is greater then 0. -% In order to precisely identify level shift position it is +% This option is used just if model.lshift is greater than 0. +% In order to precisely identify level shift position, it is % necessary to consider a local sum of squares varying the % position of the level shift around the first tentative % position keeping all the other parameters fixed. This % structure contains the following fields: % lshiftlocref.wlength = scalar greater than 0 which % identifies the length of the window. The default value -% is 15, that is the tentative level shift position +% is 15, that is the tentative level shift position; % varies from tl-15, tl-15, ..., tl+14, tl+15, where tl is % the best preliminary tentative level shift position. % lshiftlocref.typeres = scalar which identifies the type of % residuals to consider. If typerres =1, the local % residuals sum of squares is based on huberized (scaled) % residuals (this is the default -% choice) else raw residuals are used. +% choice), else raw residuals are used. % lshiftlocref.huberc= tuning constant for Huber estimator just % in case lshiftlocref.typeres=1. The default value is 2. % Example - 'lshiftlocref',lshiftlocref.typeres=2 @@ -101,7 +101,7 @@ % The default value is 1e-6; % lts.reftolbestr = scalar. Default value of tolerance for % the refining steps for each of the best -% subsets The default value is 1e-8. +% subsets. The default value is 1e-8. % Example - 'lts',lts % Data Types - struct % Remark: if lts is an empty value all default values of @@ -111,7 +111,7 @@ % which will be used. The model structure contains the following % fields: % model.s = scalar (length of seasonal period). For monthly -% data s=12 (default), for quartely data s=4, ... +% data s=12 (default), for quarterly data s=4, ... % model.trend = scalar (order of the trend component). % trend = 0 implies no trend; % trend = 1 implies linear trend with intercept (default); @@ -131,10 +131,10 @@ % if seasonal =2 we have: % $\beta_1 \cos( 2 \pi t/s) + \beta_2 \sin ( 2 \pi t/s) % + \beta_3 \cos(4 \pi t/s) + \beta_4 \sin (4 \pi t/s)$. -% Note that when $s$ is even the sine term disappears +% Note that when $s$ is even, the sine term disappears % for $j=s/2$ and so the maximum number of % trigonometric parameters is $s-1$. -% If seasonal is a number greater than 100 then it +% If seasonal is a number greater than 100, then it % is possible to specify how the seasonal component % grows over time. % For example, seasonal = 101 implies a seasonal @@ -166,10 +166,10 @@ % then it is associated to the positions of level % shifts which have to be considered. The most % significant one is included in the fitted model. -% For example if model.lshift =[13 20 36] a +% For example, if model.lshift =[13 20 36] a % tentative level shift is imposed in position % $t=13$, $t=20$ and $t=36$. The most significant -% among these positions in included in the final +% among these positions is included in the final % model. In other words, the following extra % parameters are added to the final model: % $\beta_{LS1}* I(t \geq \beta_{LS2})$ where @@ -180,7 +180,7 @@ % function. % As a particular case, if model.lshift =13 then a % level shift in position $t=13$ is added to the -% model. In other words the following additional +% model. In other words, the following additional % parameters are added: $\beta_{LS1}* I(t \geq 13)$ % where $\beta_{LS1}$ is a real number and $I$ % denotes the indicator function. @@ -213,7 +213,7 @@ % Remark: the default model is for monthly data with a linear % trend (2 parameters) + seasonal component with just one % harmonic (2 parameters), no additional explanatory -% variables and no level shift that is +% variables and no level shift that is: % model=struct; % model.s=12; % model.trend=1; @@ -225,20 +225,20 @@ % % msg : Messages on the screen. Boolean. % Scalar which controls whether to display or not messages -% on the screen. If msg==true (default) messages are displayed on +% on the screen. If msg==true (default), messages are displayed on % the screen about estimated time to compute the estimator % and the warnings about 'MATLAB:rankDeficientMatrix', % 'MATLAB:singularMatrix' and 'MATLAB:nearlySingularMatrix' -% are set to off else no message is displayed on the screen +% are set to off, else no message is displayed on the screen. % Example - 'msg',true % Data Types - logical % %nbestindexes : position of the best solutions. Positive integer. For each -% tentative level shift solution, it is interesenting to +% tentative level shift solution, it is interesting to % understand whether best solutions of target function come % from subsets associated with current level shift solution % or from best solutions from previous tentative level shift -% position. The indexes from 1 to lts.bestr/2 are associated +% position. The indexes from 1 to lts.bestr/2 are associated % with subsets just extracted. The indexes from lts.bestr/2+1 % to lts.bestr are associated with best solutions from % previous tentative level shift. More precisely: @@ -248,13 +248,13 @@ % from previous tentative level shift; % ... % nbestindexes is an integer which specifies how many indexes -% we want to store. The default value of nbestindexes is 3. +% we want to store. The default value of nbestindexes is 3. % Example - 'nbestindexes',5 % Data Types - double % % nocheck: Check input arguments. Boolean. If nocheck is equal to true no % check is performed on matrix y and matrix X. Notice that y -% and X are left unchanged. In other words the additioanl +% and X are left unchanged. In other words, the additional % column of ones for the intercept is not added. As default % nocheck=false. The controls on h, bdp and nsamp still remain. % Example - 'nocheck',true @@ -263,7 +263,7 @@ % nsamp : number of subsamples to extract. Scalar or vector of length 2. % Vector of length 1 or 2 which controls the number of % subsamples which will be extracted to find the robust -% estimator. If lshift is not equal to 0 then nsamp(1) +% estimator. If lshift is not equal to 0, then nsamp(1) % controls the number of subsets which have to be extracted % to find the solution for t=lshift(1). nsamp(2) controls the % number of subsets which have to be extracted to find the @@ -279,7 +279,7 @@ % is to extract [nsamp/2] subsamples for t=lshift(1), % lshift(2), ... Therefore, for example, in order to extract % 600 subsamples for t=lshift(1) and 300 subsamples for t= -% lshift(2) ... you can use nsamp =600 or nsamp=[600 300]. +% lshift(2) ... you can use nsamp=600 or nsamp=[600 300]. % The default value of nsamp is 1000; % Example - 'nsamp',500 % Data Types - double @@ -300,11 +300,11 @@ % Example - 'reftolALS',1e-05 % Data Types - double % -%SmallSampleCor:Small sample correction factor to control empirical size of -% the test. Scalar equal to 1 or 2 (default) or 3 or 4. -% - If SmallSampleCor=1 in the reweighting step the nominal +%SmallSampleCor: Small sample correction factor to control empirical size of +% the test. Scalar equal to 1 or 2 (default) or 3 or 4. +% - If SmallSampleCor=1 in the reweighting step, the nominal % threshold based on $\chi^2_{0.99}$ is multiplied by the -% small sample correction factor which guarrantees that the +% small sample correction factor which guarantees that the % empirical size of the test is equal to the nominal size. % Given that the correction factors were obtained through % simulation for a linear model, the number of explanatory @@ -319,7 +319,7 @@ % - If SmallSampleCor =2 Gervini and Yohai procedure is called % with 'iterating' false and 'alpha' 0.99 is invoked, that is: % weights=GYfilt(stdres,'iterating',false,'alpha',0.99); -% - If SmallSampleCor =3 Gervini and Yohai procedure called +% - If SmallSampleCor =3 Gervini and Yohai procedure is called % with 'iterating' true and 'alpha' 0.99 is invoked, that is: % weights=GYfilt(stdres,'iterating',true,'alpha',0.99); % - If SmallSampleCor =4 $\chi^2_{0.99}$ threshold is used that is: @@ -337,13 +337,13 @@ % % plots : Plots on the screen. Scalar. % If plots = 1, a two panel plot will be shown on the screen. -% The upper panel contains the orginal time series with +% The upper panel contains the original time series with % fitted values. The bottom panel will contain the plot % of robust residuals against index number. The confidence % level which is used to draw the horizontal lines associated % with the bands for the residuals is specified in input -% option conflev. If conflev is missing a nominal 0.975 -% confidence interval will be used. If plots =2 the following +% option conflev. If conflev is missing, a nominal 0.975 +% confidence interval will be used. If plots =2, the following % additional plots will be shown on the screen. % 1) Boxplot of the distribution of the lts.bestr values of % the target function for each tentative level shift position; @@ -377,13 +377,13 @@ % % out.B = Matrix containing estimated beta coefficients, % (including the intercept when options.intercept=true) -% standard errors, t-stat and p-values +% standard errors, t-stat and p-values. % The content of matrix B is as follows: -% 1st col = beta coefficients +% 1st col = beta coefficients. % The order of the beta coefficients is as follows: % 1) trend elements (if present). If the trend is -% of order two there are r+1 coefficients if the -% intercept is present otherwise there are just r +% of order two, there are r+1 coefficients if the +% intercept is present, otherwise there are just r % components; % 2) linear part of seasonal component 2, 4, 6, ..., % s-2, s-1 coefficients (if present); @@ -395,12 +395,12 @@ % component. % 4) non linear part of seasonal component, that is % varying amplitude. If varying amplitude is of order -% k there are k coefficients (if present); +% k, there are k coefficients (if present); % 5) level shift component (if present). In out.B it % is shown just the real number which identifies the % magnitude of the upward (downward) level shift. % The integer which specifies the time in which -% level shift takes place is given in output +% level shift takes place, is given in output % out.posLS. % 2nd col = standard errors; % 3rd col = t-statistics; @@ -411,22 +411,22 @@ % out.bs = Vector containing the units with the smallest p+k % squared residuals before the reweighting step, % where p is the total number of the parameters in -% the model and p+k is smallest number of units such +% the model and p+k is the smallest number of units such % that the design matrix is full rank. % out.bs can be used to initialize the forward % search. % out.Hsubset = matrix of size T-by-r % containing units forming best H subset for each -% tentative level shift which is considered. r is -% number of tentative level shift positions whicha re -% considered. For example if model.lshift=[13 21 40] +% tentative level shift which is considered. r is the +% number of tentative level shift positions which are +% considered. For example, if model.lshift=[13 21 40], % r is equal to 3. Units belonging to subset are % given with their row number, units not belonging to -% subset have missing values +% subset have missing values. % This output is present just if input option % model.lshift is not equal to 0. % out.lshift = (row) vector containing level shift positions which -% have been tested. out.lshift =0 means that +% have been tested. out.lshift=0 means that % level position has not been investigated. % out.posLS = scalar associated with best tentative level shift % position. This output is present just if input @@ -452,7 +452,7 @@ % containing local sum of squares of residuals in % order to decide best position of level shift: % 1st col = position of level shift; -% 2nd col = local sum of squares of huberized residuals; +% 2nd col = local sum of squares of Huberized residuals; % 3rd col = local sum of squares of raw residuals. % This output is present just if input option % model.lshift is not equal to 0. @@ -460,7 +460,7 @@ % residuals for all the T units of the original time % series monitored in steps lshift+1, lshift+2, ..., % T-lshift, where lshift+1 is the first tentative -% level shift position, lshift +2 is the second level +% level shift position, lshift+2 is the second level % shift position, and so on. This output is present % just if input option model.lshift is not equal to 0. % out.yhat = vector of fitted values after final (NLS=non linear @@ -484,16 +484,16 @@ % consistent. % out.conflev = confidence level which is used to declare outliers. % Remark: scalar out.conflev will be used to draw the -% horizontal lines (confidence bands) in the plots +% horizontal lines (confidence bands) in the plots. % out.outliers = vector containing the list of the units declared % as outliers using confidence level specified in % input scalar conflev. % out.outliersPval = p-value of the units declared as outliers. -% out.singsub = Number of subsets wihtout full rank. Notice that if +% out.singsub = Number of subsets without full rank. Notice that if % this number is greater than 0.1*(number of -% subsamples) a warning is produced on the screen +% subsamples) a warning is produced on the screen. % out.invXX = $cov(\beta)/\hat \sigma^2$. p-by-p, square matrix. -% If the model is linear out.invXX is equal to +% If the model is linear, out.invXX is equal to % $(X'X)^{-1}$, else out.invXX is equal to $(A'A)^{-1}$ % where $A$ is the matrix of partial derivatives. More % precisely: @@ -534,7 +534,7 @@ % % Optional Output: % -% C : cell containing the indices of the subsamples +% C : cell containing the indices of the subsamples % extracted for computing the estimate (the so called % elemental sets) for each tentative level shift % position. @@ -749,7 +749,7 @@ %{ % Contaminated time series with upward level shift. % Model with linear trend, six harmonics for seasonal component and - % varying amplitude using a linear trend). + % varying amplitude using a linear trend (3). % Load airline data. % 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 y = [112 115 145 171 196 204 242 284 315 340 360 417 % Jan @@ -791,7 +791,7 @@ %{ % Contaminated time series with downward level shift. % Model with linear trend, three harmonics for seasonal component and - % varying amplitude using a linear trend). + % varying amplitude using a linear trend (4). % Load airline data. % 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 y = [112 115 145 171 196 204 242 284 315 340 360 417 % Jan @@ -849,7 +849,7 @@ y=(y(:)); y1=log(y); % Model with linear trend, two harmonics for seasonal component and - % varying amplitude using a linear trend). + % varying amplitude using a linear trend (5). model=struct; model.trend=1; % linear trend model.s=12; % monthly time series @@ -903,7 +903,7 @@ lshiftlocref=struct; % Set window length for local refinement. lshiftlocref.wlength=10; - % Set tuning constant to use insde Huber rho function + % Set tuning constant to use inside Huber rho function lshiftlocref.huberc=1.5; % Estimate the parameters [out]=LTSts(y1,'model',model,'nsamp',500,... @@ -953,7 +953,7 @@ lshiftlocref=struct; % Set window length for local refinement. lshiftlocref.wlength=10; - % Set tuning constant to use insde Huber rho function + % Set tuning constant to use inside Huber rho function lshiftlocref.huberc=1.5; % Estimate the parameters [out, varargout]=LTSts(y1,'model',model,'nsamp',500,... @@ -1003,7 +1003,7 @@ lshiftlocref=struct; % Set window length for local refinement. lshiftlocref.wlength=10; - % Set tuning constant to use insde Huber rho function + % Set tuning constant to use inside Huber rho function lshiftlocref.huberc=1.5; close all % Estimate the parameters @@ -1206,12 +1206,12 @@ % Get model parameters s = model.s; % get periodicity of time series -trend = model.trend; % get kind of trend +trend = model.trend; % get kind of trend seasonal = model.seasonal; % get number of harmonics lshift = model.lshift; % get level shift -% nbestindexes = indexes of the best nbestindexes solutions for each -% tentative position of level shift +% nbestindexes = indexes of the best nbestindexes solutions for each +% tentative position of level shift. nbestindexes=options.nbestindexes; % Check if the optional user parameters are valid. @@ -1257,8 +1257,8 @@ for j=1:seasonal Xseaso(:,2*j-1:2*j)=[cos(j*2*pi*seq/s) sin(j*2*pi*seq/s)]; end - % Remark: when s is even the sine term disapperas for j=s/2 and so the - % maximum number of trigonometric terms is s-1 + % Remark: when s is even the sine term disappears for j=s/2 and so the + % maximum number of trigonometric terms is s-1. if seasonal==(s/2) Xseaso=Xseaso(:,1:end-1); end @@ -1351,16 +1351,16 @@ otherind=otherind(1:end-1); end -% If the number of all possible subsets is <10000 the default is to extract +% If the number of all possible subsets is <10000, the default is to extract % all subsets otherwise just 10000. Notice that we use bc, a fast version -% of nchoosek. One may also use the approximation +% of function nchoosek. One may also use the approximation % floor(exp(gammaln(n+1)-gammaln(n-p+1)-gammaln(pini+1))+0.5) ncomb=bc(T-nummissing,pini); % And check if the optional user parameters are reasonable. -% Check h and bdp The user has only specified h: no need to specify bdp. +% Check h and bdp. The user has only specified h: no need to specify bdp. if chktrim==1 if options.h < hmin error('FSDA:LTSts:WrongInput',['The LTS must cover at least ' int2str(hmin) ' observations.']) @@ -1369,7 +1369,7 @@ end bdp=1-options.h/T; - % the user has only specified bdp: h is defined accordingly + % the user has only specified bdp: h is defined accordingly. elseif chktrim==2 bdp=options.bdp; if bdp < 0 @@ -1491,13 +1491,13 @@ if lshiftYN==1 % If a level shift is present, it is necessary to % reestimate a linear model each time with a different - % level shift and, if take the one which minimizes the target + % level shift, and if so take the one which minimises the target % function (residual sum of squares/2 = negative log - % likelihood) + % likelihood). % With the instruction below we want to make sure that LSH is a row - % vector + % vector. LSH = lshift(:)'; - % total number of subsets to pass to procedure subsets + % total number of subsets to pass to procedure subsets. ncombLSH=bc(T-1-nummissing,pini+1); else @@ -1508,7 +1508,7 @@ % lLSH = length of tentative level shift positions lLSH=length(LSH); -% ScaleLSH= estimate of the squared scale for each value of LSH which has been +% numscale2LSH=estimate of the squared scale for each value of LSH which has been % considered numscale2LSH=[LSH' inf(lLSH,2)]; @@ -1516,12 +1516,12 @@ yhatrobLSH=zeros(T,lLSH); % ilsh is a counter which is linked to the rows of LSH -% ilsh=0; + bestrdiv2=round(bestr/2); -% allnumscale2 will contain the best best estimates of the target function +% allnumscale2 will contain the best estimates of the target function % for a tentative value of level shift position allnumscale2=zeros(bestr,1); @@ -1538,7 +1538,7 @@ % Weights = units forming subset for the solution associated to the minimum -% scale for each value of LSH +% scale for each value of LSH. Weights=false(T,lLSH); brobLSH=zeros(p,lLSH); @@ -1561,18 +1561,18 @@ end % WEIisum = matrix which will contain the number of times each units has -% been included into the best h-subset after two iterations +% been included into the best h-subset after two iterations. WEIisum=zeros(T,lLSH); -% WEIisumbest10 = matrix which will contain the number of times each units has -% been included into the best h-subsets among the bestr/2 best +% WEIibest10sum = matrix which will contain the number of times each units has +% been included into the best h-subsets among the bestr/2 best. WEIibest10sum=zeros(T,lLSH); WEIibestrdiv2=zeros(T,bestr); RES = nan(T,lLSH); % Consistency factor based on the variance of the truncated normal -% distribution. 1-h/n=trimming percentage Compute variance of the truncated +% distribution. 1-h/n=trimming percentage compute variance of the truncated % normal distribution. if h0 % In presence of 6 harmonics, the last one is just made up of a single - % variable, therefore the p value is just the p value of the assocaited + % variable, therefore the p value is just the p value of the associated % t-stat pval=B(ntrend+nseaso,4); end @@ -2822,7 +2822,7 @@ % OLS to estimate coefficients of trend + expl variables + non lin coeff of % seasonal + coefficient of fixed level shift - % trlshift is the matrix of explanatory variables + % tr_expl_nls_lshift is the matrix of explanatory variables XtrendXbsbXseasonXlshift(:,indnlseaso)=at.*Seqbsbvarampl; % b0145 = coefficients of intercept trend + expl var + non @@ -2849,7 +2849,7 @@ % exit from the loop if the new beta has singular values. In % such a case, any intermediate estimate is not reliable and we - % can just keep the initialbeta and initial scale. + % can just keep the initial beta and initial scale. if (any(isnan(newbeta))) newbeta = beta0; exitflag=-1; @@ -2878,7 +2878,7 @@ % OLS to estimate coefficients of trend + expl variables + non lin coeff of % seasonal + coefficient of fixed level shift - % trlshift is the matrix of explanatory variables + % tr_expl_nls_lshift is the matrix of explanatory variables if isemptyX if lshiftYN==1 tr_expl_nls_lshift=[Xtrend(bsb,:) bsxfun(@times,at,Seq(bsb,2:varampl+1)) Xlshift(bsb)]; @@ -2897,7 +2897,7 @@ b0145=tr_expl_nls_lshift\(yin(bsb)-at) ; % Now find new coefficients of linear part of seasonal - % component in the regression of y-trend-expl-lsihft versus + % component in the regression of y_trend_expl_lsihft versus % vector which contains non linear part of seasonal component % which multiplies each column of matrix Xseaso (linear part of % seasonal component) @@ -2931,7 +2931,7 @@ % exit from the loop if the new beta has singular values. In % such a case, any intermediate estimate is not reliable and we - % can just keep the initialbeta and initial scale. + % can just keep the initial beta and initial scale. if (any(isnan(newbeta))) newbeta = beta0; exitflag=-1; @@ -3012,7 +3012,7 @@ % likyhat computes fitted values using vector of regression coefficients % beta0. Note that matrices Xtrendf, Xseasof, Seqf, Xf contain n-k rows. % This function is called in the very last step of the procedure when -% routine nlinfit is invoked. Please, note the difference beween likyhat +% routine nlinfit is invoked. Please, note the difference between likyhat % and lik function objyhat=likyhat(beta0,Xtrendf) @@ -3048,16 +3048,16 @@ if lshiftYN==1 % \beta_(npar+1)* I(t \geq \beta_(npar+2)) where beta_(npar+1) - % is a real number and \beta_(npar+2) is a integer which + % is a real number and \beta_(npar+2) is an integer which % denotes the period in which level shift shows up yhatlshift=beta0(npar+1)*Xlshiftf; - % objhat = fitted values from trend (yhattrend), (time varying) seasonal + % objyhat = fitted values from trend (yhattrend), (time varying) seasonal % (yhatseaso), explanatory variables (yhatX) and level shift % component (yhatlshift) objyhat=yhattrend+yhatseaso+yhatX+yhatlshift; else - % objhat = fitted values from trend (yhattrend), (time varying) seasonal + % objyhat = fitted values from trend (yhattrend), (time varying) seasonal % (yhatseaso), explanatory variables (yhatX) and level shift % component (yhatlshift) objyhat=yhattrend+yhatseaso+yhatX; @@ -3098,7 +3098,7 @@ % step).It is the numerator of the estimate of the % squared scale. % weights : n x 1 vector. Weights assigned to each observation - % In this case weights are 0,1. 1 for the units + % In this case, weights are 0,1. 1 for the units % associated with the smallest h squared residuals % from final iteration 0 for the other units. % exitflag : scalar which informs about convergence. exitflag = @@ -3204,7 +3204,7 @@ newb = Xseld(bsb,:)\ y(bsb); % yhat = vector of fitted values for all obs yhat=Xseld*newb; - % newbeta = new estimate of beta just using units + % newbeta = new estimate of beta just using units % forming subset (newb also contains as last element % the position of level shift) newbeta=[newb; initialbeta(end)]; @@ -3224,7 +3224,7 @@ end - % Call lik with bsb=seq in order to create the vector + % Call lik with bsb=seq in order to create the vector % of fitted values (yhat) using all the observations bsb=seq; lik(newbeta); @@ -3235,7 +3235,7 @@ % reftol) betadiff = norm(beta - newbeta,1) / norm(beta,1); - % exit from the loop if new beta contains nan In + % exit from the loop if new beta contains NaN. In % such a case, any intermediate estimate is not reliable and we % can just keep the initialbeta and initial scale. if (any(isnan(newbeta))) || exitfl ~=0 @@ -3300,8 +3300,8 @@ %outIRWLS.numscale2rw = numscale2; end % weights = the final estimate of the weights for each observation, - % to be stored in outIRWLS.weights. In this case weights are 0,1. 1 - % for the units associated with the units formig subset from final + % to be stored in outIRWLS.weights. In this case, weights are 0,1. 1 + % for the units associated with the units forming subset from final % iteration 0 for the other units. weights=zerT1; weights(bsb)=true; @@ -3369,7 +3369,7 @@ % if msg==true disp('Warning: problem in subfunction corfactorRAW') disp(['Correction factor for covariance matrix based on simulations found =' num2str(rawcorfac)]) - disp('Given that this value is clearly wrong we put it equal to 1 (no correction)') + disp('Given that, this value is clearly wrong, we put it equal to 1 (no correction)') disp('This may happen when n is very small and p is large') % end end @@ -3420,7 +3420,7 @@ % if msg==true disp('Warning: problem in subfunction corfactorREW'); disp(['Correction factor for covariance matrix based on simulations found =' num2str(rewcorfac)]); - disp('Given that this value is clearly wrong we put it equal to 1 (no correction)'); + disp('Given that, this value is clearly wrong, we put it equal to 1 (no correction)'); disp('This may happen when n is very small and p is large'); % end end diff --git a/toolbox/regression/LTStsLSmult.m b/toolbox/regression/LTStsLSmult.m index 92f291fd4..3677e279b 100644 --- a/toolbox/regression/LTStsLSmult.m +++ b/toolbox/regression/LTStsLSmult.m @@ -25,8 +25,8 @@ % Example - 'alphaLTS',0.1 % Data Types - double % bdp : breakdown point. Scalar. It measures the fraction of outliers -% the algorithm should resist. In this case any value greater -% than 0 but smaller or equal than 0.5 will do fine. Default +% the algorithm should resist. In this case, any value greater +% than 0, but smaller or equal than 0.5, will do fine. Default % value 0.1. % Example - 'bdp',0.4 % Data Types - double @@ -38,7 +38,7 @@ % which will be used. The model structure contains the following % fields: % model.s = scalar (length of seasonal period). For monthly -% data s=12 (default), for quartely data s=4, ... +% data s=12 (default), for quarterly data s=4, ... % model.trend = scalar (order of the trend component). % trend = 0 implies no trend; % trend = 1 implies linear trend with intercept (default); @@ -49,17 +49,17 @@ % frequencies, i.e. harmonics, in the seasonal % component. Possible values for seasonal are % $0,1, 2, ..., [s/2]$, where $[s/2]=floor(s/2)$. -% If seasonal =0 we assume there is no seasonal +% If seasonal=0, we assume there is no seasonal % component. -% If seasonal =1 (default) we have: +% If seasonal=1 (default) we have: % $\beta_1 \cos( 2 \pi t/s) + \beta_2 sin ( 2 \pi t/s)$; -% if seasonal =2 we have: +% if seasonal=2 we have: % $\beta_1 \cos( 2 \pi t/s) + \beta_2 \sin ( 2 \pi t/s) % + \beta_3 \cos(4 \pi t/s) + \beta_4 \sin (4 \pi t/s)$. -% Note that when $s$ is even the sine term disappears +% Note that when $s$ is even, the sine term disappears % for $j=s/2$ and so the maximum number of % trigonometric parameters is $s-1$. -% If seasonal is a number greater than 100 then it +% If seasonal is a number greater than 100, then it % is possible to specify how the seasonal component % grows over time. % For example, seasonal = 101 implies a seasonal @@ -73,9 +73,9 @@ % follows: % $(1+\beta_3 t + \beta_4 t^2)\times( \beta_1 \cos( % 2 \pi t/s) + \beta_2 \sin ( 2 \pi t/s))$. -% seasonal =0 implies a non seasonal model. -% In the paper RPRH to denote the number of -% frequencies of the seasonal component +% seasonal=0 implies a non seasonal model. +% In the paper RPRH, to denote the number of +% frequencies of the seasonal component, % symbol B is used, while symbol G is used to denote % the order of the trend of the seasonal component. % Therefore, for example, model.seasonal=201 @@ -96,15 +96,15 @@ % and corresponding fitted values (second column) or % empty scalar. If model.ARtentout is not empty, when % the autoregressive component is present, the y -% values which are used to compute the autoregressive -% component are replaced by model.tentout(:,2) for +% values, which are used to compute the autoregressive +% component, are replaced by model.tentout(:,2) for % the units contained in model.tentout(:,1) % Example - 'model', model % Data Types - struct % Remark: the default model is for monthly data with no % trend (1 parameter) + seasonal component with just one % harmonic (2 parameters), no additional explanatory -% variables and no level shift that is +% variables and no level shift that is: % model=struct; % model.s=12; % model.trend=0; @@ -113,15 +113,15 @@ % model.lshift=0; % msg : Messages on the screen. Boolean. % Scalar which controls whether to display or not messages -% on the screen. If msg==true (default) messages are displayed on +% on the screen. If msg==true (default), messages are displayed on % the screen about estimated time to compute the estimator % and the warnings about 'MATLAB:rankDeficientMatrix', % 'MATLAB:singularMatrix' and 'MATLAB:nearlySingularMatrix' -% are set to off else no message is displayed on the screen +% are set to off, else no message is displayed on the screen. % Example - 'msg',true % Data Types - logical % sampleLS : vector of the positions in which Level Shift should be -% tested. Vector. It is be the vector for the parameter +% tested. Vector. It is the vector for the parameter % model.lshift of the LTSts function. % Default is 3. % Example - 'sampleLS', [5 16 27 35] @@ -140,7 +140,7 @@ % Data Types - double % plots : Plots on the screen. Scalar. % If plots = 1, a two panel plot will be shown on the screen. -% The upper panel contains the orginal time series with +% The upper panel contains the original time series with % fitted values. The bottom panel will contain the plot % of robust residuals against index number. The confidence % level which is used to draw the horizontal lines associated @@ -230,7 +230,7 @@ %{ % Multiple level shift and variable selection. Example 1. % Detection of multiple Level Shifts followed by variable selection on the -% dataset of example before. +% dataset of the example before. load TTsugar % UA-LT yin2 = sugar{:,1}; out = LTStsLSmult(yin2,'maxLS',4,'alphaLTS',0.01,... @@ -251,7 +251,7 @@ %{ % Multiple level shift and variable selection. Example 2. % Detection of multiple Level Shifts followed by variable selection on the - % dataset of example before. + % dataset of the example before. load TTplant yin2 = plant{:,1}; out = LTStsLSmult(yin2,'maxLS',4,'alphaLTS',0.01,... @@ -332,7 +332,7 @@ end % Check if all the specified optional arguments were present in - % structure options Remark: the nocheck option has already been dealt + % structure options. Remark: the nocheck option has already been dealt % by routine chkinputR inpchk=isfield(options,UserOptions); WrongOptions=UserOptions(inpchk==0); @@ -380,7 +380,7 @@ end while LSsignif==true && ij<=maxLS outTent=LTSts(y,'model',model,'conflev',1-alphaLTS/T,'plots',0,'msg',0,'bdp',bdp); - %in case there is no LS or only 1 save some results + %in case there is no LS or only 1, save some results if T <= thresLS outTent.LevelShiftPval = NaN; outTent.posLS = NaN; diff --git a/toolbox/regression/LTStsVarSel.m b/toolbox/regression/LTStsVarSel.m index 285734707..2216a77d8 100644 --- a/toolbox/regression/LTStsVarSel.m +++ b/toolbox/regression/LTStsVarSel.m @@ -24,13 +24,13 @@ % % Optional input arguments: % -% firstTestLS: initial test for presence of level shift. Boolean. if +% firstTestLS: initial test for presence of level shift. Boolean. If % firstTestLS is true, we immediately find the position of % the level shift in a model which does not contain -% autoregressive terms, the seasonal specification is 101 If +% autoregressive terms, the seasonal specification is 101. If % the level shift component is significant we pass the level % shift component in fixed position to the variable selection -% procedure. Note also that the units declared as outliers +% procedure. Note also that the units declared as outliers % with a p-value smaller than 0.001 are used to form % model.ARtentout. model.ARtentout is used in the subsequent % steps of the variable selection procedure, every time there @@ -46,18 +46,18 @@ % convenience, we list the fields also here: % % model.s = scalar (length of seasonal period). For monthly -% data s=12 (default), for quartely data s=4, ... +% data s=12 (default), for quarterly data s=4, ... % model.trend = scalar (order of the trend component). % trend = 0 implies no trend, % trend = 1 implies linear trend with intercept, % trend = 2 implies quadratic trend, % trend = 3 implies cubic trend. % Admissible values for trend are, 0, 1, 2 and 3. -% In the paper RPRH to denote the order of the trend +% In the paper RPRH to denote the order of the trend, % symbol A is used. If this field is not present into % input structure model, model.trend=2 is used. % model.seasonal = scalar (integer specifying number of -% frequencies, i.e. harmonics, in the seasonal +% frequencies), i.e. harmonics, in the seasonal % component. Possible values for seasonal are % $1, 2, ..., [s/2]$, where $[s/2]=floor(s/2)$. % For example: @@ -66,10 +66,10 @@ % if seasonal =2 we have: % $\beta_1 \cos( 2 \pi t/s) + \beta_2 \sin ( 2 \pi t/s) % + \beta_3 \cos(4 \pi t/s) + \beta_4 \sin (4 \pi t/s)$. -% Note that when $s$ is even the sine term disappears +% Note that when $s$ is even, the sine term disappears % for $j=s/2$ and so the maximum number of % trigonometric parameters is $s-1$. -% If seasonal is a number greater than 100 then it +% If seasonal is a number greater than 100, then it % is possible to specify how the seasonal component % grows over time. % For example, seasonal = 101 implies a seasonal @@ -84,8 +84,8 @@ % $(1+\beta_3 t + \beta_4 t^2)\times( \beta_1 \cos( % 2 \pi t/s) + \beta_2 \sin ( 2 \pi t/s))$. % seasonal =0 implies a non seasonal model. -% In the paper RPRH to denote the number of -% frequencies of the seasonal component +% In the paper RPRH, to denote the number of +% frequencies of the seasonal component, % symbol B is used, while symbol G is used to denote % the order of the trend of the seasonal component. % Therefore, for example, model.seasonal=201 @@ -103,10 +103,10 @@ % then it is associated to the positions of level % shifts which have to be considered. The most % significant one is included in the fitted model. -% For example if model.lshift =[13 20 36] a +% For example, if model.lshift =[13 20 36], a % tentative level shift is imposed in position % $t=13$, $t=20$ and $t=36$. The most significant -% among these positions in included in the final +% among these positions is included in the final % model. In other words, the following extra % parameters are added to the final model: % $\beta_{LS1}* I(t \geq \beta_{LS2})$ where @@ -152,7 +152,7 @@ % trend (3 parameters) + seasonal component with three % harmonics which grows in a cubic way over time (9 parameters), % no additional explanatory variables, no level shift -% and no AR component that is +% and no AR component that is: % model=struct; % model.s=12; % model.trend=2; @@ -186,7 +186,7 @@ % The default value of nsamp is 1000; % Example - 'nsamp',500 % Data Types - double -% Remark: if nsamp=0 all subsets will be extracted. +% Remark: if nsamp=0 ,all subsets will be extracted. % They will be (n choose p). % % thPval: threshold for pvalues. Scalar. A value between 0 and 1. @@ -204,8 +204,8 @@ % % msg: Messages on the screen. Scalar. % Scalar which controls whether LTSts will display or not -% messages on the screen. Deafault is msg=0, that is no -% messages are displayed on the screen. If msg==1 messages +% messages on the screen. Default is msg=0, that is no +% messages are displayed on the screen. If msg==1, messages % displayed on the screen are about estimated time to compute % the estimator and the warnings about % 'MATLAB:rankDeficientMatrix', 'MATLAB:singularMatrix' and @@ -235,7 +235,7 @@ % model.lshift = the optimal level shift position. % model.X = a matrix containing the values of the extra % covariates which are likely to affect y. If the -% imput model specifies autoregressive components +% input model specifies autoregressive components % in model.ARp, then the selected ones will be also % included in model.X. % @@ -268,7 +268,7 @@ % using final weights. % out.conflev = confidence level used to declare outliers. % out.outliers = vector of the units declared outliers. -% out.singsub = number of subsets wihtout full rank. +% out.singsub = number of subsets without full rank. % out.y = response vector y. % out.X = data matrix X containing trend, seasonal, expl % (with autoregressive component) and lshift. @@ -440,15 +440,15 @@ model.trendb=[0 1]; % parameters of the linear trend model.s=12; % monthly time series model.seasonal=1; % 1 harmonic - model.seasonalb=[2 3]; % parameter for one harmonic - model.lshiftb=50; % level shift amplitude + model.seasonalb=[2 3]; % parameter for one harmonic + model.lshiftb=50; % level shift amplitude model.lshift= 35; % level shift position - model.signal2noiseratio = 30; % signal to noise ratio + model.signal2noiseratio = 30; % signal to noise ratio model.ARp=1; model.ARb=0.9; - n = 50; % sample size + n = 50; % sample size tmp = rand(n,1); - model.X = tmp; % a extra covariate + model.X = tmp; % a extra covariate model.Xb = 1; % beta coefficient of the covariate % generate data out_sim=simulateTS(n,'plots',1,'model',model); @@ -554,7 +554,7 @@ % If firstTestLS is true, we immediately find the position of the level shift % in a model which does not contains autoregressive terms and -% and seasonal specification is 101 +% and seasonal specification is 101. % If the level shift component is significant we pass the level shift % component in fixed position to the variable selection procedure. if firstTestLS==true && (length(model.lshift)>1 || model.lshift(1)==-1) @@ -613,7 +613,7 @@ % Initializations -% AllPvalSig = dycotomic variable that becomes 1 if all variables are +% AllPvalSig = dichotomic variable that becomes 1 if all variables are % significant. This means that the variables are to be kept and the % iterative procedure should stop. AllPvalSig=0; @@ -698,7 +698,7 @@ model.trend=model.trend-1; case 2 % elseif indmaxPvalall ==2 - % Remove from model the last term of the seasonal component that + % Remove from model the last term of the seasonal component, that % is remove last harmonic if msg==1 || plots==1 tmp = num2str(model.seasonal); @@ -786,10 +786,10 @@ ARfinalrefinement=false; if ARfinalrefinement==true && ~isempty(model.ARp) % 1) Estimate the model without the autoregressive component using final - % values of seasonal component, level shift and trend + % values of seasonal component, level shift and trend; % 2) Find the outliers and use fitted values for the units declared as - % outliers for the autoregressive component - % 3) Final call to LTSts to restimate the model adding the specification for + % outliers for the autoregressive component; + % 3) Final call to LTSts to re-estimate the model adding the specification for % the autoregressive component found before and using yhat for y lagged % for the units declared as outliers. modelfinref=model; @@ -802,7 +802,7 @@ ARtentout=[tentOutForAR yhatout]; model.ARtentout=ARtentout; - % reestimate final model + % re-estimate final model [out_LTSts]=LTSts(out_LTSts.y,'model',model,'nsamp',nsamp,... 'plots',0,'msg',msg,'dispresults',dispresults,'SmallSampleCor',1); end diff --git a/toolbox/regression/LXS.m b/toolbox/regression/LXS.m index 1eb0c5568..2d2865186 100644 --- a/toolbox/regression/LXS.m +++ b/toolbox/regression/LXS.m @@ -6,8 +6,8 @@ % Required input arguments: % % y: Response variable. Vector. A vector with n elements that -% contains the response -% variable. It can be either a row or a column vector. +% contains the response variable. +% It can be either a row or a column vector. % X : Predictor variables. Matrix. Data matrix of explanatory % variables (also called 'regressors') % of dimension (n x p-1). Rows of X represent observations, and @@ -23,11 +23,11 @@ % % bdp : breakdown point. Scalar. % It measures the fraction of outliers -% the algorithm should -% resist. In this case any value greater than 0 but smaller -% or equal than 0.5 will do fine. If on the other hand the -% purpose is subgroups detection then bdp can be greater than -% 0.5. In any case however n*(1-bdp) must be greater than +% the algorithm should resist. +% In this case any value greater than 0, but smaller +% or equal than 0.5, will do fine. If, on the other hand, the +% purpose is subgroups detection, then bdp can be greater than +% 0.5. In any case, however, n*(1-bdp) must be greater than % p. If this condition is not fulfilled an error will be % given. Please specify h or bdp not both. % Example - 'bdp',0.4 @@ -37,13 +37,14 @@ % % bonflevoutX : remote units in the X space. Scalar or empty (default). % If the design matrix X contains several high leverage units -% (that is units which are very far from the bulk of the +% (that is, units which are very far from the bulk of the % data), it may happen that the best subset may include some % of these units. -% If boflevoutX is not empty, outlier detection procedure FSM -% is applied to the design matrix X, using name/pair option -% 'bonflev',bonflevoutX. The extracted subsets which contain -% at least one unit declared as outlier in the X space by FSM +% If bonflevoutX is not empty, outlier detection procedure FSM +% is applied to the design matrix X, using name/pair option +% 'bonflev',bonflevoutX. The extracted subsets, which contain +% at least one unit declared as outlier in the X space by +% FSM, % are removed (more precisely they are treated as singular % subsets) from the list of candidate subsets to find the LXS % solution. The default value of bonflevoutX is empty, that @@ -59,7 +60,7 @@ % Example - 'conflev',0.99 % Data Types - double % -% conflevrew : Confidence level for use for reweighting. Scalar. Number +% conflevrew : Confidence level used for reweighting. Scalar. Number % between 0 and 1 containing confidence level which is used to do % the reweighting step. Default value is the one specified in % previous option conflev. @@ -70,11 +71,11 @@ % trimmed squares estimator. Scalar. % The number of observations that have determined the least % trimmed squares estimator. h is an integer greater than p -% (number of columns of matrix X including the intercept but -% smaller then n. If the purpose is outlier detection than h +% (number of columns of matrix X including the intercept, but +% smaller then n. If the purpose is outlier detection, then h % does not have to be smaller than [0.5*(n+p+1)] (default -% value). On the other hand if the purpose is to find -% subgroups of homogeneous observations h can be smaller than +% value). On the other hand, if the purpose is to find +% subgroups of homogeneous observations, h can be smaller than % [0.5*(n+p+1)]. If h