📄 weights.m
字号:
function w = Weights(x,y,n)
% Calculating the weights 计算权值
nv = length(n); % Number of dependent variables
if nv > 1
for j = 1:nv
tmpy = y(1,j);
ss(j) = 0; % Sum of squares
ns(j) = 0; % Degrees of freedom
% Search for repeated data
for i = 2:n(j)
if x(i-1,j) == x(i,j)
tmpy = [tmpy; y(i,j)];
else
if length(tmpy) ~= 1
ly = length(tmpy);
ss(j) = ss(j) + (ly-1)*std(tmpy)^2;
ns(j) = ns(j) + (ly-1);
end
end
if i == n(j) & length(tmpy) ~= 1
ly = length(tmpy);
ss(j) = ss(j) + (ly-1)*std(tmpy)^2;
ns(j) = ns(j) + (ly-1);
end
if x(i-1,j) ~= x(i,j)
tmpy = y(i,j);
end
end
% Estimating variance for each dependent variable
if ns(j) == 0
s2(j) = 1;
else
s2(j) = ss(j) / ns(j);
end
end
w = sum(n)./s2 / sum(n./s2); % Vector of weights
else
w = 1;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -