Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Theil-Sen-Matlab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Keyser, Johannes
Theil-Sen-Matlab
Commits
984d9f78
Commit
984d9f78
authored
3 years ago
by
Keyser, Johannes
Browse files
Options
Downloads
Patches
Plain Diff
-unnecessary indexing, +sensible indentation, y not Y
parent
85ed7d84
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
TheilSen.m
+9
-8
9 additions, 8 deletions
TheilSen.m
with
9 additions
and
8 deletions
TheilSen.m
+
9
−
8
View file @
984d9f78
...
...
@@ -18,7 +18,7 @@ function coef = TheilSen(X, y)
% to one predictor in X, i.e. it will have as many columns as X.
% The first row, i.e. coef(1, :), contains the estimated offset(s).
% The second row, i.e. coef(2, :), contains the estimated slope(s).
% (This output format
i
s chosen to avoid confusion, e.g. with previous
% (This output format
wa
s chosen to avoid confusion, e.g. with previous
% versions of this code.)
%
% EXAMPLE
...
...
@@ -39,7 +39,7 @@ function coef = TheilSen(X, y)
sizeX
=
size
(
X
);
sizeY
=
size
(
y
);
if
length
(
sizeY
)
~=
2
||
sizeY
(
1
)
<
2
||
sizeY
(
2
)
~=
1
||
~
isnumeric
(
Y
)
if
length
(
sizeY
)
~=
2
||
sizeY
(
1
)
<
2
||
sizeY
(
2
)
~=
1
||
~
isnumeric
(
y
)
error
(
'Input y must be a column array of at least 2 observed responses.'
)
end
...
...
@@ -72,19 +72,20 @@ Num_Pred = sizeX(2); % columns in X are (independent) predictor variables
C
=
nan
(
Num_Obs
,
Num_Pred
,
Num_Obs
);
for
i
=
1
:
Num_Obs
C
(:,
:,
i
)
=
bsxfun
(
@
rdivide
,
...
bsxfun
(
@
minus
,
y
(
i
),
y
(:)
),
...
bsxfun
(
@
minus
,
X
(
i
,
1
:
end
),
X
(:,
1
:
end
)
));
bsxfun
(
@
minus
,
y
(
i
),
y
),
...
bsxfun
(
@
minus
,
X
(
i
,
:),
X
));
end
% stack layers of C to 2D
Cprm
=
reshape
(
permute
(
C
,
[
1
,
3
,
2
]),
[],
size
(
C
,
2
),
1
);
Cprm
=
reshape
(
permute
(
C
,
[
1
,
3
,
2
]),
...
[],
size
(
C
,
2
),
1
);
% estimate slope as the median of all pairwise slopes (per predictor column)
b1s
=
median
(
Cprm
,
1
,
'omitnan'
);
% estimate offset as the median of all pairwise offsets (per predictor column)
b0s
=
median
(
bsxfun
(
@
minus
,
y
(:)
,
...
bsxfun
(
@
times
,
b1s
,
X
(:,
1
:
end
)
)),
...
b0s
=
median
(
bsxfun
(
@
minus
,
y
,
...
bsxfun
(
@
times
,
b1s
,
X
)),
...
'omitnan'
);
coef
=
[
b0s
;
b1s
];
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment