model cost=cattle/p clm cli;
/*p:计算每个观测的预测值;给出因变量,预测因变量的值,残差(观测值-预测值),预测
?x)?均值的标准误V(yx?(X?X)?1x?2,预测值的标准误为?x)?(1?x?(X?X)?1x)?2,其中的?2用??2?MSE去估计 V(y?y??t?clm:均值的置信区间(y2?x),y??t?2(n?1)?V(y?x)) (n?1)?V(y?(y?y?(y?y??t?2(n?1)?V?),y??t?2(n?1)?V?)) CLI: 预测值的置信区间:(y*/
plot cost*cattle;
/*打印原始数据的散点图,及回归直线*/
run;
Adj R-sq: 1?(1?R)?2n?1,其中n为观测数,m为回归参数的个数(包括截距项) n?m?1 /* Use the following DATA step to produce Outputs 2.5 through 2.8. */
2.2 多元回归(ss1,ss2,检验语句test,约束估计restrict)
data auction;
input marketid $ cattle calves hogs sheep cost type $; volume=cattle+calves+hogs+sheep; cards;
A 3.437 5.791 3.268 10.649 27.698 O B 12.801 4.558 5.751 14.375 57.634 O C 6.136 6.223 15.175 2.811 47.172 O D 11.685 3.212 .639 .694 49.295 B E 5.733 3.220 .534 2.052 24.115 B F 3.021 4.348 .839 2.356 33.612 B G 1.689 .634 .318 2.209 9.512 O H 2.339 1.895 .610 .605 14.755 B I 1.025 .834 .734 2.825 10.570 O J 2.936 1.419 .331 .231 15.394 B K 5.049 4.195 1.589 1.957 27.843 B L 1.693 3.602 .837 1.582 17.717 B M 1.187 2.679 .459 18.837 20.253 O N 9.730 3.951 3.780 .524 37.465 B O 14.325 4.300 10.781 36.863 101.334 O P 7.737 9.043 1.394 1.524 47.427 B Q 7.538 4.538 2.565 5.109 35.944 B R 10.211 4.994 3.081 3.681 45.945 B
S 8.697 3.005 1.378 3.338 46.890 B ;
proc print data=auction; run;
proc reg data=auction; id marketid;
model cost=cattle calves hogs sheep/ss1 ss2; hogs: test hogs=0;
hogsheep: test hogs=0, sheep=0; intercep: test intercept=0; hogone: test hogs=1; hequals: test hogs-sheep=0; run;
注:假设检验中,事实上是比较全模型与选模型间的差别。
关于SS1,SS2的说明见书P16,;test语句的说明见p17,给出相应语句对应的模型含义;
注:SS1,SS2的意义:
设线性模型为:y??0??1x1????pxpR(?1|?0)表示只有一个变量x1时回归平方和,??,
R(?2|?0,?1)表示添加变量x2后,与原来的只有一个变量x1时回归平方和的增量(它反映的
是变量x2对回归的贡献)。 SS1,SS2的含义可表示为: 变量 Ss1 Ss2 x1 x2 ? R(?1|?0) R(?2|?0,?1) R(?1|?0,?2,?3,?,?p) R(?2|?0,?1,?3,?,?p) xp
R(?p|?0,?1,?,?p?1) R(?p|?0,?1,?,?p?1)
/* Use the following DATA step to produce Output 2.9. */ /*带约束的最小二乘估计*/
proc reg data=auction; id marketid; model cost=cattle calves hogs sheep; restrict intercept=0, hogs-sheep=0; run;
/* Use the following DATA step to produce Output 2.10. */
2.3 变量间有线性关系
data auction; set auction; hs=hogs+sheep; run;
proc reg data=auction; id marketid; model cost=cattle calves hs / noint; run;
/*以上两个程序的结果一致,尽管有些统计量的数值有些差异,但要计算的系数是一样的,其中hs = hogs+sheep */
/* Use the following DATA step to produce Output 2.11.
这个程序是考虑变量间有确定的线性关系时,程序的输出,注意在DF一栏下的B和0的含义 */
proc reg data=auction; id marketid;
model cost=cattle calves hogs sheep volume; run;
/* Use the following DATA step to produce Output 2.12. */ /* 此程序给出了与REG过程的一些比较,尤其是关于Type I-IV SS间的关系,P23 */
用GLM过程进行回归分析,由于GLM过程概括了线性回归,方差分析,以及协方差分析等多种内容,因此在进行回归分析时其语句的调用与REG过程有些差别,希望注意这些差别。
1)REG过程中只有两种类型的平方和,即SS1,SS2;而GLM过程有四种类型的平方和,在进行回归分析时,有如下的对应关系:REGSS1=GLMSS1 ,REGSS2=GLM(SS2,SS3,SS4)素,其它的平方和主要是进行方差分析而设定的(这三类平方和间的差别只是在有些方差分析模型中有所不同。在单因素方差分析以及平衡多因素方差分析中,ANOVA中的平方和与GLM中SS1,SS3是相同的)。
proc glm data=auction; id marketid; model cost=cattle calves hogs sheep; run;
/* Use the following DATA step to produce Outputs 2.13 and 2.14. */ /* Contrast 语句是关于检验用的,Estimate是关于线性估计的,首先要关注到这两种语句的表示方式,见P25 */
2.4 给出感兴趣的检验和估计(线性组合的检验contrast和估计estimate)
proc glm data=auction; id marketid; model cost=cattle calves hogs sheep;
contrast 'hogcost=0' intercept 0 cattle 0 calves 0 hogs 1 sheep 0; contrast 'hogcost=0' hogs 1;
contrast 'hogcost=sheepcost' hogs 1 sheep -1; contrast 'hogcost=sheepcost=0' hogs 1, sheep 1; estimate 'hogcost' hogs 1;
estimate 'hogcost-sheepcost' hogs 1 sheep -1; run;
2)如何给出检验和估计(检验语句contrast和估计语句estimate) 对于如下的两因素析因实验,其模型为:?ij????i??j?(??)ij, (2.1)写出想要估计或检验的均值的线性组合; (2.2)将均值转换成模型参数; (2.3)合并同类项;
让cij表示?ij的系数,如下表所示:
1 因 子 2 1 2 因子B ? b 合计 c11 c21 c12 ? ? c1b c1? c22 c2b c2? A ? a ? ca1 ? ca2 c?2 ? ? ? ? cab c?b ? ca? c?? 合计 c?1 如求c21?21?c45?45=c21(???2??1?(??)21)?c45(???4??5?(??)45) =(c21?c45)??c21?2?c21?1?c21(??)21)?c45(?4??5?(??)45)
c21?21?c25?55=c21(???2??1?(??)21)?c25(???2??5?(??)25) =(c21?c25)??(c21?c25)?2?c21(?1?(??)21)?c25(?5?(??)25)
2.5一个完全的回归分析的例子
考虑Hald水泥数据
X1—3CaO·Al2O3的含量(%) X2—3CaO·SiO2的含量(%) X3—4CaO·Al2O3·Fe2O3的含量(%)
X4—2CaO·SiO2的含量(%)
Y表示水泥凝固时释放的热量(卡/克)。
Data hald;
Input x1-x4 y;Cards;
7 26 6 60 78.5 1 29 15 52 74.3 11 56 8 20 104.3 11 31 8 47 87.6 7 52 6 33 95.9 11 55 9 22 109.2 3 71 17 6 102.7 1 31 22 44 72.5 2 54 18 22 93.1 21 47 4 26 115.9 1 40 23 34 83.8 11 66 9 12 113.3 10 68 8 12 109.4 Run;
proc reg data=hald; model y=x1-x4; run;
识别多重共线性 proc reg data=hald;
model y=x1-x4/ vif collin; run;
多重共线性的处理 ①选择变量法 逐步回归法
proc reg data=hald;
model y=x1-x4/selection=stepwise; run; 全子集法
proc reg data=hald;
model y=x1-x4/selection=adjrsq cp bic; run;
②岭回归法
proc reg data=hald outest=rghald outvif graphics corr; model y=x1-x4/ridge=0 to 1 by 0.1 2 3 4 5 6 ;
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库2011线性模型sas(2)在线全文阅读。
相关推荐: