Main Content

LSCOV.

在已知协方差存在下的最小二乘溶液

句法

X = LSCOV(A,B)
X= lscov(A,B,w)
X= lscov(A,B,V)
X= lscov(A,B,V,alg)
[x,stdx] = lscov(...)
[x,stdx,mse] = lscov(...)
[x,stdx,mse,s] = lscov(...)

描述

X = LSCOV(A,B)将普通的最小二乘解返回到线性系统的方程式一种*x = B,即,Xis the n-by-1 vector that minimizes the sum of squared errors(b - a * x)'*(b - a * x),在哪里一种是m-by-n,和B.is m-by-1.B.也可以是m-by-k矩阵,和LSCOV.为每列返回一个解决方案B.。什么时候等级(a)LSCOV.sets the maximum possible number of elements ofXto zero to obtain a "basic solution".

X= lscov(A,B,w),在哪里W.is a vector length m of real positive weights, returns the weighted least squares solution to the linear system一种*x = B, 那是,Xminimizes(B - A*x)'*diag(w)*(B - A*x)W.typically contains either counts or inverse variances.

X= lscov(A,B,V),在哪里V.是一个m-by-m真正的对称正定矩阵,将广义最小二乘解返回线性系统一种*x = BW.ith covariance matrix proportional toV., 那是,Xminimizes(b - a * x)'* inv(v)*(b - a * x)

More generally,V.can be positive semidefinite, andLSCOV.回报Xthat minimizesE.'*e,约束一种*x + T*e = B,在哪里the minimization is overXandE.那andt * t'= v。什么时候V.是Semidefinite,这个问题只有一个解决方案B.和......一致一种andV.(那是,B.处于列空间[在]), 除此以外LSCOV.返回错误。

默认,LSCOV.计算Cholesky分解V.并且,实际上,反转该因素将问题转变为普通的最小二乘。但是,如果LSCOV.确定V.is semidefinite, it uses an orthogonal decomposition algorithm that avoids invertingV.

X= lscov(A,B,V,alg)specifies the algorithm used to computeX什么时候V.是一个矩阵。alg可以具有以下值:

  • 'chol'uses the Cholesky decomposition ofV.

  • 'orth'使用正交分解,并且更合适的时间V.是不良状态或单数,但是计算得更昂贵。

[x,stdx] = lscov(...)返回估计的标准错误X。什么时候一种排名缺乏,STDX.contains zeros in the elements corresponding to the necessarily zero elements ofX

[x,stdx,mse] = lscov(...)返回平均方形错误。如果B.假设具有协方差矩阵σ2V.(或(σ2诊断接头(1. /W.)), 然后mseis an estimate of σ2

[x,stdx,mse,s] = lscov(...)返回估计的协方差矩阵X。什么时候一种排名缺乏,S.contains zeros in the rows and columns corresponding to the necessarily zero elements ofXLSCOV.cannot returnS.if it is called with multiple right-hand sides, that is, ifsize(B,2) > 1

这些数量的标准公式,何时一种andV.是全级别,是

  • x = inv(a'* inv(v)* a)* a'* inv(v)* b

  • mse = b'*(inv(v) - inv(v)* a * inv(a'* inv(v)* a)* a'* inv(v))* b./()

  • s = inv(a'* inv(v)* a)* mse

  • stdx = sqrt(diag(s))

However,LSCOV.使用更快更稳定的方法,并且适用于等级缺乏案例。

LSCOV.假设协方差矩阵B.只知道达到比例因素。mseis an estimate of that unknown scale factor, andLSCOV.scales the outputsS.andSTDX.appropriately. However, ifV.is known to be exactly the covariance matrix ofB.,然后不需要缩放。要在这种情况下获得适当的估计,您应该重新归类S.andSTDX.通过1 / MSE.andSQRT(1 / MSE), 分别。

例子

示例1 - 计算普通的最小二乘

The MATLAB®backslash operator (\) enables you to perform linear regression by computing ordinary least-squares (OLS) estimates of the regression coefficients. You can also useLSCOV.计算相同的OLS估计值。通过使用LSCOV.,您还可以计算这些系数的标准错误的估计,以及回归错误项的标准偏差的估计值:

X1 = [.2 .5 .6 .8 1.0 1.1]';X2 = [.1 .3 .4 .9 1.1 1.4]';x = [(尺寸(x1))x1 x2];Y = [.17 .26 .28 .23 .27 .34]';a = x \ y a = 0.1203 0.1203 0.3284 -0.1312 [SE_B,MSE] = LSCOV(X,Y)B = 0.1203 0.3284 -0.1312 SE_B = 0.0643 0.2267 0.1488 MSE = 0.0015

示例2 - 计算加权最小二乘

UseLSCOV.to compute a weighted least-squares (WLS) fit by providing a vector of relative observation weights. For example, you might want to downweight the influence of an unreliable observation on the fit:

w = [1 1 1 1 1 .1]';[BW,SEW_B,MSEW] = LSCOV(X,Y,W)BW = 0.1046 0.4614 -0.2621 SEF_B = 0.0309 0.1152 0.0814 MSEW = 3.4741E-004

Example 3 — Computing General Least Squares

UseLSCOV.to compute a general least-squares (GLS) fit by providing an observation covariance matrix. For example, your data may not be independent:

v = .2 *那些(长度(x1))+ .8 * diag(inal(尺寸(x1)));[BG,SEW_B,MSEG] = LSCOV(X,Y,V)BG = 0.1203 0.3284 -0.1312 SEF_B = 0.0672 0.2267 0.1488 MSEG = 0.0019

示例4 - 估计系数协方差矩阵

计算OLS,WLS或GLS的系数协方差矩阵的估计。系数标准误差等于该协方差矩阵对角线上的值的平方根:

[b,se_b,mse,s] = lscov(x,y);S S = 0.0041 -0.0130 0.0075 -0.0130 0.0514 -0.0328 0.0075 -0.0328 0.0221 0.0221 0.0221 0.02210.0221 0.06430.0643 0.0643 0.2267 0.2267 0.2267 0.2267 0.1488 0.22267 0.2267 0.0643 0.2267 0.22267 0.2267 0.06430.2267

一种lgorithms

矢量X最小化数量(a * x-b)'* inv(v)*(a * x-b)。The classical linear algebra solution to this problem is

x = inv(a'* inv(v)* a)* a'* inv(v)* b

但是LSCOV.函数来计算QR分解一种and then modifies问:通过V.

References

[1]斯特朗,G.,应用数学介绍那W.E.llesley-Cambridge, 1986, p. 398.

扩展能力

Introduced before R2006a