注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

数据挖掘

学习数据挖掘

 
 
 

日志

 
 

matlab实现多元线性回归  

2013-04-02 21:56:33|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

二、一元线性回归

21.命令 polyfit最小二乘多项式拟合

 [pS]=polyfitxym

多项式y=a1xm+a2xm-1++amx+am+1

其中x=x1x2,…,xmx1…xm为(n*1)的矩阵;

y为(n*1)的矩阵;

p=a1a2,…,am+1)是多项式y=a1xm+a2xm-1++amx+am+1的系数;

S是一个矩阵,用来估计预测误差.

22.命令 polyval多项式函数的预测值

Y=polyvalpx)求polyfit所得的回归多项式在x处的预测值Y

ppolyfit函数的返回值;

xpolyfit函数的x值相同。

23.命令 polyconf 残差个案次序图

[YDELTA]=polyconfpxSalpha)求polyfit所得的回归多项式在x处的预测值Y及预测值的显著性为1-alpha的置信区间DELTAalpha缺省时为0.05

ppolyfit函数的返回值;

xpolyfit函数的x值相同;

Spolyfit函数的S值相同。

2命令 polytoolxym)一元多项式回归命令

 

25.命令regress多元线性回归(可用于一元线性回归)

b=regress( Y,  X )

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

回归系数

bint 回归系数的区间估计

残差

rint 残差置信区间

stats 用于检验回归模型的统计量,有三个数值:相关系数R2F值、与F对应的概率p,相关系数R2越接近1,说明回归方程越显著;F > F1-α(kn-k-1)时拒绝H0F越大,说明回归方程越显著;与F对应的概率时拒绝H0,回归模型成立。

Yn*1的矩阵;

X为(ones(n,1),x1,…,xm)的矩阵;

alpha显著性水平(缺省时为0.05)。

 画出残差以及其置信区间

 命令为rcoplot(r,rint);

三、多元线性回归

31.命令 regress(见25

32.命令 rstool 多元二项式回归

命令:rstoolxy,’model, alpha

n*m矩阵

y n维列向量

model 由下列4个模型中选择1个(用字符串输入,缺省时为线性模型):

linear(线性):

purequadratic(纯二次): 

interaction(交叉):

quadratic(完全二次):

alpha 显著性水平(缺省时为0.05

返回值beta 系数

返回值rmse剩余标准差

返回值residuals残差

 

四、非线性回归

41.命令 nlinfit

[beta,R,J]=nlinfit(X,Y,’’model’,beta0)

n*m矩阵

Y n维列向量

model为自定义函数

beta0为估计的模型系数

beta为回归系数

R为残差

J

 

42.命令 nlintool

nlintool(X,Y,’model’,beta0,alpha)

n*m矩阵

Y n维列向量

model为自定义函数

beta0为估计的模型系数

alpha显著性水平(缺省时为0.05

 

43.命令 nlparci

betaci=nlparci(beta,R,J)

beta为回归系数

R为残差

J

返回值为回归系数beta的置信区间

 

44.命令 nlpredci

[Y,DELTA]=nlpredci(‘model’,X,beta,R,J)

Y为预测值

DELTA为预测值的显著性为1-alpha的置信区间;alpha缺省时为0.05

n*m矩阵

model为自定义函数

beta为回归系数

R为残差

以上转自:http://blog.sciencenet.cn/blog-388372-403472.html

-----逐步回归stepwise

 stepwise Interactive tool for stepwise regression. %与用户交互的逐步回归

    stepwise(X,Y) displays an interactive tool for creating a
    regression model to predict the vector Y using a subset of the% 选择X中的若干变量 建立回归模型
    predictors given by columns of the matrix X.  Initially no
    predictors are included in the model, but you can click on% 开始模型不包括任何变量,可以手动的调进 调出。
    predictors to switch them into and out of the model.  stepwise
    automatically includes a constant term in all models.
 
    For each predictor in the model, its least squares coefficient
    is plotted with a blue filled circle.  For each predictor not  %模型中变量的 最小二乘的系数 有蓝色标记
    in the model, a filled red circle indicates the coefficient it %不在模型中变量的 最小二乘的系数 有红色标记(加入加到模型中)
    would have if it were added to the model.  Horizontal bars indicate
    90% (colored) and 95% (black) confidence intervals. % 相应的置信区间
 
    stepwise(X,Y,INMODEL,PENTER,PREMOVE) specifies the initial state
    of the model and the confidence levels to use.  INMODEL is a logical
    or index vector specifying the predictors that should be in the
    initial model (default is none).  PENTER specifies the maximum
    p-value for a predictor to be recommended for adding to the model
    (default 0.05).  PREMOVE specifies the minimum p-value for a
    predictor to be recommended for removal (default 0.10). %两个临界值的设置
 
    A NaN in either X or Y is treated as a missing value.  Rows
    containing missing values are not used in the fit.
 
-----逐步回归的拟合函数

stepwisefit()。。。。
stepwisefit Fit regression model using stepwise regression % 使用前面的stepwise 拟合回归模型


    B=stepwisefit(X,Y) uses stepwise regression to model the response variable
    Y as a function of the predictor variables represented by the columns
    of the matrix X.  The result B is a vector of estimated coefficient values %输出B为各项的回归系数
    for all columns of X.  The B value for a column not included in the final
    model is the coefficient that would be obtained by adding that column to
    the model.  stepwisefit automatically includes a constant term in all
    models.
 
    [B,SE,PVAL,INMODEL,STATS,NEXTSTEP,HISTORY]=stepwisefit(...) returns additional
    results.  
     SE is a vector of standard errors for B. 
   PVAL is a vector of p-values for testing if B is 0.  
   INMODEL is a logical vector indicatingwhich predictors are in the final model.  
   STATS is a structure containin additional statistics.  
    NEXTSTEP is the recommended next step -- either
    the index of the next predictor to move in or out, or 0 if no further
    steps are recommended.  
HISTORY is a structure containing information
    about the history of steps taken.
 
    [...]=stepwisefit(X,Y,'PARAM1',val1,'PARAM2',val2,...) specifies one or
    more of the following name/value pairs:
 
      'inmodel'  A logical vector, or a list of column numbers, indicating which
                 predictors to include in the initial fit (default none)
      'penter'   Max p-value for a predictor to be added (default 0.05)
      'premove'  Min p-value for a predictor to be removed (default 0.10)
      'display'  Either 'on' (default) to display information about each
                 step or 'off' to omit the display
      'maxiter'  Maximum number of steps to take (default is no maximum)
      'keep'     A logical vector, or a list of column numbers, indicating which
                 predictors to keep in their initial state (default none)
      'scale'    Either 'on' to scale each column of X by its standard deviation
                 before fitting, or 'off' (the default) to omit scaling.
 
  评论这张
 
阅读(15037)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018