-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtm.m
executable file
·35 lines (30 loc) · 1017 Bytes
/
tm.m
1
function [trimmedMean,g] = tm(x,pr)% function [trimmedMean,g]=tm(x,pr)%% Returns the trimmed mean of x as trimmedMean.% returns number of winsorized observations at each tail of sample as g% x must be a vector% pr ranges between 0 and 100 - default = 20% The trimmed mean is calculated from x after dropping the lower and upper g values from% x, where g=floor(pr*length(x)). If x is empty, then NaN is% returned.%% See Wilcox (2005), Introduction to Robust Estimation and Hypothesis% Testing (2nd Edition), Chapter 3, for a description of trimmed means.%% Original code provided by Prof. Patrick J. Bennett, McMaster University% The output size for [] is a special case, handle it here.if isequal(x,[]), trimmedMean = NaN; return; end;if nargin < 2 pr = 20;end% make sure that x is a vectorsz = size(x);if sz > 2 | min(sz) > 1 error('tm requires x to be a vector, not a matrix.');endn = length(x);xsort=sort(x);g=floor((pr/100)*n);tx=xsort((g+1):(n-g));trimmedMean=mean(tx);