📄 leastsqrrdm.m
字号:
function [a,b,variance,CombineXY,s] = leastSqrRdm(x,y)
%LEASTSQRRDM Least square computation; x is random;
% [a, b] = LEASTSQRRDM(X,Y) perform least square computation based on
% N-by-p data matrix X and N-by-1 vector Y, returns the parameters and variances of
% the model. Rows of X and Y represent the observations,
% and columns of X and Y correspond to variables.
% This arithmatic assumes the both X and X are normally distributed, and
% the variance of X is equal to Y.(COV(X)=I(p)*a, Var(Y)=a)
%
% [a,b,variance] = LEASTSQRRDM(X,Y) return variance of X and Y.
%
% $Date: 2008/02/27 23:49:01 $
[n,p] = size(x);
CombineXY = x;
COmbineXY(:,p+1) = y;
% Center CombineXY by substracting off the column means
CombineXY0 = CombineXY - repmat(mean(CombineXY,1),n,1);
s = CombineXY0'*CombineXY0./(n-1);
[V,D] = eig(s);
b = -V(:,p)./V(p,p);
meanx = mean(x);
a = meanx(:,p+1) - b'*meanx(:,[1:p]);
variance = D(p+1)/n-p-1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -