




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(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);H#H起過渡作用,不規(guī)則的數(shù)組下標(biāo)G-B,H
2、;G要點(diǎn):矩陣賦值方法。默認(rèn)是byrow=FALSE數(shù)據(jù)按列放置。取出部分?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(iin1:n)for(jin1:n)Hi,j-1/(i+j-1);HG-solve(H);G#求H的逆矩陣ev-e
3、igen(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),age=c(14,15,16,14,15),height=c(156,165,157,162,159),weight=c(42,49,41.5,52,45.5);StudentData要點(diǎn):數(shù)據(jù)框的使用待解決:SSH登陸linux服務(wù)器中文顯示亂
4、碼。此處用英文代替。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在工作目錄里輸出,輸出的文件名為studentdata.csv可用Excel打開.要點(diǎn):讀寫文件。re
5、ad.table(file)write.table(Rdata,file)read.csv(file)write.csv(Rdata,file)外部文件,不論是待讀入或是要寫出的,命令中都得加雙引號(hào)。Fun-function(n)if(n=0)list(fail=pleaseinputaintegerabove0!)elserepeatif(n=1)breakelseif(n%2=0)n-n/2elsen-3*n+1list(sucess!)在linux下新建一個(gè)R文件,輸入上述代碼,保存為2.7.R然后在當(dāng)前目錄下進(jìn)入R環(huán)境,輸入source(2.7.R),即打開了這個(gè)程序腳本。然后就可以執(zhí)
6、行函數(shù)了。輸入Fun(67),顯示sucess!輸入Fun(-1),顯示$fail1pleaseinputaintegerabove0!待解決: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)cv-100*s/mcss-sum(x-m)2)uss-sum(x2)R-max(x)-min(x)R1-quantile(x,3/4)
7、-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=R1,Skewness=g1,Kurtosis=g2,s=1)進(jìn)入R,source(data_outline.R)#將程序調(diào)入內(nèi)存serumdata
8、-scan(3.1.txt);serumdata#將數(shù)據(jù)讀入向量serumdata。data_outline(serumdata)結(jié)果如下:NMeanVarstd_devMedianstd_meanCVCSSUSSR110073.69615.416753.92641773.50.39264175.3278571526.258544636.320R1SkewnessKurtosis要點(diǎn):read.table()用于讀表格形式的文件。上述形式的數(shù)據(jù)由于第七行缺幾個(gè)數(shù)據(jù),故用read.table()不能讀入。scan()可以直接讀純文本文件。scan()和matrix()連用還可以將數(shù)據(jù)存放成矩陣形
9、式。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(thehistogramofserumdata),xlab=age,ylab=frequency)#直方圖。col是填充顏色。默認(rèn)空白。border是邊框的顏色,默認(rèn)前景色。density是在圖上畫條紋陰影,默認(rèn)不畫。angle是條紋陰影的傾斜角度(逆時(shí)針方向),默認(rèn)45度
10、。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(serumdata)#正態(tài)性Shapori-Wilk檢驗(yàn)方法Shapiro-Wilknormalitytestdata:serumdata結(jié)論:p值,可認(rèn)為來自正態(tài)分布的總體。ks.test(serumdata,pnorm,mean(serumdata),sd(seru
11、mdata)#Kolmogrov-SmirnoV檢驗(yàn),正態(tài)性O(shè)ne-sampleKolmogorov-Smirnovtestdata:serumdataalternativehypothesis:two-sidedWarningmessage:Inks.test(serumdata,pnorm,mean(serumdata),sd(serumdata):cannotcomputecorrectp-valueswithties結(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
12、,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(生成箱線圖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組合
13、其他兩組有顯著差異。數(shù)據(jù)太多,懶得錄入。離散圖應(yīng)該用plot即可。studatanames(studata)attach(studata)#將數(shù)據(jù)框調(diào)入內(nèi)存plot(weightheight,col=red)#體重對(duì)于身高的散點(diǎn)圖coplot(weightheight|sex,col=blue)#不同性別,體重與身高的散點(diǎn)圖coplot(weightheight|age,col=blue)#不同年齡,體重與身高的散點(diǎn)圖coplot(weightheight|age+sex,col=blue)#不同年齡和性別,體重與身高的散點(diǎn)圖xy-seq(-1,7,0.05)f-function(x,y)xA
14、4-2*xA2*y+xA2-2*x*y+2*yA2+4.5*x-4*y+4zt.test(x,alternative=less,mu=72)#t.test()做單樣本正態(tài)分布單側(cè)區(qū)間估計(jì)OneSamplet-testdata:xalternativehypothesis:truemeanislessthan7295percentconfidenceinterval:sampleestimates:meanofxp值小于,拒絕原假設(shè),平均脈搏低于常人。要點(diǎn):t.test()函數(shù)的用法。本例為單樣本;可做雙邊和單側(cè)檢驗(yàn)。xv-c(140,137,136,140,145,148,140,135,14
15、4,141);x1140137136140145148140135144141yv-c(135,118,115,140,128,131,130,115,131,125);y1135118115140128131130115131125t.test(x,y,varequal=TRUE)TwoSamplet-testdata:xandyalternativehypothesis:truedifferenceinmeansisnotequalto095percentconfidenceinterval:sampleestimates:meanofxmeanofy140.6期望差的95%置信區(qū)間為7.
16、5362620.06374。要點(diǎn):t.test()可做兩正態(tài)樣本均值差估計(jì)。此例認(rèn)為兩樣本方差相等。ps:我怎么覺得這題應(yīng)該用配對(duì)t檢驗(yàn)?xv-c(0.143,0.142,0.143,0.137)yv-c(0.140,0.142,0.136,0.138,0.140)t.test(x,y,varequal=TRUE)TwoSamplet-testdata:xandyalternativehypothesis:truedifferenceinmeansisnotequalto095percentconfidenceinterval:-0.001996351sampleestimates:meano
17、fxmeanofy0.14125期望差的95%的區(qū)間估計(jì)為-0.001996351接var.test(x,y)Ftesttocomparetwovariancesdata:xandyalternativehypothesis:trueratioofvariancesisnotequalto195percentconfidenceinterval:sampleestimates:ratioofvariances要點(diǎn):可做兩樣本方差比的估計(jì)。基于此結(jié)果可認(rèn)為方差不等。因此,在中,計(jì)算期望差時(shí)應(yīng)該采取方差不等的參數(shù)。t.test(x,y)WelchTwoSamplet-testdata:xandya
18、lternativehypothesis:truedifferenceinmeansisnotequalto095percentconfidenceinterval:sampleestimates:meanofxmeanofy140.6期望差的95%置信區(qū)間為7.35971320.240287。要點(diǎn):t.test(x,y,var.equal=TRUE)做方差相等的兩正態(tài)樣本的均值差估計(jì)t.test(x,y)做方差不等的兩正態(tài)樣本的均值差估計(jì)xmean(x)-tmp;mean(x)+tmp平均呼喚次數(shù)為的置信區(qū)間為1.49,2,32xv-c(1067,919,1196,785,1126,936,
19、918,1156,920,948)t.test(x,alternative=greater)OneSamplet-testdata:xalternativehypothesis:truemeanisgreaterthan095percentconfidenceinterval:920.8443Infsampleestimates:meanofx燈泡平均壽命置信度95%的單側(cè)置信下限為920.8443要點(diǎn):t.test()做單側(cè)置信區(qū)間估計(jì)xv-c(220,188,162,230,145,160,238,188,247,113,126,245,164,231,256,183,190,158,22
20、4,175)t.test(x,mu=225)OneSamplet-testdata:xalternativehypothesis:truemeanisnotequalto22595percentconfidenceinterval:sampleestimates:上述檢驗(yàn)是雙邊檢驗(yàn)。也可米用單邊檢驗(yàn)。備擇假設(shè):油漆工人的血小板計(jì)數(shù)小于正常年男子。t.test(x,mu=225,alternative=less)OneSamplet-testdata:xalternativehypothesis:truemeanislessthan22595percentconfidenceinterval:s
21、ampleestimates:meanofx同樣可得出油漆工人的血小板計(jì)數(shù)小于正常成年男子的結(jié)論。pnorm(1000,mean(x),sd(x)x11067919119678511269369181156920948pnorm(1000,mean(x),sd(x)xv=1000的概率為0.509,故x大于1000的概率為0.491.要點(diǎn):pnorm計(jì)算正態(tài)分布的分布函數(shù)。在R軟件中,計(jì)算值均為下分位點(diǎn)。Av-c(113,120,138,120,100,118,138,123)Bv-c(138,116,125,136,110,132,130,110)t.test(A,B,paired=TRUE
22、)Pairedt-testdata:AandBalternativehypothesis:truedifferenceinmeansisnotequalto095percentconfidenceinterval:-15.62889sampleestimates:meanofthedifferencesp值大于,接受原假設(shè),兩種方法治療無差異。(1)正態(tài)性W檢驗(yàn):xv-c(-0.7,-5.6,2,2.8,0.7,3.5,4,5.8,7.1,-0.5,2.5,-1.6,1.7,3,0.4,4.5,4.6,2.5,6,-1.4)yv-c(3.7,6.5,5,5.2,0.8,0.2,0.6,3.4,
23、6.6,-1.1,6,3.8,2,1.6,2,2.2,1.2,3.1,1.7,-2)shapiro.test(x)Shapiro-Wilknormalitytestdata:xshapiro.test(y)Shapiro-Wilknormalitytestdata:yks檢驗(yàn):ks.test(x,pnorm,mean(x),sd(x)One-sampleKolmogorov-Smirnovtest(2)data:xalternativehypothesis:two-sidedWarningmessage:Inks.test(x,pnorm,mean(x),sd(x):cannotcompute
24、correctp-valueswithtiesks.test(y,pnorm,mean(y),sd(y)One-sampleKolmogorov-Smirnovtestdata:yalternativehypothesis:two-sidedWarningmessage:Inks.test(y,pnorm,mean(y),sd(y):cannotcomputecorrectp-valueswithtiespearson擬合優(yōu)度檢驗(yàn),以x為例。sort(x)1-5.6-1.6-1.4-0.7-1.72.03.03.56.0 x1v-tab
25、le(cut(x,br=c(-6,-3,0,3,6,9)pv-pnorm(c(-3,0,3,6,9),mean(x),sd(x)ppchisq.test(x1,p=p)Chi-squaredtestforgivenprobabilitiesdata:x1Warningmessage:Inchisq.test(x1,p=p):Chi-squaredapproximationmaybeincorrectp值為,接受原假設(shè),x符合正態(tài)分布。方差相同模型t檢驗(yàn):t.test(x,y,varequal=TRUE)TwoSamplet-testdata:xandyalternativehypothesis
26、:truedifferenceinmeansisnotequalto095percentconfidenceinterval:-2.326179sampleestimates:meanofxmeanofy2.065方差不同模型t檢驗(yàn):t.test(x,y)WelchTwoSamplet-testdata:xandyalternativehypothesis:truedifferenceinmeansisnotequalto095percentconfidenceinterval:-2.32926sampleestimates:meanofxmeanofy2.065配對(duì)t檢驗(yàn):t.test(x,
27、y,paired=TRUE)Pairedt-testdata:xandyalternativehypothesis:truedifferenceinmeansisnotequalto095percentconfidenceinterval:-2.373146sampleestimates:meanofthedifferences三種檢驗(yàn)的結(jié)果都顯示兩組數(shù)據(jù)均值無差異。(3)方差檢驗(yàn):var.test(x,y)Ftesttocomparetwovariancesdata:xandyalternativehypothesis:trueratioofvariancesisnotequalto195p
28、ercentconfidenceinterval:sampleestimates:ratioofvariances接受原假設(shè),兩組數(shù)據(jù)方差相同。a-c(126,125,136,128,123,138,142,116,110,108,115,140)bks.test(b,pnorm,mean(b),sd(b)One-sampleKolmogorov-Smirnovtestdata:balternativehypothesis:two-sidedWarningmessage:Inks.test(b,pnorm,mean(b),sd(b):cannotcomputecorrectp-valueswi
29、thtiesa和b都服從正態(tài)分布。方差齊性檢驗(yàn):var.test(a,b)Ftesttocomparetwovariancesdata:aandbalternativehypothesis:trueratioofvariancesisnotequalto195percentconfidenceinterval:sampleestimates:ratioofvariances可認(rèn)為a和b的方差相冋。選用方差相同模型t檢驗(yàn):t.test(a,b,var.equal=TRUE)TwoSamplet-testdata:aandbalternativehypothesis:truedifferencei
30、nmeansisnotequalto095percentconfidenceinterval:sampleestimates:meanofxmeanofy125.5833可認(rèn)為兩者有差別。二項(xiàng)分布總體的假設(shè)檢驗(yàn):binom.test(57,400,p=0.147)Exactbinomialtestdata:57and40095percentconfidenceinterval:sampleestimates:probabilityofsuccessP值,故接受原假設(shè),表示調(diào)查結(jié)果支持該市老年人口的看法二項(xiàng)分布總體的假設(shè)檢驗(yàn):binom.test(178,328,p=0.5,alternativ
31、e=greater)Exactbinomialtestdata:178and32895percentconfideneeinterval:sampleestimates:probabilityofsuccess不能認(rèn)為這種處理能增加母雞的比例。利用pearson卡方檢驗(yàn)是否符合特定分布:chisqtest(c(315,101,108,32),p=c(9,3,3,1)/16)Chi-squaredtestforgivenprobabilitiesdata:c(315,101,108,32)接受原假設(shè),符合自由組合定律。利用pearson卡方檢驗(yàn)是否符合泊松分布:nv-length(z)yv-c(
32、92,68,28,11,1,0)xv-0:5qv-ppois(x,mean(rep(x,y);nv-length(y)p1v-q1;pn=1-qn-1chisqtest(y,p=p)Chi-squaredtestforgivenprobabilitiesdata:yWarningmessage:Inchisq.test(y,p=p):Chi-squaredapproximationmaybeincorrect重新分組,合并頻數(shù)小于5的組:zv-c(92,68,28,12)nv-length(z);pv-p1:n-1;pnv-1-qn-1chisq.test(z,p=p)Chi-squaredt
33、estforgivenprobabilitiesdata:z可認(rèn)為數(shù)據(jù)服從泊松分布。ks檢驗(yàn)兩個(gè)分布是否相同:xv-c(2.36,3.14,752,3.48,2.76,5.43,6.54,7.41)yv-c(4.38,4.25,6.53,3.28,7.21,6.55)ks.test(x,y)Two-sampleKolmogorov-Smirnovtestdata:xandyalternativehypothesis:two-sided列聯(lián)數(shù)據(jù)的獨(dú)立性檢驗(yàn):xv-c(358,2492,229,2745)dim(x)v-c(2,2)chisq.test(x)PearsonsChi-squaredt
34、estwithYatescontinuitycorrectiondata:xP值0.05,拒絕原假設(shè),有影響。列聯(lián)數(shù)據(jù)的獨(dú)立性檢驗(yàn):TOC o 1-5 h zy,1,2,31,4512102,4620283,2823304,111235chisq.test(y)PearsonsChi-squaredtestdata:yP值0.05,拒絕原假設(shè),不獨(dú)立,有關(guān)系。因有的格子的頻數(shù)小于5,故采用fiser確切概率法檢驗(yàn)獨(dú)立性。fisher.test(x)FishersExactTestforCountDatadata:xalternativehypothesis:trueoddsratioisnot
35、equalto195percentconfideneeinterval:sampleestimates:oddsratiop值大于,兩變量獨(dú)立,兩種工藝對(duì)產(chǎn)品的質(zhì)量沒有影響。由于是在相同個(gè)體上的兩次試驗(yàn),故采用McNemar檢驗(yàn)。mcnemar.test(x)McNemarsChi-squaredtestdata:xH1:中位數(shù)xv-c(13.32,13.06,14.02,11.86,13.58,13.77,13.51,14.42,14.44,15.43)binomtest(sum(x)146,length(x),al=l)Exactbinomialtestdata:sum(x)14.6and
36、length(x)95percentconfidenceinterval:sampleestimates:probabilityofsuccess拒絕原假設(shè),中位數(shù)小于Wilcoxon符號(hào)秩檢驗(yàn):wilcox.test(x,mu=146,al=l,exact=F)data:xandyWilcoxonsignedranktestwithcontinuitycorrectiondata:x拒絕原假設(shè),中位數(shù)小于符號(hào)檢驗(yàn)法:xv-c(48,33,37.5,48,42.5,40,42,36,11.3,22,36,27.3,14.2,32.1,52,38,17.3,20,21,46.1)yy),leng
37、th(x)Exactbinomialtestdata:sum(xy)andlength(x)95percentconfidenceinterval:sampleestimates:probabilityofsuccess接受原假設(shè),無差別。Wilcoxon符號(hào)秩檢驗(yàn):wilcox.test(x,y,paired=TRUE,exact=FALSE)Wilcoxonsignedranktestwithcontinuitycorrectiondata:xandyalternativehypothesis:truelocationshiftisnotequalto0拒絕原假設(shè),有差別。Wilcoxon
38、秩和檢驗(yàn):wilcox.test(x,y,exact=FALSE)Wilcoxonranksumtestwithcontinuitycorrectionalternativehypothesis:truelocationshiftisnotequalto0One-sampleKolmogorov-Smirnovtestdata:xalternativehypothesis:two-sidedWarningmessage:Inks.test(x,pnorm,mean(x),sd(x):cannotcomputecorrectp-valueswithtiesks.test(y,pnorm,mean
39、(y),sd(y)One-sampleKolmogorov-Smirnovtestdata:yalternativehypothesis:two-sided兩組數(shù)據(jù)均服從正態(tài)分布。方差齊性檢驗(yàn):var.test(x,y)Ftesttocomparetwovariancesdata:xandyalternativehypothesis:trueratioofvariancesisnotequalto195percentconfidenceinterval:sampleestimates:ratioofvariances可認(rèn)為兩組數(shù)據(jù)方差相同。綜上,該數(shù)據(jù)可做t檢驗(yàn)。t檢驗(yàn):t.test(x,y,
40、varequal=TRUE)TwoSamplet-testalternativehypothesis:truedifferenceinmeansisnotequalto095percentconfidenceinterval:sampleestimates:meanofxmeanofy33.215拒絕原假設(shè),有差別。綜上所述,Wilcoxon符號(hào)秩檢驗(yàn)的差異檢出能力最強(qiáng),符號(hào)檢驗(yàn)的差異檢出最弱。spearman秩相關(guān)檢驗(yàn):xv-c(24,17,20,41,52,23,46,18,15,20)yv-c(8,1,4,7,9,5,10,3,2,6)cor.test(x,y,method=spearm
41、an,exact=F)Spearmansrankcorrelationrhodata:xandyalternativehypothesis:truerhoisnotequalto0sampleestimates:rhokendall秩相關(guān)檢驗(yàn):cor.test(x,y,method=kendall,exact=F)Kendallsrankcorrelationtaudata:xandyalternativehypothesis:truetauisnotequalto0sampleestimates:tau二者有關(guān)系,呈正相關(guān)。xv-rep(1:5,c(0,1,9,7,3);yv-rep(1:5
42、,c(2,2,11,4,1)wilcox.test(x,y,exact=F)Wilcoxonranksumtestwithcontinuitycorrectionalternativehypothesis:truelocationshiftisnotequalto0p值大于,不能拒絕原假設(shè),尚不能認(rèn)為新方法的療效顯著優(yōu)于原療法。(1)x-c(5.1,3.5,7.1,6.2,8.8,7.8,4.5,5.6,8.0,6.4)yCJ由此判斷,Y和X有線性關(guān)系。lm.solv-lm(y1+x)summary(lm.sol)Call:lm(formula=y1+x)Residuals:Min1QMedi
43、an3QMax-128.591-70.978-3.72749.263Coefficients:EstimateStd.ErrortvaluePr(|t|)(Intercept)140.95125.111.1270.293x364.1819.2618.9086.33e-08*Signif.codes:0*0.001*0.01*0.05.0.11Residualstandarderror:96.42on8degreesoffreedomlm.predv-predict(lm.sol,new,interval=prediction)fitIwrupr故Y(7)=2690.227,2454.971,2
44、925.484(1)phov-data.frame(x1v-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),x2v-c(52,34,19,34,24,65,44,31,29,58,37,46,50,44,56,36,58,51),x3v-c(158,163,37,157,59,123,46,117,173,112,111,114,134,73,168,143,202,124),yv-c(64,60,71,61,54,77,81,93,93,51,76,96,77,93,95
45、,54,168,99)Im.solv-lm(yx1+x2+x3,data=pho)summary(lm.sol)Call:lm(formula=yx1+x2+x3,data=pho)Residuals:Min1QMedian3QMax-27.575-11.160-2.79911.574Coefficients:EstimateStd.ErrortvaluePr(|t|)(Intercept)44.929018.34082.4500.02806*x11.80330.52903.4090.00424*x2-0.13370.4440-0.3010.76771x30.16680.11411.4620.
46、16573Signif.codes:0*0.001*0.01*0.05.0.11Residualstandarderror:19.93on14degreesoffreedomlmstepv-step(lmsol)Start:yx1+x2+x3DfSumofSqRSSAIC-x2136.05599.4vnone5563.4-x31849.86413.1-x114617.810181.2Step:yx1+x3DfSumofSqRSSAICvnone5599.4-x31833.26432.6-x115169.510768.9summary(lm.step)Call:lm(formula=yx1+x3
47、,data=pho)Residuals:Min1QMedian3QMax-29.713-11.324-2.95311.286Coefficients:EstimateStd.ErrortvaluePr(|t|)(Intercept)41.479413.88342.9880.00920*x11.73740.46693.7210.00205*x30.15480.10361.4940.15592Signif.codes:0*0.001*0.01*0.05.0.11Residualstandarderror:19.32on15degreesoffreedomMultipleR-squared:0.54
48、81,F-statistic:9.095on2and15DF,x3仍不夠顯著。再用drop1函數(shù)做逐步回歸。drop1(lm.step)SingletermdeletionsModel:yx1+x3DfSumofSqRSSAICvnone5599.4x115169.510768.9x31833.26432.6可以考慮再去掉x3.lmopt|t|)(Intercept)59.25907.42007.9865.67e-07*x11.84340.47893.8490.00142*-Signif.codes:0*0.001*0.01*0.05.0.11Residualstandarderror:20.
49、05on16degreesoffreedomMultipleR-squared:0.4808,F-statistic:14.82on1and16DF,皆顯著。xv-c(1,1,1,1,2,2,2,3,3,3,4,4,4,5,6,6,6,7,7,7,8,8,8,9,11,12,12,12)yv-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.solv-lm(y1+x)summary
50、(lm.sol)Call:lm(formula=y1+x)Residuals:Min1QMedian3QMax-9.8413-2.3369-0.0214Coefficients:EstimateStd.ErrortvaluePr(|t|)(Intercept)-1.45191.8353-0.7910.436x1.55780.28075.5497.93e-06*Signif.codes:0*0.001*0.01*0.05.0.11Residualstandarderror:5.168on26degreesoffreedomoooooooooooos-o80801510plot(y.rsty.fi
51、t)匚、J+0ydCM1015y+fit殘差并非是等方差的。修正模型,對(duì)相應(yīng)變量Y做開方。Im.newv-update(lm.sol,sqrt(.).)summary(lm.new)Call:lm(formula=sqrt(y)x)Residuals:Min1QMedian3QMax-1.54255-0.45280-0.011770.34925Coefficients:EstimateStd.ErrortvaluePr(|t|)(Intercept)0.766500.255922.9950.00596*x0.291360.039147.4446.64e-08*Signif.codes:0*0.
52、001*0.01*0.05.0.11Residualstandarderror:0.7206on26degreesoffreedom:l+8.CMtoothpastev-data.frame(X1=c(-0.05,0.25,0.60,0,0.20,0.15,-0.15,0.15,0.10,0.40,0.45,0.35,0.30,0.50,0.50,0.40,-0.05,-0.05,0.10,0.20,0.10,0.50,0.60,-0.05,0,0.05,0.55),X2=c(5.50,6.75,7.25,5.50,6.50,6.75,5.25,6.00,6.25,7.00,6.90,6.80
53、,6.80,7.10,7.00,6.80,6.50,6.25,6.00,6.50,7.00,6.80,6.80,6.50,5.75,5.80,6.80),Y=c(7.38,8.51,9.52,7.50,8.28,8.75,7.10,8.00,8.15,9.10,8.86,8.90,8.87,9.26,9.00,8.75,7.95,7.65,7.27,8.00,8.50,8.75,9.21,8.27,7.67,7.93,9.26)lm.solv-lm(YX1+X2,data=toothpaste);summary(lm.sol)Call:lm(formula=YX1+X2,data=toothp
54、aste)Residuals:Min1QMedian3QMax-0.37130-0.101140.030660.10016Coefficients:EstimateStd.ErrortvaluePr(|t|)(Intercept)4.07590.62676.5041.00e-06*X11.52760.23546.4891.04e-06*:X20.61380.10275.9743.63e-06*:-Signif.codes:0*0.001*0.01*0.05.0.11Residualstandarderror:0.1767on24degreesoffreedomMultipleR-squared
55、:0.9378,F-statistic:181on2and24DF,回歸診斷:influence.measures(lm.sol)Influeneemeasuresoflm(formula=YX1+X2,data=toothpaste):dfb.1dfb.X1dfb.X2dffitcov.rcook.dhatinf0.009080.00260-0.008470.01211.3665.11e-050.16810.062770.04467-0.06785-0.12441.1595.32e-030.0537-0.028090.077240.025400.18581.2831.19e-020.1386
56、0.116880.05055-0.110780.14041.3776.83e-030.1843*0.011670.01887-0.01766-0.10371.1413.69e-030.0384-0.43010-0.428810.457740.60610.8141.11e-010.09360.078400.01534-0.072840.10821.4814.07e-030.2364*0.015770.00913-0.014850.02081.2371.50e-040.08230.01127-0.02714-0.003640.10711.1563.95e-030.0466-0.078300.001
57、710.080520.18901.1551.22e-020.07260.00301-0.09652-0.00365-0.22811.1271.76e-020.0735-0.031140.018480.034590.15421.1328.12e-030.0514-0.09236-0.038010.099400.22011.0711.62e-020.0522-0.026500.034340.026060.11791.2354.81e-030.09560.00968-0.11445-0.00857-0.25451.1502.19e-020.0910-0.00285-0.061850.00098-0.
58、16081.1468.83e-030.05940.072010.09744-0.07796-0.10991.3644.19e-030.17310.151320.30204-0.17755-0.39071.0875.04e-020.10850.074890.47472-0.12980-0.75790.7311.66e-010.10920.052490.08484-0.07940-0.46600.6256.11e-020.0384*0.075570.07284-0.07861-0.08801.4712.69e-030.2304*-0.17959-0.390160.18241-0.54940.912
59、9.41e-020.10220.060260.10607-0.062070.12511.3745.42e-030.1804-0.54830-0.741970.593580.83710.9142.13e-010.17310.085410.01624-0.077750.13141.2495.97e-030.10690.325560.11734-0.302000.44801.0186.49e-020.10330.172430.32754-0.176760.41271.1485.66e-020.1369source(Reg_Diag.R);Reg_Diag(lm.sol)#薛毅老師自己寫的程序resi
60、duals1standards2students3hatmatrixs4DFFITSs50.004438430.027538650.026959250.168118190.01211949-0.09114255-0.53021138-0.522114690.05369239-0.124367270.077268870.471128630.463356660.138573530.185843100.048056650.301110620.295329120.184276630.14036860-0.09130271-0.52689847-0.518814060.03838430-0.103654
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(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ǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- T/CSMT-YB 003-2022膜式燃?xì)獗響?yīng)用評(píng)價(jià)規(guī)范
- T/CSBME 052-2022虛擬現(xiàn)實(shí)產(chǎn)品視覺健康影響評(píng)價(jià)方法
- T/CNFIA 176-2023柔雅馥合香型白酒
- T/CNCA 028-2022井下巷道失速防護(hù)設(shè)施碰撞性能試驗(yàn)技術(shù)規(guī)范
- T/CNCA 022-2022煤礦用可伸縮帶式輸送機(jī)無基礎(chǔ)安裝裝置
- T/CMMA 3-2016鎂質(zhì)膠凝材料制品建筑模殼
- T/CIES 015-2017基于窄帶物聯(lián)網(wǎng)(NB-IoT)的道路照明智能控制系統(tǒng)技術(shù)規(guī)范
- T/CGCC 57-2021散裝即食食品經(jīng)營操作規(guī)范
- T/CERDS 5-2023企業(yè)ESG管理體系
- T/CECS 10365-2024太陽能光伏投光燈
- 2025屆高三高考押題預(yù)測卷 數(shù)學(xué)(新高考Ⅱ卷02) 含解析
- 智能家居安裝與調(diào)試協(xié)議
- 擔(dān)保貸款免責(zé)協(xié)議書
- 租金折抵欠款協(xié)議書
- 2025年人機(jī)交互領(lǐng)域考試題及答案
- 2025年全科衛(wèi)生資格考試試題及答案
- 2025年中考英語沖刺模擬試卷-山西省適用-教師版
- 山西晟誠環(huán)美固體廢物處置有限公司 粉煤灰、煤矸石綜合利用整溝治理項(xiàng)目報(bào)告書
- 石油銷售企業(yè)“雙低”站治理實(shí)踐與探索
- 2025-2030中國風(fēng)洞行業(yè)市場發(fā)展趨勢與前景展望戰(zhàn)略研究報(bào)告
- 仁愛版八年級(jí)下冊英語期末復(fù)習(xí)計(jì)劃
評(píng)論
0/150
提交評(píng)論