




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、第二章答案:x-c(1,2,3)y-c(4,5,6)e-c(1,1,1)z=2*x+y+ez1=crossprod(x,y)#z1 為 x1 與 x2 的內(nèi)積 或者 x%*%yz2=tcrossprod(x,y)#z1 為 x1 與 x2 的外積 或者 x%o%yz;z1;z2要點(diǎn):基本的列表賦值方法,內(nèi)積和外積概念。內(nèi)積為標(biāo)量,外積為矩陣。A-matrix(1:20,c(4,5);AB-matrix(1:20,nrow=4,byrow=TRUE);BC=A+B;C不存在AB這種寫法E=A*B;EF-A1:3,1:3;FH-matrix(c(1,2,4,5),nrow=1);HH起過渡作用,不
2、規(guī)則的數(shù)組下標(biāo)G-B,H;G要點(diǎn):矩陣賦值方法。默認(rèn)是byrow=FALSE數(shù)據(jù)按歹U放置。取出部分?jǐn)?shù)據(jù)的方法??梢杂脭?shù)組作為數(shù)組的下標(biāo)取出數(shù)組元素。x-c(rep(1,times=5),rep(2,times=3),rep(3,times=4),rep(4,times=2);x # 或者省略 times=,如下面 的形式x-c(rep(1,5),rep(2,3),rep(3,4),rep(4,2);x要點(diǎn):rep ()的使用方法。rep (a,b)即將a重復(fù)b次 n - 5; H-array(0,dim=c(n,n)for (i in 1:n)for (j in 1:n)Hi,j-1/(i+
3、j-1);HG - solve(H);G 球 H的逆矩陣ev - eigen(H);ev #求H的特征值和特征向量要點(diǎn):數(shù)組初始化;for循環(huán)的使用待解決:如何將很長的命令(如 for循環(huán))用幾行打出來再執(zhí)行?每次想換行的時(shí)候一按回 車就執(zhí)行了還沒打完的命令StudentData-data.frame(name=c(zhangsan,lisi,wangwu,zhaoliu,dingyi),sex=c(F,M,F,M,F),a ge=c(14,15,16,14,15),height=c(156,165,157,162,159),weight=c(42,49,41. 5,52,45.5);Stud
4、entData要點(diǎn):數(shù)據(jù)框的使用待解決:SSH登陸linux服務(wù)器中文顯示亂碼。此處用英文代替。write.table(StudentData,file=studentdata.txt)把數(shù)據(jù)框 StudentData在工作目錄里輸出,車出的文件名為 studentdata.txt.StudentData_a-read.table(studentdata.txt);StudentData_a以數(shù)據(jù)框的形式讀取文檔,存入數(shù)據(jù)框StudentData_a中。write.csv(StudentData_a,studentdata.csv)把數(shù)據(jù)框 StudentData_a在工作目錄里輸出,輸出的文
5、件名為studentdata.csv,可用Excel打開.要點(diǎn):讀寫文件。read.table(file)write.table(Rdata,file) read.csv(file) write.csv(Rdata,file) 外部文件,不論是待讀入或是要寫出的,命令中都得加雙引號(hào)。Fun-function(n)if(n = 0)list(fail=please input a integer above 0!)elserepeatif(n=1) breakelse if(n%2=0)n-n/2else n- 3*n+1list(sucess!)在linux下新建一個(gè)R文件,輸入上述代碼,保存
6、為 2.7.R然后在當(dāng)前目錄下進(jìn)入R環(huán)境,輸入source(2.7.R),即打開了這個(gè)程序腳本。然后就可以執(zhí)行函數(shù)了。輸入Fun(67),顯示sucess!輸入Fun(-1),顯示$fail1 please input a integer above 0!待解決:source(*.R)是可以理解為載入這個(gè)R文件吧?如何在 R環(huán)境下關(guān)閉R文件呢?OK,自己寫的第一個(gè) R程序新建txt文件如下:編寫一個(gè)函數(shù)(程序名為)描述樣本的各種描述性統(tǒng)計(jì)量。data_outline-function(x) n-length(x) m-mean(x) v-var(x) s-sd(x) me-median(x)
7、cv-100*s/m css-sum(x-m)A2) uss-sum(xA2) R - max(x)-min(x) R1 -quantile(x,3/4)-quantile(x,1/4) sm -s/sqrt(n)g1 -n/(n-1)*(n-2)*sum(x-m)A3)/sA3g2 -(n*(n+1)/(n-1)*(n-2)*(n-3)*sum(x-m)A4)/sA4-(3*(n-1)A2)/(n-2)*(n-3)data.frame(N=n,Mean=m,Var=v,std_dev=s,Median=me,std_mean=sm,CV=cv,CSS=css,USS=uss,R= R,R1=
8、R1,Skewness=g1,Kurtosis=g2,s=1)進(jìn)入R,source(data_outline.R) # 將程序調(diào)入內(nèi)存serumdata-scan(3.1.txt);serumdata # 將數(shù)據(jù)讀入向量 serumdata。 data_outline(serumdata)結(jié)果如下:N Mean Var std_dev Median std_mean CV CSS USS R1 100 73.696 15.41675 3.92641773.5 0.3926417 5.327857 1526.258 544636.3 20R1 Skewness Kurtosis要
9、點(diǎn):read.table()用于讀表格形式的文件。上述形式的數(shù)據(jù)由于第七行缺幾個(gè)數(shù)據(jù),故用 read.table()不能讀入。scan()可以直接讀純文本文件。scan()和matrix()連用還可以將數(shù)據(jù)存放成矩陣形式。X-matrix(scan(3.1.txt,0),ncol=10,byrow=TRUE)# 將上述數(shù)據(jù)放置成10*10的矩陣。scan()還可以從屏幕上直接輸入數(shù)據(jù)。Yhist(serumdata,freq=FALSE,col=purple,border=red,density=3,angle=60,main=paste(the histogram of serumdata)
10、,xlab=age,ylab=frequency)# 直方圖。col 是填充顏色。 默認(rèn)空白。 border是邊框的顏色,默認(rèn)前景色。density是在圖上畫條紋陰影,默認(rèn)不畫。angle是條紋陰影的傾斜角度(逆時(shí)針方向),默認(rèn)45度。main, xlab, ylab是 標(biāo)題,x和y坐標(biāo)軸名稱。 lines(density(serumdata),col=blue)# 密度估計(jì)曲線。xboxplot(serumdata,col=lightblue,notch=T) # 作箱線圖。notch 表示帶有缺口。fivenum(serumdata) # 五數(shù)總結(jié)shapiro.test(serumdat
11、a) # 正態(tài)性 Shapori-Wilk 檢驗(yàn)方法Shapiro-Wilk normality testdata: serumdata 結(jié)論:p值,可認(rèn)為來自正態(tài)分布的總體。ks.test(serumdata,pnorm,mean(serumdata),sd(serumdata) #Kolmogrov-Smirnov 檢驗(yàn),正態(tài) 性O(shè)ne-sample Kolmogorov-Smirnov testdata: serumdataalternative hypothesis: two-sidedWarning message:In ks.test(serumdata, pnorm, mean(
12、serumdata), sd(serumdata): cannot compute correct p-values with ties結(jié)論:p值,可認(rèn)為來自正態(tài)分布的總體。注意,這里的警告信息,是因?yàn)閿?shù)據(jù)中有重復(fù)的數(shù)值,ks檢驗(yàn)要求待檢數(shù)據(jù)時(shí)連續(xù)的,不允許重復(fù)值。y-c(2,4,3,2,4,7,7,2,2,5,4,5,6,8,5,10,7,12,12,6,6,7,11,6,6,7,9,5,5,10,6,3,10) # 輸入數(shù)據(jù)f-factor(c(rep(1,11),rep(2,10),rep(3,12) # 因子分類plot(f,y,col=lightgreen) #plot()生成箱線圖
13、x-c(2,4,3,2,4,7,7,2,2,5,4)y-c(5,6,8,5,10,7,12,12,6,6)z-c(7,11,6,6,7,9,5,5,10,6,3,10)boxplot(x,y,z,names=c(1,2,3),col=c(5,6,7)#boxplot()生成箱線圖結(jié)論:第2和第3組沒有顯著差異。第 1組合其他兩組有顯著差異。數(shù)據(jù)太多,懶得錄入。離散圖應(yīng)該用plot即可。studata names(studata)-c(stuno,name,sex,age,height,weight),studata #給各列命名stuno name sex age height weighta
14、ttach(studata) #將數(shù)據(jù)框調(diào)入內(nèi)存plot(weightheight,col=red) # 體重對于身高的散點(diǎn)圖coplot(weightheight|sex,col=blue) # 不同性別,體重與身高的散點(diǎn)圖coplot(weightheight|age,col=blue) # 不同年齡,體重與身高的散點(diǎn)圖coplot(weightheight|age+sex,col=blue) # 不同年齡和性別,體重與身高的散點(diǎn)圖x-seq(-2,3,0.05)y-seq(-1,7,0.05)f-function(x,y) xA4-2*xA2*y+xA2-2*x*y+2*yA2+4.5*
15、x-4*y+4z contour(x,y,z,levels=c(0,1,2,3,4,5,10,15,20,30,40,50,60,80,100),col=blue) # 二維等值線 persp(x,y,z,theta=120,phi=0,expand=0.7,col=lightblue) # 三位網(wǎng)格曲面 attach(studata) cor.test(height,weight) #Pearson 相關(guān)性檢驗(yàn)Pearsons product-moment correlationdata: height and weight alternative hypothesis: true corr
16、elation is not equal to 0 95 percent confidence interval:sample estimates: cor由此可見身高和體重是相關(guān)的。上述兩題原始數(shù)據(jù)太多,網(wǎng)上找不到,懶得錄入。略。指數(shù)分布,入的極大似然估計(jì)是 n/sum(Xi)x lamda x mean(x)ll平均為1個(gè)。obj-function(x)f x0 x x y t.test(x,y,var .equal=TRUE)Two Sample t-testdata: x and yalternative hypothesis: true difference in means is
17、not equal to 095 percent confidence interval:sample estimates:mean of x mean of y140.6期望差的95%置信區(qū)間為 7.53626 20.06374。要點(diǎn):t.test()可做兩正態(tài)樣本均值差估計(jì)。此例認(rèn)為兩樣本方差相等。ps :我怎么覺得這題應(yīng)該用配對t檢驗(yàn)?x-c(0.143,0.142,0.143,0.137)y var .test(x,y)F test to compare two variancesdata: x and yalternative hypothesis: true ratio of va
18、riances is not equal to 195 percent confidence interval:sample estimates:ratio of variances要點(diǎn):可做兩樣本方差比的估計(jì)?;诖私Y(jié)果可認(rèn)為方差不等。因此,在中,計(jì)算期望差時(shí)應(yīng)該采取方差不等的參數(shù)。 t.test(x,y)Welch Two Sample t-testdata: x and yalternative hypothesis: true difference in means is not equal to 095 percent confidence interval: sample esti
19、mates: mean of x mean of y 140.6期望差的95%置信區(qū)間為 7.359713 20.240287。要點(diǎn):t.test(x,y , var .equal=TRUE)做方差相等的兩正態(tài)樣本的均值差估計(jì)t.test(x,y)做方差不等的兩正態(tài)樣本的均值差估計(jì)x-c(rep(0,7),rep(1,10),rep(2,12),rep(3,8),rep(4,3),rep(5,2)n-length(x)tmp mean(x)mean(x)-tmp;mean(x)+tmp平均呼喚次數(shù)為的置信區(qū)間為1.49,2,32 x t.test(x,alternative=greater)O
20、ne Sample t-test data: x alternative hypothesis: true mean is greater than 095 percent confidence interval:920.8443 Infsample estimates: mean of x燈泡平均壽命置信度 95%的單側(cè)置信下限為920.8443要點(diǎn):t.test()做單側(cè)置信區(qū)間估計(jì)x t.test(x,mu=225,alternative=less)One Sample t-testdata: xalternative hypothesis: true mean is less than
21、 22595 percent confidence interval:sample estimates:mean of x同樣可得出油漆工人的血小板計(jì)數(shù)小于正常成年男子的結(jié)論。 pnorm(1000,mean(x),sd(x) x1 1067 919 1196 785 1126 936 918 1156 920 948 pnorm(1000,mean(x),sd(x)x=1000的概率為0.509,故x大于1000的概率為0.491.要點(diǎn):pnorm 計(jì)算正態(tài)分布的分布函數(shù)。在 R軟件中,計(jì)算值均為下分位點(diǎn)。A-c(113,120,138,120,100,118,138,123)Bxy sha
22、piro.test(x)Shapiro-Wilk normality test data: x shapiro.test(y)Shapiro-Wilk normality testdata: yks檢驗(yàn): ks.test(x,pnorm,mean(x),sd(x)One-sample Kolmogorov-Smirnov testdata: x alternative hypothesis: two-sidedWarning message:In ks.test(x, pnorm, mean(x), sd(x): cannot compute correct p-values with tie
23、s ks.test(y,pnorm,mean(y),sd(y)One-sample Kolmogorov-Smirnov test |data: yalternative hypothesis: two-sided|Warning message:In ks.test(y, pnorm, mean(y), sd(y): cannot compute correct p-values with tiespearson擬合優(yōu)度檢驗(yàn),以x為例。 sort(x)1 -5.6 -1.6 -1.4 -0.7 -0.5 0.4 0.7 1.7 2.0 2.5 2.5 2.8 3.0 3.54.5 4.6 5
24、.8 6.0 x1-table(cut(x,br=c(-6,-3,0,3,6,9)p p t.test(x,y,var .equal=TRUE)Two Sample t-testdata: x and yalternative hypothesis: true difference in means is not equal to 095 percent confidence interval:-2.326179sample estimates:mean of x mean of y2.065方差不同模型t檢驗(yàn): t.test(x,y)Welch Two Sample t-testdata:
25、x and yalternative hypothesis: true difference in means is not equal to 095 percent confidence interval:-2.32926sample estimates:mean of x mean of y2.065配對t檢驗(yàn): t.test(x,y,paired=TRUE)Paired t-testdata: x and yalternative hypothesis: true difference in means is not equal to 095 percent confidence int
26、erval:-2.373146sample estimates: mean of the differences三種檢驗(yàn)的結(jié)果都顯示兩組數(shù)據(jù)均值無差異。 var .test(x,y)F test to compare two variancesdata: x and yalternative hypothesis: true ratio of variances is not equal to 195 percent confidence interval:sample estimates:ratio of variances接受原假設(shè),兩組數(shù)據(jù)方差相同。 a b ks.test(a,pnor
27、m,mean(a),sd(a)One-sample Kolmogorov-Smirnov test data: aalternative hypothesis: two-sided ks.test(b,pnorm,mean(b),sd(b)One-sample Kolmogorov-Smirnov test data: balternative hypothesis: two-sidedWarning message:In ks.test(b, pnorm, mean(b), sd(b): cannot compute correct p-values with ties a和b都服從正態(tài)分布
28、。方差齊性檢驗(yàn): var .test(a,b)F test to compare two variancesdata: a and b alternative hypothesis: true ratio of variances is not equal to 195 percent confidence interval:sample estimates:ratio of variances可認(rèn)為a和b的方差相同。選用方差相同模型t檢驗(yàn): t.test(a,b,var .equal=TRUE)Two Sample t-testdata: a and balternative hypothe
29、sis: true difference in means is not equal to 095 percent confidence interval:sample estimates:mean of x mean of y125.5833可認(rèn)為兩者有差別。二項(xiàng)分布總體的假設(shè)檢驗(yàn): binom.test(57,400,p=0.147)Exact binomial testdata: 57 and 400 _|95 percent confidence interval:sample estimates:probability of successP值,故接受原假設(shè),表示調(diào)查結(jié)果支持該市老年
30、人口的看法二項(xiàng)分布總體的假設(shè)檢驗(yàn): binom.test(178,328,p=0.5,alternative=greater)Exact binomial test data: 178 and 32895 percent confidence interval:sample estimates:probability of success不能認(rèn)為這種處理能增加母雞的比例。利用pearson卡方檢驗(yàn)是否符合特定分布: chisq.test(c(315,101,108,32),p=c(9,3,3,1)/16)Chi-squared test for given probabilitiesdata:
31、 c(315, 101, 108, 32)接受原假設(shè),符合自由組合定律。利用pearson卡方檢驗(yàn)是否符合泊松分布:n-length(z)y-c(92,68,28,11,1,0)x-0:5q-ppois(x,mean(rep(x,y);n-length(y)p1 chisq.test(z,p=p)Chi-squared test for given probabilities data: z可認(rèn)為數(shù)據(jù)服從泊松分布。ks檢驗(yàn)兩個(gè)分布是否相同:x-c(2.36,3.14,752,3.48,2.76,5.43,6.54,7.41)y-c(4.38,4.25,6.53,3.28,7.21,6.55)k
32、s.test(x,y)Two-sample Kolmogorov-Smirnov testdata: x and yalternative hypothesis: two-sided列聯(lián)數(shù)據(jù)的獨(dú)立性檢驗(yàn):x - c(358,2492,229,2745)dim(x)-c(2,2)chisq.test(x)Pearsons Chi-squared test with Yates continuity correction data: xP值0.05,拒絕原假設(shè),有影響。列聯(lián)數(shù)據(jù)的獨(dú)立性檢驗(yàn):y,1,2 ,31, 45 12 102, 46 20 283, 28 23 304, 11 12 35ch
33、isq.test(y)Pearsons Chi-squared testdata: yP值=14.6;H1:中位數(shù) x14.6,length(x),al=T) |Exact binomial testdata: sum(x) 14.6 and length(x)95 percent confidence interval: sample estimates:probability of success拒絕原假設(shè),中位數(shù)小于Wilcoxon符號(hào)秩檢驗(yàn): wilcox.test(x,mu=14.6,al=l,exact=F)Wilcoxon signed rank test with contin
34、uity correctiondata: x拒絕原假設(shè),中位數(shù)小于符號(hào)檢驗(yàn)法: TOC o 1-5 h z xy binom.test(sum(xy),length(x) |Exact binomial testdata: sum(x y) and length(x)95 percent confidence interval:sample estimates:probability of success接受原假設(shè),無差別。Wilcoxon符號(hào)秩檢驗(yàn):wilcox.test(x,y,paired=TRUE,exact=FALSE)Wilcoxon signed rank test with c
35、ontinuity correctiondata: x and y alternative hypothesis: true location shift is not equal to 0拒絕原假設(shè),有差別。Wilcoxon 秩和檢驗(yàn):wilcox.test(x,y,exact=FALSE)Wilcoxon rank sum test with continuity correction data: x and y alternative hypothesis: true location shift is not equal to 0拒絕原假設(shè),有差別。正態(tài)性檢驗(yàn): TOC o 1-5 h
36、 z ks.test(x,pnorm,mean(x),sd(x) |One-sample Kolmogorov-Smirnov test |data: xalternative hypothesis: two-sided|Warning message:In ks.test(x, pnorm, mean(x), sd(x):cannot compute correct p-values with tiesks.test(y,pnorm,mean(y),sd(y)One-sample Kolmogorov-Smirnov test data: yalternative hypothesis: t
37、wo-sided兩組數(shù)據(jù)均服從正態(tài)分布。方差齊性檢驗(yàn):var .test(x,y)F test to compare two variancesdata: x and y alternative hypothesis: true ratio of variances is not equal to 195 percent confidence interval:sample estimates:ratio of variances可認(rèn)為兩組數(shù)據(jù)方差相同。綜上,該數(shù)據(jù)可做t檢驗(yàn)。t檢驗(yàn):t.test(x,y,var .equal=TRUE)Two Sample t-test data: x an
38、d y alternative hypothesis: true difference in means is not equal to 095 percent confidence interval:sample estimates:mean of x mean of y33.215拒絕原假設(shè),有差別。綜上所述,Wilcoxon符號(hào)秩檢驗(yàn)的差異檢出能力最強(qiáng),符號(hào)檢驗(yàn)的差異檢出最弱。spearman秩相關(guān)檢驗(yàn):x-c(24,17,20,41,52,23,46,18,15,20)y-c(8,1,4,7,9,5,10,3,2,6)cor .test(x,y,method=spearman,exac
39、t=F)Spearmans rank correlation rhodata: x and yalternative hypothesis: true rho is not equal to 0sample estimates:rhokendall秩相關(guān)檢驗(yàn):cor .test(x,y,method=kendall,exact=F)Kendalls rank correlation taudata: x and yalternative hypothesis: true tau is not equal to 0sample estimates:tau二者有關(guān)系,呈正相關(guān)。x-rep(1:5,
40、c(0,1,9,7,3);y x y plot(x,y)由此判斷,Y和X有線性關(guān)系。. lm.sol summary(lm.sol)Call:lm(formula = y 1 + x)Residuals:_ Min1Q 二Median = 3QMax-128.591 -70.978 -3.727 49.263Coefficients:Estimate Std. Error t value Pr(|t|)(Intercept) 140.95125.11 1.127 0.293x 364.1819.26 18.908 6.33e-08 *Signif. codes: 0 * 0.001 * 0.0
41、1 * 0.05 . 0.1 1Residual standard error: 96.42 on 8 degrees of freedomMultiple R-squared: 0.9781,F-statistic: 357.5 on 1 and 8 DF ,回歸方程為31項(xiàng)很顯著,但常數(shù)項(xiàng)30不顯著?;貧w方程很顯著。new - data.frame(x=7) |lm.predpho-data.frame(x1-c(0.4,0.4,3.1,0.6,4.7,1.7,9.4,10.1,11.6,12.6,10.9,23.1,23.1,21.6,23.1,1.9,26 .8,29.9), x2 -
42、 c(52,34,19,34,24,65,44,31,29,58,37,46,50,44,56,36,58,51), x3-c(158,163,37,157,59,123,46,117,173,112,111,114,134,73,168,143,202,124), y lm.sol summary(lm.sol) Call: lm(formula = y x1 + x2 + x3, data = pho) Residuals: Min 1Q Median 3Q Max |-27.575 -11.160 -2.799 11.574 Coefficients:Estimate Std. Erro
43、r t value Pr(|t|) (Intercept) 44.9290 18.3408 2.450 0.02806 * x11.80330.52903.4090.00424 *x2-0.13370.4440-0.3010.76771x30.16680.11411.4620.16573Signif. codes: 0 * 0.001 * 0.01 * 0.05 . 0.1 1Residual standard error: 19.93 on 14 degrees of freedomMultiple R-squared: 0.551,|F-statistic: 5.726 on 3 and
44、14 DF,回歸方程為回歸方程顯著,但有些回歸系數(shù)不顯著。1m.step 5563.4x31849.8 6413.1x114617.8 10181.2Step:_|y x1 + x3Df Sum of Sq RSS AIC 5599.4 -x3 1833.2 6432.6x11 5169.5 10768.9summary(lm.step)Call:lm(formula = y x1 + x3, data = pho)Residuals:Min 1Q Median 3Q Max -29.713 -11.324 -2.953 11.286Coefficients:Estimate Std. Err
45、or t value Pr(|t|) (Intercept) 41.4794 13.8834 2.988 0.00920 * x11.73740.4669 3.721 0.00205 *x30.15480.1036 1.494 0.15592Signif. codes: 0 ,* 0.001 * 0.01 * 0.05 . 0.1 1Residual standard error: 19.32 on 15 degrees of freedom Multiple R-squared: 0.5481, F-statistic: 9.095 on 2 and 15 DF,x3仍不夠顯著。再用drop
46、1函數(shù)做逐步回歸。drop1(lm.step) Single term deletionsModel: y x1 + x3 Df Sum of Sq RSS AIC 5599.4 x11 5169.5 10768.9x31833.2 6432.6可以考慮再去掉x3. lm.opt|t|) (Intercept) 59.25907.4200 7.986 5.67e-07 *x1 1.84340.4789 3.849 0.00142 *Signif. codes: 0 ,* 0.001 * 0.01 * 0.05 . 0.1 1Residual standard error: 20.05 on 1
47、6 degrees of freedomMultiple R-squared: 0.4808,F-statistic: 14.82 on 1 and 16 DF,皆顯著。 xy-c(0.6,1.6,0.5,1.2,2.0,1.3,2.5,2.2,2.4,1.2,3.5,4.1,5.1,5.7,3.4,9.7,8.6,4.0,5.5,10.5,17.5,13.4,4.5,30.4,12.4,13.4,26.2,7.4)plot(x,y)lm.sol summary(lm.sol)Call:lm(formula = y 1 + x)Residuals:Min 1Q Median 3Q Max -9
48、.8413 -2.3369 -0.0214Coefficients:Estimate Std. Error t value Pr(|t|) (Intercept) -1.45191.8353 -0.791 0.436x 1.55780.2807 5.549 7.93e-06 *Signif. codes: 0 ,* 0.001 * 0.01 * 0.05 . 0.1 1Residual standard error: 5.168 on 26 degrees of freedomMultiple R-squared: 0.5422,F-statistic: 30.8 on 1 and 26 DF
49、,線性回歸方程為,通過 F檢驗(yàn)。常數(shù)項(xiàng)參數(shù)未通過t檢驗(yàn)。abline(lm.sol) y.yes y.fit y.rst plot(y.yesy.fit)yjit plot(y.rst-y.fit)殘差并非是等方差的。修正模型,對相應(yīng)變量 Y做開方。 lm.new summary(lm.new)Call:lm(formula = sqrt(y) x)Residuals:Min 1Q Median 3Q Max -1.54255-0.45280 -0.01177 0.34925Coefficients:Estimate Std. Error t value Pr(|t|) (Intercept)
50、 0.76650 0.25592 2.995 0.00596 * x 0.29136 0.03914 7.444 6.64e-08 *Signif. codes: 0 ,* 0.001 * 0.01 * 0.05 . 0.1 1Residual standard error: 0.7206 on 26 degrees of freedomMultiple R-squared: 0.6806,F-statistic: 55.41 on 1 and 26 DF,此時(shí)所有參數(shù)和方程均通過檢驗(yàn)。24和第28個(gè)值對新模型做標(biāo)準(zhǔn)化殘差圖,情況有所改善,不過還是存在一個(gè)離群值。第 存在問題。 toothpa
51、ste lm.sol|t|) (Intercept) 4.07590.6267 6.504 1.00e-06 *X11.52760.23546.489 1.04e-06 *X20.61380.10275.974 3.63e-06 *Signif. codes: 0 ,* 0.001 * 0.01 * 0.05 . 0.1 1Residual standard error: 0.1767 on 24 degrees of freedomMultiple R-squared: 0.9378,F-statistic: 181 on 2 and 24 DF ,回歸診斷: influence.measu
52、res(lm.sol) Influence measures oflm(formula = Y X1 + X2, data = toothpaste):dfb.1_ dfb.X1 dfb.X2 dffit cov.r cook.d hat inf0.00908 0.00260 -0.00847 0.0121 1.366 5.11e-05 0.16810.06277 0.04467 -0.06785 -0.1244 1.159 5.32e-03 0.0537-0.02809 0.07724 0.02540 0.1858 1.283 1.19e-02 0.13860.11688 0.05055 -
53、0.11078 0.1404 1.377 6.83e-03 0.1843 *0.01167 0.01887 -0.01766 -0.1037 1.141 3.69e-03 0.0384-0.43010 -0.42881 0.45774 0.6061 0.814 1.11e-01 0.09360.07840 0.01534 -0.07284 0.1082 1.481 4.07e-03 0.2364 *0.01577 0.00913 -0.01485 0.0208 1.237 1.50e-04 0.08230.01127 -0.02714 -0.00364 0.1071 1.156 3.95e-0
54、3 0.0466-0.07830 0.00171 0.08052 0.1890 1.155 1.22e-02 0.07260.00301 -0.09652 -0.00365 -0.2281 1.127 1.76e-02 0.0735-0.03114 0.01848 0.03459 0.1542 1.132 8.12e-03 0.0514-0.09236 -0.03801 0.09940 0.2201 1.071 1.62e-02 0.0522-0.02650 0.03434 0.02606 0.1179 1.235 4.81e-03 0.09560.00968 -0.11445 -0.0085
55、7 -0.2545 1.150 2.19e-02 0.0910-0.00285 -0.06185 0.00098 -0.1608 1.146 8.83e-03 0.05940.07201 0.09744 -0.07796 -0.1099 1.364 4.19e-03 0.173118 0.15132 0.30204 -0.17755 -0.3907 1.087 5.04e-02 0.108519 0.07489 0.47472 -0.12980 -0.7579 0.731 1.66e-01 0.109220 0.05249 0.08484 -0.07940 -0.4660 0.625 6.11
56、e-02 0.0384 *21 0.07557 0.07284 -0.07861 -0.0880 1.471 2.69e-03 0.2304 *22 -0.17959 -0.39016 0.18241 -0.5494 0.912 9.41e-02 0.102223 0.06026 0.10607 -0.06207 0.1251 1.374 5.42e-03 0.180424 -0.54830 -0.74197 0.59358 0.8371 0.914 2.13e-01 0.173125 0.08541 0.01624 -0.07775 0.1314 1.249 5.97e-03 0.10692
57、6 0.32556 0.11734 -0.30200 0.4480 1.018 6.49e-02 0.103327 0.17243 0.32754 -0.17676 0.4127 1.148 5.66e-02 0.1369 source(Reg_Diag.R);Reg_Diag(lm.sol) #薛毅老師自己寫的程序residual s1standard s2student s3 hatmatrix s4DFFITS s510.004438430.027538650.026959250.168118190.012119492-0.09114255-0.53021138-0.522114690.
58、05369239-0.1243672730.077268870.471128630.463356660.138573530.1858431040.048056650.301110620.295329120.184276630.140368605-0.09130271-0.52689847-0.518814060.03838430-0.1036544260.301621011.792879131.885965790.093622230.6061340670.030660050.198558420.194537630.23641540* 0.108246260.01199519 0.0708586
59、00.06937393 0.082265370.020770470.084918910.492175910.48426323 0.046641580.107112460.116254050.683158140.67537315 0.072611340.18897969-0.13874451 -0.81570765 -0.80983786 0.07348894 -0.228078200.115402280.670519400.662637610.051375890.154208640.161784060.940416230.938061440.052194320.220132040.062107
60、270.369572770.362825310.095574110.11794546 TOC o 1-5 h z -0.13650951-0.81026658-0.804283490.09101221-0.25449541-0.11097950-0.64757782-0.639555240.05943308-0.16076716-0.03939381-0.24515626-0.240295570.17309048-0.10993940-0.18593575-1.11438446-1.120290130.10845395-0.39073410-0.33609591 -2.01522068 *-2
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- VB編程能力的試題與答案提升
- 學(xué)習(xí)大數(shù)據(jù)分析的工具與方法試題及答案
- 未來企業(yè)戰(zhàn)略與風(fēng)險(xiǎn)管理考核要點(diǎn)試題及答案
- 地理信息系統(tǒng)的職業(yè)路徑計(jì)劃
- 2025租賃設(shè)備的租賃合同
- 數(shù)據(jù)分析工具試題及答案
- 【成都】2025年上半年成都大學(xué)附屬醫(yī)院公開考試招聘工作人員24人筆試歷年典型考題及考點(diǎn)剖析附帶答案詳解
- 如何通過工作計(jì)劃激勵(lì)團(tuán)隊(duì)
- 行政法學(xué)資源配置試題及答案
- 實(shí)現(xiàn)業(yè)務(wù)多元化的工作策略計(jì)劃
- 遼寧點(diǎn)石聯(lián)考2025屆高三5月份聯(lián)合考試-英語試題+答案
- 【MOOC】大學(xué)英語視聽導(dǎo)學(xué)-湖南大學(xué) 中國大學(xué)慕課MOOC答案
- 2024年高考真題-化學(xué)(天津卷) 含解析
- 2024年可行性研究報(bào)告投資估算及財(cái)務(wù)分析全套計(jì)算表格(含附表-帶只更改標(biāo)紅部分-操作簡單)
- NB-T+10110-2018風(fēng)力發(fā)電場技術(shù)監(jiān)督導(dǎo)則
- 中國民主同盟入盟申請表(樣表)
- 國家標(biāo)準(zhǔn)色卡電子版(WORD版圖片)
- 9種基坑坍塌案例
- 《呼吸機(jī)的使用管理》PPT課件.ppt
- 年產(chǎn)10萬噸甲醇低壓羰基化合成醋酸精制工段工藝設(shè)計(jì)(共56頁)
- 兒童相聲劇本43286
評論
0/150
提交評論