Matlab回归说明

来源:互联网 发布:矩阵的秩的所有性质 编辑:程序博客网 时间:2024/06/01 09:29
Regress

Multiple linear regression 
Syntax 


b = regress(y,X)

[b,bint] = regress(y,X)
[b,bint,r] = regress(y,X)
[b,bint,r,rint] = regress(y,X)
[b,bint,r,rint,stats] = regress(y,X)
[...] = regress(y,X,alpha)

Description
b = regress(y,X) returns the least squares fit of y on X by solving the linear model
for β, where:
y is an n-by-1 vector of observations
X is an n-by-p matrix of regressors
β is a p-by-1 vector of parameters
ɛ is an n-by-1 vector of random disturbances

[b,bint] = regress(y,X) returns a matrix bint of 95% confidence intervals for β.
[b,bint,r] = regress(y,X) returns a vector, r of residuals.
[b,bint,r,rint] = regress(y,X) returns a matrix rint of intervals that can be used to diagnose outliers. If rint(i,:) does not contain zero, then the ith residual is larger than would be expected, at the 5% significance level. This is evidence that the ith observation is an outlier. 
[b,bint,r,rint,stats] = regress(y,X) returns a vector stats that contains the R2 statistic, the F statistic and a p value for the full model, and an estimate of the error variance.

[...] = regress(y,X,alpha) uses a 100(1 - alpha)% confidence level to compute bint, and a (100*alpha)% significance level to computerint. For example, alpha = 0.2 gives 80% confidence intervals.

X should include a column of ones so that the model contains a constant term. The F statistic and p value are computed under the assumption that the model contains a constant term, and they are not correct for models without a constant. The R-square value is one minus the ratio of the error sum of squares to the total sum of squares. This value can be negative for models without a constant, which indicates that the model is not appropriate for the data.

If the columns of X are linearly dependent, regress sets the maximum possible number of elements of B to zero to obtain a basic solution, and returns zeros in elements of bint corresponding to the zero elements of B.

regress treats NaNs in X or y as missing values, and removes them.
Examples
Suppose the true model is
where I is the identity matrix.
X = [ones(10,1) (1:10)']
X =
   1   1
   1   2
   1   3
   1   4
   1   5
   1   6
   1   7
   1   8
   1   9
   1  10
y = X * [10;1] + normrnd(0,0.1,10,1)
y =
  11.1165
  12.0627
  13.0075
  14.0352
  14.9303
  16.1696
  17.0059
  18.1797
  19.0264
  20.0872
[b,bint] = regress(y,X,0.05)
b =
  10.0456
  1.0030
bint =
  9.9165  10.1747
  0.9822  1.0238

Compare b to [10 1]'. Note that bint includes the true model values.


0 0
原创粉丝点击