第二章 1. 矩阵A:
1.00 0.80 0.26 0.67 0.34 0.80 1.00 0.33 0.59 0.34 0.26 0.33 1.00 0.37 0.21 0.67 0.59 0.37 1.00 0.35 0.34 0.34 0.21 0.35 1.00
矩阵A的逆矩阵
[,1] [,2] [,3] [,4] [,5] [1,] 3.3881372 -2.1222233 0.23706087 -1.0684729 -0.10622799 [2,] -2.1222233 2.9421167 -0.33593309 -0.1330915 -0.16163579 [3,] 0.2370609 -0.3359331 1.20698521 -0.3763728 -0.08811984 [4,] -1.0684729 -0.1330915 -0.37637284 2.0091273 -0.21562437 [5,] -0.1062280 -0.1616358 -0.08811984 -0.2156244 1.18504738 特征值 [1] 2.7922569 0.8263366 0.7790638 0.4205873 0.1817554
x1=c(1.00,0.80,0.26,0.67,0.34,0.80,1.00,0.33,0.59,0.34,0.26,0.33,1.00,0.37,0.21,0.67,0.59,0.37,1.00,0.35,0.34,0.34,0.21,0.35,1.00);x1 A=matrix(x1,nrow=5,ncol=5);A solve(A) A.e=eigen(A);A.e A.e$vectors%*%diag(A.e$values)%*%t(A.e$vectors) 特征向量:
[,1] [,2] [,3] [,4] [,5] [1,] -0.5255426 0.3402197 -0.1665086 0.15937771 0.74493565 [2,] -0.5186716 0.2343491 -0.1777739 0.50822995 -0.62141694 [3,] -0.3131429 -0.9030775 -0.2287038 0.149427 0.108433 [4,] -0.49633 0.0386900 -0.1185744 -0.83115510 -0.21672526 [5,] -0.3317705 -0.1108387 0.9350433 0.05615655 0.01354831
2.2
e2.2=read.table(\"clipboard\ attach(e2.2) mean(X) sd(X) median(X) f=hist(X,breaks=c(1000,1300,1600,1900,2200,2500,2800,3100)) f$count f$count/length(X) cumsum(f$count/length(X)) qqnorm(X) qqline(X) detach(e2.2) 平均工资 17.2 工资方差 455.9808 工资中位数1872.5
各组频率 0.12 0.14 0.26 0.22 0.14 0.08 0.04 累计频率 0.12 0.26 0.52 0.74 0.88 0.96 1.00 近似服从正态分布
Histogram of XFrequency024681012100015002000X25003000Normal Q-Q Plot3000Sample Quantiles1000150020002500-2-10Theoretical Quantiles12 e2.3=read.table(\"clipboard\ 0.8 Y y N <5h
>10h
x
5-10h
e2.3 summary(e2.3) attach(e2.3) barplot(table(Smoke)) plot(Study,Smoke) table(Smoke,Study) tab=table(Smoke,Study) prop.table(tab,1) prop.table(tab,2) prop.table(tab) prop=function(x) x/sum(x) apply(tab,2,prop) t(apply(tab,1,prop)) 编号 是否抽烟 Smoke 每天学习时间 Study Min. : 1.00 否:4 N:4 5-10小时 :4 5h :3 1st Qu.: 3.25 是:6 Y:6 超过10小时:3 10h :3 Median : 5.50 少于5小时 :3 5-10h:4 Mean : 5.50 3rd Qu.: 7.75 Max. :10.00 Study Study Smoke <5h >10h 5-10h Smoke <5h >10h 5-10h N 0.0 0.2 0.2 N 0.0000000 0.5000000 0.5000000 Y 0.3 0.1 0.2 Y 0.5000000 0.1666667 0.3333333 按列统计: Study <5h >10h 5-10h N 0 0.6666667 0.5 Y 1 0.3333333 0.5 0.0 0.2 0.4 0.6 1.0 2.3
第三章 3.2
e3.2=read.table(\"clipboard\ e3.2 summary(e3.2) barplot(apply(e3.2,1,mean)) boxplot(e3.2) stars(e3.2,full=T) stars(e3.2,full=T,draw.segments=T) library(aplpack) faces(e3.2,ncol.plot=7) library(mvstats) plot.andrews(e3.2) > summary(e3.2) x1 x2 x3 x4 Min. : 2.41 Min. : 0.68 Min. : 2.17 Min. : 0.01 1st Qu.: 26.21 1st Qu.: 7.56 1st Qu.: 25.05 1st Qu.: 0. Median : 70.06 Median : 16.90 Median : 65. Median : 1.94 Mean : 407.06 Mean :104.75 Mean : 390.92 Mean : 28.91 > barplot(apply(e3.2,1,mean)) 3rd Qu.: 465.07 3rd Qu.: 77.25 3rd Qu.: 447.08 3rd Qu.: 31.75 Max. :3266.52 Max. :940.86 Max. :3120.18 Max. :350.60
0广州市50010001500珠海市江门市肇庆市汕尾市清远市潮州市> boxplot(e3.2)
050010001500200025003000x1x2x3x4
> stars(e3.2,full=T)
清远市东莞市中山市潮州市揭阳市惠州市梅州市汕尾市河源市阳江市佛山市江门市湛江市茂名市肇庆市广州市韶关市深圳市珠海市汕头市云浮市
> stars(e3.2,full=T,draw.segments=T)
云浮市清远市东莞市中山市潮州市揭阳市惠州市梅州市汕尾市河源市阳江市佛山市江门市湛江市茂名市肇庆市广州市韶关市深圳市珠海市汕头市
> plot.andrews(e3.2)
6000广州市韶关市深圳市珠海市汕头市佛山市江门市湛江市茂名市肇庆市惠州市梅州市汕尾市河源市阳江市清远市东莞市中山市潮州市揭阳市云浮市
-1000010002000300040005000-3-2-10123第四章 4.1
回归方程为
Y=-0.6667+1.2667x 残差平方和101.4667
残差为3.000000 3.333333 -5.200000 1.600000 -6.266667 3.533333
4.2
x1=c(10,5,7,19,11,8) x2=c(2,3,3,6,7,9) y=c(15,9,3,25,7,13) y=(y-mean(y))/sd(y) x1=(x1-mean(x1))/sd(x1) x2=(x2-mean(x2))/sd(x2) fm=lm(y~x1+x2) fm Call:
lm(formula = y ~ x1 + x2)
Coefficients:
(Intercept) x1 x2 5.319e-17 8.152e-01 -2.123e-02
x=c(10,5,7,19,11,8) y=c(15,9,3,25,7,13) x y plot(x,y) lxy<-function(x,y){n=length(x);sum(x*y)-sum(x)*sum(y)/n} lxy(x,x) lxy(x,y) b1=lxy(x,y)/lxy(x,x) b0=mean(y)-b1*mean(x) c(b1=b1,b0=b0) fm=lm(y~x) fm y1=b0+b1*x y1 e=y-y1 e e2=sum(e^2) e2 4.3
x=c(825,215,1070,550,480,920,1350,325,670,121相关系数为 0.94428 5) 残差的方差为0.2048199 y=c(3.5,1,4,2,1,3,4.5,1.5,3,5) plot(x,y) 回归方程为Y=0.1181+0.0036x cor(x,y) R2= 0.94428 lxy<-function(x,y){n=length(x);sum(x*y)-sum(x)*sum(y)/n}
lxy(x,x) lxy(x,y)
b=lxy(x,y)/lxy(x,x) a=mean(y)-b*mean(x)
y1=a+b*x e=y-y1
(sd(e))^2 fm=lm(y~x) fm (R2=summary(fm)$r.sq) 方差分析 (R=sqrt(R2)) Analysis of Variance Table anova(fm) y0=a+b*1000 Response: y y0 Df Sum Sq Mean Sq F value Pr(>F) x 1 16.6816 16.6816 72.396 2.795e-05 *** Residuals 8 1.8434 0.2304 ---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
X等于1000时预测y= 3.703262
123y45200400600800x100012004.4
e4.4=read.table(\"clipboard\ cor(e4.4) fm=lm(x3~x1+x2,data=e4.4) fm summary(fm) R=sqrt(summary(fm)$r.squared);R cor(e4.4)
x1 x2 x3 x1 1.0000000 0.3198116 0.5796714 x2 0.3198116 1.0000000 0.48153 x3 0.5796714 0.48153 1.0000000 Call:
lm(formula = x3 ~ x1 + x2, data = e4.4)
Coefficients:
(Intercept) x1 x2 -22.7450 0.1511 1.2166 Call:
lm(formula = x3 ~ x1 + x2, data = e4.4)
Residuals:
1 2 3 4 5 6 7 8
-1.1335 -3.9430 -0.6517 15.6699 -0.5939 2.7178 -16.2745 4.20
Coefficients:
Estimate Std. Error t value Pr(>|t|) (Intercept) -22.7450 30.6939 -0.741 0.492 x1 0.1511 0.1132 1.335 0.239 x2 1.2166 1.3094 0.929 0.395
Residual standard error: 10.52 on 5 degrees of freedom
Multiple R-squared: 0.4338, Adjusted R-squared: 0.2073 F-statistic: 1.915 on 2 and 5 DF, p-value: 0.2412
复相关系数R= 0.6586
解释变量与依赖变量之间线性关系不明显。
4.5 e4.5=read.table(\"clipboard\ fm=lm(y~x1+x2,data=e4.5);fm cor(e4.5) summary(fm) predict(fm,data.frame(x1=3,x2=24)) Call:
lm(formula = y ~ x1 + x2, data = e4.5)
Coefficients:
(Intercept) x1 x2
-5213.1 8508.8 181.6
回归方程为y=-5213.1+8508.8*x1+181.6*x2
Call:
lm(formula = y ~ x1 + x2, data = e4.5)
Residuals:
1 2 3 4 5 6 7 8 1617.4 206.9 1282.3 -703.6 -2215.0 -770.3 -310.6 2.9
Coefficients:
Estimate Std. Error t value Pr(>|t|) (Intercept) -5213.1 12704.5 -0.410 0.6986 x1 8508.8 2721.6 3.126 0.0261 * x2 181.6 283.5 0.1 0.5500 ---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1496 on 5 degrees of freedom
Multiple R-squared: 0.6677, Adjusted R-squared: 0.5347 F-statistic: 5.022 on 2 and 5 DF, p-value: 0.06368
可以看出X1即GPA对起始工资的影响是显著的,而年龄对起始工资的影响并不显著。
GPA=3.00,年龄为24岁时的起始工资为24671.16
4.6 e4.6=read.table(\"clipboard\cor(e4.6) pairs(e4.6,gap=0)fm=lm(y~x1+x2+x3,data=e4.6);fm summary(fm)library(leaps) varsel=regsubsets(y~x1+x2+x3,data=e4.6)result=summary(varsel) data.frame(result$outmat,RSS=result$rss,R2=result$rsq) Call: lm(formula = y ~ x1 + x2 + x3, data = e4.6)
Coefficients:
(Intercept) x1 x2 x3 -348.280 3.754 7.101 12.447 Call:
lm(formula = y ~ x1 + x2 + x3, data = e4.6)
Residuals:
Min 1Q Median 3Q Max -25.198 -17.035 2.627 11.677 33.225
Coefficients:
Estimate Std. Error t value Pr(>|t|) (Intercept) -348.280 176.459 -1.974 0.0959 .
x1 3.754 1.933 1.942 0.1002 x2 7.101 2.880 2.465 0.0488 * x3 12.447 10.569 1.178 0.2835 ---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 23.44 on 6 degrees of freedom
Multiple R-squared: 0.8055, Adjusted R-squared: 0.7083 F-statistic: 8.283 on 3 and 6 DF, p-value: 0.01487
x1 x2 x3 RSS R2 1 ( 1 ) * 7903.1 0.5338054 2 ( 1 ) * * 4059.301 0.7605485 3 ( 1 ) * * * 3297.130 0.8055077
从结果来看最优回归模型为y=-348.28+3.754*x1+7.101*x2+12.477*x3
667074781.02.03.04.074786670x13638404244x24.03.01.02.0x31602002403638404244160200y240
4.7 e4.7=read.table(\"clipboard\ cor(e4.7) pairs(e4.7,gap=0) fm=lm(Y~X1+X2+X3+X4+X5+X6+X7,data=e4.7);fm summary(fm) fm1=lm(Y~X2+X4+X5+X6+X7,data=e4.7);fm1 summary(fm1) fm.step=step(fm,direction=\"both\") library(leaps) varsel=regsubsets(y~x1+x2+x3,data=e4.6) result=summary(varsel) data.frame(result$outmat,RSS=result$rss,R2=result$rsq)
建立多元回归模型: Call:
lm(formula = Y ~ X1 + X2 + X3 + X4 + X5 + X6 + X7, data = e4.7)
Coefficients:
(Intercept) X1 X2 X3 X4 X5
-12.073680 -0.055770 -0.224494 0.094609 -2.1370 0.611382
X6 X7 0.002203 0.048863
显著性检验:
Coefficients:
Estimate Std. Error t value Pr(>|t|) (Intercept) -1.207e+01 9.705e+00 -1.244 0.23139 X1 -5.577e-02 3.027e-02 -1.843 0.08398 . X2 -2.245e-01 1.051e-01 -2.135 0.04854 * X3 9.461e-02 1.946e-01 0.486 0.63346 X4 -2.137e+00 5.972e-01 -3.579 0.00251 ** X5 6.114e-01 2.688e-01 2.274 0.03706 * X6 2.203e-03 7.022e-04 3.137 0.00636 ** X7 4.886e-02 1.771e-02 2.759 0.01399 * ---
重建回归方程与显著性检验: Call:
lm(formula = Y ~ X2 + X4 + X5 + X6 + X7, data = e4.7)
Coefficients:
(Intercept) X2 X4 X5 X6 X7
-20.915034 -0.281937 -2.746151 0.4136 0.001381 0.072278
Coefficients:
Estimate Std. Error t value Pr(>|t|) (Intercept) -2.092e+01 8.774e+00 -2.384 0.02836 * X2 -2.819e-01 1.086e-01 -2.595 0.01829 * X4 -2.746e+00 4.230e-01 -6.492 4.18e-06 *** X5 4.1e-01 1.4e-01 2.212 0.04013 *
X6 1.381e-03 4.043e-04 3.417 0.00308 ** X7 7.228e-02 1.428e-02 5.063 8.10e-05 ***
应用逐步回归法获得的最优模型Y ~ X1 + X2 + X4 + X5 + X6 + X7
Step: AIC=35.06
Y ~ X1 + X2 + X4 + X5 + X6 + X7
Df Sum of Sq RSS AIC 变量选择法获得的最优模型为Y~X1+X2+X3+X4+X5+X6+X7: X1 X2 X3 X4 X5 X6 X7 RSS R2 1 ( 1 ) * 554.07888 0.9834693 2 ( 1 ) * * 185.51830 0.9944651 3 ( 1 ) * * * 129.91097 0.9961242 4 ( 1 ) * * * * 85.37337 0.9974529 5 ( 1 ) * * * * * 73.20098 0.9978161 6 ( 1 ) * * * * * * 57.71056 0.9982782 7 ( 1 ) * * * * * * * 56.87054 0.9983033 06004012040140120020120Y060040120X3X4X5X6X720120100160612030000401401200030000612100X2160X1 4.8 4.9 fm=lm(Y~x1+x2+x3) g=Y-mean(Y) d=fm$fitted.values-mean(Y) e=Y-fm$fitted.values data.frame(总离差=g,回归=d,残差=e) c(R2=sum(d^2)/sum(g^2)) x=c(275,300,325,350,375) y=c(1.60,0.95,0.65,0.50,0.45) plot(x,y) lm.pow=lm(log(y)~log(x));summary(lm.pow)$coef summary(lm.pow)$r.sq plot(e4.9);lines(x,exp(fitted(lm.pow))) predict(lm.pow,data.frame(x=295)) 0.60.81.0y1.21.41.6280300320x340360 Estimate Std. Error t value Pr(>|t|) (Intercept) 23.638658 2.825720 8.365534 0.003581692 log(x) -4.143308 0.4873 -8.473490 0.003450851 直线回归方程为y1=23.-4.14x1 其中y1=logy,xi=logx,a1=loga 决定系数为0.95931 价格为295元时的市场销售率为1.079 4.10 x=c(3,5,10,30,40,50,60,80,100,120,160) y=c(310,200,100,49,40,32,28,23,16,14,10) plot(x,y) lm.1=lm(y~x);summary(lm.1)$r.sq x1=x;x2=x^2 lm.2=lm(y~x1+x2);summary(lm.2)$r.sq lm.log=lm(y~log(x));summary(lm.log)$r.sq lm.exp=lm(log(y)~x);summary(lm.exp)$r.sq lm.pow=lm(log(y)~log(x));summary(lm.pow)$r.sq summary(lm.pow)$coef plot(x,y);lines(x,exp(fitted(lm.pow))) 决定系数: 直线回归 0.466234 多项式回归0.7295078 对数法 0.8592786 指数法0.8217183 幂函数法 0.9933294 幂函数显然是最好的选择。 > summary(lm.pow)$coef Estimate Std. Error t value Pr(>|t|) (Intercept) 6.17280 0.08484557 78.28020 4.585597e-14 log(x) -0.8263118 0.02257138 -36.60882 4.194761e-11 050100150y200250300050x100150 4.11 e4.11=read.table(\"clipboard\ fm=lm(y~X1+X2+X3,data=e4.11);fm model=nls(log(y)~b1*log(X1)+b2*log(X2)+b3*log(X3/X2),data=e4.11,start=list(b1=1,b2=1, b3=1)) model summary(fm) summary(model) library(leaps) varsel=regsubsets(y~X1+X2+X3,data=e4.11) result=summary(varsel) data.frame(result$outmat,RSS=result$rss,R2=result$rsq,adjR2=result$adjr2,Cp=result$cp, BIC=result$bic) fm1=lm(y~X3,data=e4.11);fm summary(fm1) 拟合线性回归模型: Call: lm(formula = y ~ X1 + X2 + X3, data = e4.11) Coefficients: (Intercept) X1 X2 X3 6.081e+03 1.172e-01 -2.245e-02 9.096e-04 对数线性模型: Nonlinear regression model model: log(y) ~ b1 * log(X1) + b2 * log(X2) + b3 * log(X3/X2) data: e4.11 b1 b2 b3 1.30619 -0.39484 0.07031 residual sum-of-squares: 0.01914 Number of iterations to convergence: 1 Achieved convergence tolerance: 3.282e-06 线性模型检验: Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 6.081e+03 9.566e+03 0.636 0.538 X1 1.172e-01 2.673e-01 0.438 0.670 X2 -2.245e-02 3.321e-02 -0.676 0.513 X3 9.096e-04 8.659e-04 1.050 0.316 Residual standard error: 301.7 on 11 degrees of freedom Multiple R-squared: 0.9133, Adjusted R-squared: 0.86 F-statistic: 38.62 on 3 and 11 DF, p-value: 3.92e-06 对数线性模型检验: Parameters: Estimate Std. Error t value Pr(>|t|) b1 1.30619 0.49603 2.633 0.0218 * b2 -0.39484 0.41030 -0.962 0.3549 b3 0.07031 0.08551 0.822 0.4269 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 0.03994 on 12 degrees of freedom Number of iterations to convergence: 1 Achieved convergence tolerance: 3.282e-06 变量选择法: X1 X2 X3 RSS R2 adjR2 Cp 1 ( 1 ) * 1063207 0.90786 0.9008139 0.6843806 -30.356882 ( 1 ) * * 1018408 0.9117794 0.70760 2.1920514 -28.294573 ( 1 ) * * * 1000932 0.9132932 0.859 4.0000000 -25.84615 选择X3作为变量有: Call: lm(formula = y ~ X3, data = e4.11) Coefficients: (Intercept) X3 4.9e+03 1.493e-03 检验: Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 4.9e+03 2.031e+02 24.12 3.54e-12 *** X3 1.493e-03 1.319e-04 11.32 4.19e-08 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 286 on 13 degrees of freedom Multiple R-squared: 0.9079, Adjusted R-squared: 0.9008 F-statistic: 128.1 on 1 and 13 DF, p-value: 4.192e-08 R2达到了0.9079,拟合效果比对数模型要好。 BIC 4.12 e4.12=read.table(\"clipboard\ lm.pow=lm(log(EXPDUR)~log(PCEXP),data=e4.12) summary(lm.pow) lm.exp=lm(log(EXPS)~t,data=e4.12) summary(lm.exp) Call: lm(formula = log(EXPDUR) ~ log(PCEXP), data = e4.12) Coefficients: (Intercept) log(PCEXP) -9.697 1.906 幂函数回归方程为EXPDUR6.14105PCEXP1.9056 指数模型: Call: lm(formula = log(EXPS) ~ t, data = e4.12) Residuals: Min 1Q Median 3Q Max -0.006169 -0.003692 -0.001653 0.003051 0.014052 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 7.788347 0.0022 3402.20 <2e-16 *** t 0.007466 0.000167 44.72 <2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 0.005311 on 21 degrees of freedom Multiple R-squared: 0.96, Adjusted R-squared: 0.91 F-statistic: 2000 on 1 and 21 DF, p-value: < 2.2e-16 指数回归方程为: EXPSt2411(10.007)t 故r=0.007 5.1 x=c(103,101,98,110) y=c(113,107,108,116,115,109) z=c(82,92,84,86,88) x=c(x,y,z) a=c(1,1,1,1,2,2,2,2,2,2,3,3,3,3,3) fm=lm(x~factor(a)) anova(fm) Analysis of Variance Table Response: x Df Sum Sq Mean Sq F value Pr(>F) factor(a) 2 1721.87 860.93 49.072 1.672e-06 *** Residuals 12 210.53 17.54 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 因素a显著,所以平均强度不同。 5.2 y=c(.9,69.1,76.1,82.9,62.6,70.1,74,80,61.1, 66.8,71.3,76,59.2,63.6,67.2,72.3) a=c(1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4) b=c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4) anova(lm(y~factor(a)+factor(b))) 方差分析: Analysis of Variance Table Response: y Df Sum Sq Mean Sq F value Pr(>F) factor(a) 3 547.61 182.537 118.06 1.520e-07 *** factor(b) 3 137.07 45.688 29.55 5.449e-05 *** Residuals 9 13.92 1.546 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 a, b均显著,说明不同配方,不同日期对生产率均有影响。 5.3 y=c(28,25,27,36,32,32,18,19,23,31,30,29) a=c(1,1,1,2,2,2,1,1,1,2,2,2) b=c(1,1,1,1,1,1,2,2,2,2,2,2) fm=lm(y~factor(a)+factor(b)+factor(a):factor(b)) anova(fm) 一般线性模型其矩阵表示为: y112811010y1010e1111y251111010e11y273612110110e11e21y210110y011032132211e211y121811001e212y191211001 e121ey12231001122ey122010112e22y311223010101y222910101e22e22 方差分析: Analysis of Variance Table Response: y Df Sum Sq Mean Sq F value Pr(>F) factor(a) 1 208.333 208.333 53.1915 8.444e-05 *** factor(b) 1 75.000 75.000 19.14 0.002362 ** factor(a):factor(b) 1 8.333 8.333 2.1277 0.182776 Residuals 8 31.333 3.917 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’因素a、b显著,交互作用不显著。 1 5.4 y=c(60.7,61.1,61.5,60.8,60.6,60.3,61.5,61.3,61.7,61.2,60.6,61,61.6,62,62.2,62.8,61.4,61.5,61.7,61.1,62.1,61.7,60.7,60.9) a=c(1,1,2,2,3,3,1,1,2,2,3,3,1,1,2,2,3,3,1,1,2,2,3,3) b=c(1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4) fm=lm(y~factor(a)+factor(b)+factor(a):factor(b)) anova(fm) 方差分析: Analysis of Variance Table Response: y Df Sum Sq Mean Sq F value Pr(>F) factor(a) 2 3.0833 1.5417 16.2281 0.0003868 *** factor(b) 3 3.6300 1.2100 12.7368 0.0004872 *** factor(a):factor(b) 6 0.3000 0.0500 0.5263 0.7782903 Residuals 12 1.1400 0.0950 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 由方差分析结果来看因素a与因素b均显著,但ab的交互作用对提高利用率没有影响。 5.5 y=c(160,215,180,168,236,190,157,205,140) a=c(1,1,1,2,2,2,3,3,3) b=c(1,2,3,1,2,3,1,2,3) c=c(1,2,3,2,3,1,3,1,2) fm=lm(y~factor(a)+factor(b)+factor(c)) anova(fm) Analysis of Variance Table Response: y Df Sum Sq Mean Sq F value Pr(>F) factor(a) 2 1421.6 710.78 12.2314 0.07558 . factor(b) 2 5686.9 2843.44 48.9312 0.02003 * factor(c) 2 427.6 213.78 3.6788 0.21373 Residuals 2 116.2 58.11 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 由方差分析的结果来看因素a和因素b,对实验结果是有显著影响的因素c的影响不显著。利用直观分析法可以得出最佳的方案是充磁量选择第2水平,定位角度选择第2水平,定子线圈匝数选择第3水平。 5.6 e5.6=read.table(\"clipboard\ logit.glm<-glm(G~x1+x2,data=e5.6) summary(logit.glm) 分析结果: Call: glm(formula = G ~ x1 + x2, data = e5.6) Deviance Residuals: Min 1Q Median 3Q Max -0.70312 -0.14109 -0.04428 0.18048 0.58624 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.4125311 0.0994961 14.197 2.72e-09 *** x1 0.0006129 0.0010550 0.581 0.5712 x2 -0.2813970 0.065 -4.081 0.0013 ** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Dispersion parameter for gaussian family taken to be 0.1094161) Null deviance: 4.0000 on 15 degrees of freedom Residual deviance: 1.4224 on 13 degrees of freedom AIC: 14.682 Number of Fisher Scoring iterations: 2 得到的初步Logistic回归方程为: pexp(1.413+0.001x10.281x2) 1exp(1.413+0.001x10.281x2) 5.7 e5.7=read.table(\"clipboard\ logit.glm<-glm(G~x1+x2+x3+x4,data=e5.7) summary(logit.glm) 分析结果: Call: glm(formula = G ~ x1 + x2 + x3 + x4, data = e5.7) Deviance Residuals: Min 1Q Median 3Q Max -0.52180 -0.30835 0.01688 0.21148 0.84797 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.117469 0.338886 3.297 0.00711 ** x1 0.010714 0.005309 2.018 0.06863 . x2 -0.129014 0.071329 -1.809 0.09788 . x3 -0.011146 0.011805 -0.944 0.36536 x4 -0.002192 0.004885 -0.449 0.66243 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Dispersion parameter for gaussian family taken to be 0.1948263) Null deviance: 4.0000 on 15 degrees of freedom Residual deviance: 2.1431 on 11 degrees of freedom AIC: 25.241 Number of Fisher Scoring iterations: 2 即 Logit(p)=1.1174+0.0107x1-0.129x2-0.0111x3-0.0021x4
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- huatuo9.cn 版权所有 赣ICP备2023008801号-1
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务