median.src
来自「没有说明」· SRC 代码 · 共 58 行
SRC
58 行
/*
** median.src - medians of columns of a matrix
** (C) Copyright 1988-1998 by Aptech Systems, Inc.
** All Rights Reserved.
**
** This Software Product is PROPRIETARY SOURCE CODE OF APTECH
** SYSTEMS, INC. This File Header must accompany all files using
** any portion, in whole or in part, of this Source Code. In
** addition, the right to create such files is strictly limited by
** Section 2.A. of the GAUSS Applications License Agreement
** accompanying this Software Product.
**
** If you wish to distribute any portion of the proprietary Source
** Code, in whole or in part, you must first obtain written
** permission from Aptech Systems.
*/
/*
**> median
**
** Purpose: Computes the medians of a set of variables contained in the
** columns of a matrix.
**
** Format: m = median(x);
**
** Input: x NxK matrix.
**
** Output: m Kx1 vector containing the medians of the respective
** columns of x.
*/
proc median(x);
local k, n, med, mid, mflag, i, v, svx, indx, sv;
k=cols(x); n=rows(x); med=zeros(k,1); mid=n/2;
if round(mid) eq mid; /* even */
mflag=1; mid=mid|(mid+1);
else;
mflag=0; mid=ceil(mid);
endif;
indx=seqa(1,1,n);
i=1;
do until i > k;
v=submat(x,0,i);
svx=sortc((v~indx),1);
sv=submat(svx,0,1);
if mflag; /* even # of elements */
med[i,1]=meanc(sv[mid,1]);
else;
med[i,1]=sv[mid,1];
endif;
i=i+1;
endo;
retp(med);
endp;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?