Matlab regression analysis and prediction

Statistical Analysis Regression Analysis and Forecasting

Mathematical Statistics - Regression Analysis

Type of regression analysis

insert image description here

Purpose of regression analysis

insert image description here
insert image description here

insert image description here

unary linear regression

insert image description here

The Case for Multiple Linear Regression

%{
    
    
[B,BINT,R,RINT,STATS] = regress(Y,X)
[B,BINT,R,RINT,STATS] = regress(Y,X,ALPHA)
参数解释:
    B:     回归系数,是个向量(“the vector B of regression coefficients in the  linear model Y = X*B”)。
    BINT:  回归系数的区间估计(“a matrix BINT of 95% confidence intervals for B”)。
    R:     残差( “a vector R of residuals”)。
    RINT:  置信区间(“a matrix RINT of intervals that can be used to diagnose outliers”)。
    STATS: 用于检验回归模型的统计量。有4个数值:判定系数R^2,F统计量观测值,检验的p的值,误差方差的估计。
    ALPHA: 显著性水平(缺少时为默认值0.05%}
%导入数据  
x1=[3.5 5.3 5.1 5.8 4.2 6.0 6.8 5.5 3.1 7.2 4.5 4.9 8.0 6.5 6.5 3.7 6.2 7.0 4.0 4.5 5.9 5.6 4.8 3.9];
x2=[9 20 18 33 31 13 25 30 5 47 25 11 23 35 39 21 7 40 35 23 33 27 34 15];
x3=[6.1 6.4 7.4 6.7 7.5 5.9 6.0 4.0 5.8 8.3 5.0 6.4 7.6 7.0 5.0 4.0 5.5 7.0 6.0 3.5 4.9 4.3 8.0 5.0];
Y=[33.2 40.3 38.7 46.8 41.4 37.5 39.0 40.7 30.1 52.9 38.2 31.8 43.3 44.1 42.5 33.6 34.2 48.0 38.0 35.9 40.4 36.8 45.2 35.1];
n=24; m=3;
X=[ones(n,1),x1',x2',x3'];
[b,bint,r,rint,s]=regress(Y',X,0.05)
%{
    
    
    建立 Y 与x1,x2,x3的多元线性回归模型
    Y = b0 +b1*x1+b2*x2+b3*x3      回归系数 b = (b0,b1,b2,b3)
    计算回归系数的置信区间,以及统计变量 stats(它包含四个检验统计量:相关系数的平方R^2,假设检验统计量F,与F对应的概率p,s^2的值)
    判断模型
    1. 回归系数置信区间不包含零点表示模型较好,
    2. 残差在零点附近也表示模型较好,
    3. 接着就是利用检验统计量 R^2,F,p 的值判断该模型是否可用。
    (1)^2是拟合回归最后对拟合回归效果的一个评价指标。 R^2越接近于1,则拟合回归效果越好。
    (2)F 检验法:当 F > F1-α(m,n-m-1) ,即认为因变量 y 与自变量 x1,x2,...,xm 之间有显著的线性相关关系;
                否则认为因变量 y 与自变量 x1,x2,...,xm 之间线性相关关系不显著。
    (3)若 p < α(α 为预定显著水平),则说明因变量 y 与自变量 x1,x2,...,xm之间显著地有线性相关关系。
    (4)以上三种统计推断方法推断的结果是一致的,说明因变量 y 与自变量之间显著地有线性相关关系.
     所得线性回归模型可用。s^2 当然越小越好,这主要在模型改进时作为参考。
    % (b0,b1,b2,b3) 
    b =    18.0157 
        1.0817
        0.3212
        1.2835  
    s =
    0.9106(R^2)   67.9195(F)    0.0000(p)    3.0719(s^2)
%}

Guess you like

Origin blog.csdn.net/weixin_43599390/article/details/131358165