📄 data_outliers3.m
字号:
% location parameter of the columns of a matrix
% X. If X is a vector, it returns the LMS
% location parameter of its components. If X
% is a scalar, it returns X."
[gm]=LMSloc(rtb);
% calculate standard deviation
stdrt=std(rtb);
if length(rtb) > 3 && isequal(sod, 0)
pts=intersect( find(rtb > gm - num_std*stdrt), find(rtb < gm + num_std*stdrt)); % find all values within num_std std of geometric mean
npts=setdiff( 1:num_cols, pts); % find the indices of the outliers
else
pts=1:num_cols;
npts=[];
end
if isempty(pts)
pts=1:num_cols;
npts=[];
end
% Determine the maximum number of outliers in any rta data row
max_num_out=max([max_num_out, length(npts)]);
% indices of set of non-outliers (i.e. values kept)
ptsa{e1, 1}=pts;
% indices of set of outliers (i.e. values discarded from
% descriptive statistics)
nptsa{e1, 1}=npts;
% select the set of non-outliers data for calculating descriptive statistics
if isequal(abs_rta, 1)
rts=abs(rt(pts));
else
rts=rt(pts);
end
% Calculate the arithmetic mean.
[mn_rt1]=mean(rts);
% Calculate the robust estimate of the mean
[mn_rt2]=LMSloc(rts);
% calculate standard deviation
stdrt=std(rts);
% calculate 95% confidence interval of
% the standard error of the
% t-distribution with a two-sided test
[ci_int]=t_confidence_interval(rts, 0.95);
% Calculate the median
medianrt=median(rts);
% Calculate the median index
% (data point closest ot the median value)
[mbuf ix]=min(abs(rts-medianrt));
% Calculate the minimum
minrt=min(rts);
% Calculate the maximum
maxrt=max(rts);
mn_rt1a(e1,1)= m_round(mn_rt1, round_kind(1), round_digits(1));
mn_rt2a(e1,1)= m_round(mn_rt2, round_kind(1), round_digits(1));
stdrta(e1,1)= m_round(stdrt, 1, 3);
ci_inta(e1,1)= m_round(ci_int, 1, 3);
median_indexa(e1,1)=m_round(ix, 0, 0);
median_val(e1,1)= m_round(medianrt, round_kind(1), round_digits(1));
min_rta(e1,1)= m_round(minrt, round_kind(1), round_digits(1));
max_rta(e1,1)= m_round(maxrt, round_kind(1), round_digits(1));
if ~isequal(sod, 1) && ~isempty(npts)
% select the set of outliers data for calculating descriptive statistics
if isequal(abs_rta, 1)
rts=abs(rt(npts));
else
rts=rt(npts);
end
% Calculate the arithmetic mean.
[mn_rt1]=mean(rts);
% Calculate the robust estimate of the mean
[mn_rt2]=LMSloc(rts);
% calculate standard deviation
stdrt=std(rts);
% calculate 95% confidence interval of
% the standard error of the
% t-distribution with a two-sided test
[ci_int]=t_confidence_interval(rts, 0.95);
% Calculate the median
medianrt=median(rts);
% Calculate the median index
% (data point closest ot the median value)
[mbuf ix]=min(abs(rts-medianrt));
% Convert to Median Index of the original data array
ix=npts(ix);
% Calculate the minimum
minrt=min(rts);
% Calculate the maximum
maxrt=max(rts);
out_mn_rt1a(e1,1)= m_round(mn_rt1, round_kind(1), round_digits(1));
out_mn_rt2a(e1,1)= m_round(mn_rt2, round_kind(1), round_digits(1));
out_stdrta(e1,1)= m_round(stdrt, 1, 3);
out_ci_inta(e1,1)= m_round(ci_int, 1, 3);
out_median_indexa(e1,1)=m_round(ix, 0, 0);
out_median_val(e1,1)= m_round(medianrt, round_kind(1), round_digits(1));
out_min_rta(e1,1)= m_round(minrt, round_kind(1), round_digits(1));
out_max_rta(e1,1)= m_round(maxrt, round_kind(1), round_digits(1));
else
out_mn_rt1a(e1,1)=0;
out_mn_rt2a(e1,1)=0;
out_stdrta(e1,1)=0;
out_ci_inta(e1,1)=0;
out_median_indexa(e1,1)=0;
out_median_val(e1,1)=0;
out_min_rta(e1,1)=0;
out_max_rta(e1,1)=0;
end
else
% if the data array is empty
ptsa{e1,1}=[];
nptsa{e1,1}=[];
mn_rt1a(e1,1)=0;
mn_rt2a(e1,1)=0;
stdrta(e1,1)=0;
ci_inta(e1,1)=0;
median_indexa(e1,1)=0;
median_val(e1,1)=0;
min_rta(e1,1)=0;
max_rta(e1,1)=0;
out_mn_rt1a(e1,1)=0;
out_mn_rt2a(e1,1)=0;
out_stdrta(e1,1)=0;
out_ci_inta(e1,1)=0;
out_median_indexa(e1,1)=0;
out_median_val(e1,1)=0;
out_min_rta(e1,1)=0;
out_max_rta(e1,1)=0;
end
end
% Save data to the output variable rt_stats
rt_stats=[mn_rt1a, mn_rt2a, stdrta, ci_inta, median_indexa, median_val, min_rta, max_rta];
% Calculate the number of descriptive statistics
num_stats=size(rt_stats, 2);
% % Save data to the output variable rt_outlier_stat
rt_outlier_stats=[out_mn_rt1a, out_mn_rt2a, out_stdrta, out_ci_inta, out_median_indexa, out_median_val, out_min_rta, out_max_rta];
% % Initialize the output variables other_stats and other_outlier_stats
other_stats=zeros(num_vars, num_data_rows, num_stats);
other_outlier_stats=zeros(num_vars, num_data_rows, num_stats);
for e2=1:num_vars;
rta=varargin{e2};
[num_data_rows, buf]=size(rta);
for e1=1:num_data_rows;
if iscell(rta);
buf1=rta{e1, :};
if iscell(buf1);
rt=buf1{1};
else
rt=buf1;
end
else
rt=rta(e1, :);
end
num_cols=length(rt);
if num_cols > 0
if ~isequal(dep_var, 1)
% Calculate the robust estimate of the mean.
%
% Statistical language for this type of mean is
% "calculates the Least Median of Squares (LMS)
% location parameter of the columns of a matrix
% X. If X is a vector, it returns the LMS
% location parameter of its components. If X
% is a scalar, it returns X."
[gm]=LMSloc(rt);
% calculate standard deviation
stdrt=std(rt);
if length(rt) > 3 && isequal(sod, 0)
pts=intersect( find(rt > gm - num_std*stdrt), find(rt < gm + num_std*stdrt)); % find all values within num_std std of geometric mean
npts=setdiff( 1:num_cols, pts); % find the indices of the outliers
else
pts=1:num_cols;
npts=[];
end
if isempty(pts)
pts=1:num_cols;
npts=[];
end
% Determine the maximum number of outliers in any rta data row
max_num_out=max([max_num_out, length(npts)]);
% indices of set of non-outliers (i.e. values kept)
ptsa{e1, e2+1}=pts;
% indices of set of outliers (i.e. values discarded from
% descriptive statistics)
nptsa{e1, e2+1}=npts;
else
[mp1 np1]=size(ptsa);
if mp1 < e1
pts=ptsa{1, 1};
ptsa{e1, e2+1}=ptsa{1, 1};
else
pts=ptsa{e1, 1};
ptsa{e1, e2+1}=ptsa{e1, 1};
end
end
% select the set of non-outliers data for calculating descriptive statistics
if isequal( abs_other(e2), 1)
rts=abs(rt(pts));
else
rts=rt(pts);
end
% Calculate the arithmetic mean.
[mn_rt1]=mean(rts);
if isempty(rts)
e2
end
% Calculate the robust estimate of the mean
if ~isempty(rts)
[mn_rt2]=LMSloc(rts);
else
mn_rt2=[];
end
% calculate standard deviation
stdrt=std(rts);
% calculate 95% confidence interval of
% the standard error of the
% t-distribution with a two-sided test
[ci_int]=t_confidence_interval(rts, 0.95);
% Calculate the median
medianrt=median(rts);
% Calculate the median index
% (data point closest ot the median value)
[mbuf ix]=min(abs(rts-medianrt));
% Calculate the minimum
minrt=min(rts);
% Calculate the maximum
maxrt=max(rts);
other_stats(e2, e1, 1)=m_round(mn_rt1, round_kind(e2+1), round_digits(e2+1));
other_stats(e2, e1, 2)=m_round(mn_rt2, round_kind(e2+1), round_digits(e2+1));
other_stats(e2, e1, 3)=m_round(stdrt, 1, 3);
other_stats(e2, e1, 4)=m_round(ci_int, 1, 3);
other_stats(e2, e1, 5)=m_round(ix, 0, 0);
other_stats(e2, e1, 6)=m_round(medianrt, round_kind(e2+1), round_digits(e2+1));
other_stats(e2, e1, 7)=m_round(minrt, round_kind(e2+1), round_digits(e2+1));
other_stats(e2, e1, 8)=m_round(maxrt, round_kind(e2+1), round_digits(e2+1));
if ~isequal(sod, 1) && ~isempty(npts)
if isequal(dep_var, 1)
[mp1 np1]=size(nptsa);
if mp1 < e1
npts=nptsa{1, 1};
nptsa{e1, e2+1}=nptsa{1, 1};
else
npts=nptsa{e1, 1};
nptsa{e1, e2+1}=nptsa{e1, 1};
end
end
% select the set of outliers data for calculating descriptive statistics
if isequal( abs_other(e2), 1)
rts=abs(rt(npts));
else
rts=rt(npts);
end
% Calculate the arithmetic mean.
[mn_rt1]=mean(rts);
% Calculate the robust estimate of the mean
[mn_rt2]=LMSloc(rts);
% calculate standard deviation
stdrt=std(rts);
% calculate 95% confidence interval of
% the standard error of the
% t-distribution with a two-sided test
[ci_int]=t_confidence_interval(rts, 0.95);
% Calculate the median
medianrt=median(rts);
% Calculate the median index
% (data point closest ot the median value)
[mbuf ix]=min(abs(rts-medianrt));
% Convert to Median Index of the original data array
ix=npts(ix);
% Calculate the minimum
minrt=min(rts);
% Calculate the maximum
maxrt=max(rts);
other_outlier_stats(e2, e1, 1)=m_round(mn_rt1, round_kind(e2+1), round_digits(e2+1));
other_outlier_stats(e2, e1, 2)=m_round(mn_rt2, round_kind(e2+1), round_digits(e2+1));
other_outlier_stats(e2, e1, 3)=m_round(stdrt, 1, 3);
other_outlier_stats(e2, e1, 4)=m_round(ci_int, 1, 3);
other_outlier_stats(e2, e1, 5)=m_round(ix, 0, 0);
other_outlier_stats(e2, e1, 6)=m_round(medianrt, round_kind(e2+1), round_digits(e2+1));
other_outlier_stats(e2, e1, 7)=m_round(minrt, round_kind(e2+1), round_digits(e2+1));
other_outlier_stats(e2, e1, 8)=m_round(maxrt, round_kind(e2+1), round_digits(e2+1));
else
other_outlier_stats(e2, e1, 1:8)=0;
end
else
% if the data is empty
other_stats(e2, e1, 1:8)=[];
other_outlier_stats(e2, e1, 1:8)=[];
end
end
end
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Write the descriptive statistics to the tab delimited outfile
%
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -