統(tǒng)計(jì)學(xué)-基于R第3版習(xí)題答案(第二章)_第1頁
統(tǒng)計(jì)學(xué)-基于R第3版習(xí)題答案(第二章)_第2頁
統(tǒng)計(jì)學(xué)-基于R第3版習(xí)題答案(第二章)_第3頁
統(tǒng)計(jì)學(xué)-基于R第3版習(xí)題答案(第二章)_第4頁
統(tǒng)計(jì)學(xué)-基于R第3版習(xí)題答案(第二章)_第5頁
已閱讀5頁,還剩13頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、習(xí)題2.1 (1)簡單頻數(shù)分布表:> load("D:工作總結(jié)人大R語言統(tǒng)計(jì)學(xué)基于R(第3版)例題和習(xí)題數(shù)據(jù)(公開資源)exercisech2exercise2_1.RData")> summary(exercise2_1) 行業(yè) 性別 滿意度 電信業(yè):38 男:58 不滿意:75 航空業(yè):19 女:62 滿意 :45 金融業(yè):26 旅游業(yè):37 二維列聯(lián)表:> mytable1<-table(exercise2_1$行業(yè),exercise2_1$滿意度)> addmargins(mytable1)# 增加邊界和 不滿意 滿意 Sum 電信業(yè)

2、25 13 38 航空業(yè) 12 7 19 金融業(yè) 11 15 26 旅游業(yè) 27 10 37 Sum 75 45 120三維列聯(lián)表:> mytable1<-ftable(exercise2_1, row.vars = c("性別","滿意度"), col.var="行業(yè)");mytable1 行業(yè) 電信業(yè) 航空業(yè) 金融業(yè) 旅游業(yè)性別 滿意度 男 不滿意 11 7 7 11 滿意 6 3 7 6女 不滿意 14 5 4 16 滿意 7 4 8 4(2)條形圖:> count1<-table(exercise2_1

3、$行業(yè))> count2<-table(exercise2_1$性別)> count3<-table(exercise2_1$滿意度)> par(mfrow=c(1,3),mai=c(0.7,0.7,0.6,0.1),cex=0.7,cex.main=0.8)> barplot(count1,xlab="行業(yè)",ylab="頻數(shù)")> barplot(count2,xlab="性別",ylab="頻數(shù)")> barplot(count3,xlab="滿意度&

4、quot;,ylab="頻數(shù)")帕累托圖:> count1<-table(exercise2_1$行業(yè))> par(mai=c(0.7,0.7,0.1,0.8),cex=0.8)> x<-sort(count1,decreasing = T)> bar<-barplot(x,xlab="行業(yè)",ylab="頻數(shù)",ylim=c(0,1.2*max(count1),col=2:5)> text(bar,x,labels = x,pos=3) # 條形圖增加數(shù)值> y<-cums

5、um(x)/sum(x) # cumsum累計(jì)求和> par(new=T)> plot(y,type="b",lwd=1.5,pch=15,axes=F)> axis(4) # 右Y軸> mtext("累積頻率",side=4,line=3)> mtext("累積分布曲線",line=-2.5,cex=0.8,adj=0.75)復(fù)式條形圖:> mytable1<-table(exercise2_1$滿意度,exercise2_1$行業(yè))> barplot(mytable1,xlab=&q

6、uot;行業(yè)",ylab="頻數(shù)",legend=rownames(mytable1),args.legend=list(x=13), beside = T)脊形圖:> library(vcd)> spine(行業(yè)滿意度,data=exercise2_1,xlab="滿意度", ylab="行業(yè)",margins=c(4,3.5,1,2.5)馬賽克圖:> mosaicplot(性別+行業(yè)+滿意度,data=exercise2_1,col=2:3)(3)餅圖:> count1<-table(exe

7、rcise2_1$行業(yè))> name<-names(count1)> percent<-prop.table(count1)*100> label1<-paste(name," ",percent,"%",sep="")> par(pin=c(3,3),mai=c(0.1,0.4,0.1,0.4),cex=0.8) # 圓的大小> pie(count1,labels=label1,init.angle = 90)扇形圖:> count1<-table(exercise2_1$

8、行業(yè))> name<-names(count1)> percent<-count1/sum(count1)*100> labs<-paste(name," ",percent,"%",sep="")> library(plotrix)> fan.plot(count1,labels=labs,ticks=200)2.2(1)分10組,繪制頻數(shù)分布表> load("D:工作總結(jié)人大R語言統(tǒng)計(jì)學(xué)基于R(第3版)例題和習(xí)題數(shù)據(jù)(公開資源)exercisech2exercise2

9、_2.RData")> library(actuar)> v<-as.vector(exercise2_2$燈泡壽命)> gd1<-grouped.data(v, breaks = 10, right = FALSE)> table1<-data.frame(gd1);table1 Var.1 v1 2600, 2800) 12 2800, 3000) 43 3000, 3200) 124 3200, 3400) 135 3400, 3600) 276 3600, 3800) 207 3800, 4000) 198 4000, 4200) 4

10、(2)直方圖> d<-exercise2_2$燈泡壽命> hist(d,breaks=10,xlab="壽命",ylab="頻數(shù)")莖葉圖:> stem(exercise2_2$燈泡壽命) The decimal point is 2 digit(s) to the right of the | 26 | 0 28 | 968 30 | 0557882356799 32 | 7888990134569 36 | 033566600024445567788 38 | 22455566670055669 40 | 0010172.3

11、(1)箱線圖:> load("D:工作總結(jié)人大R語言統(tǒng)計(jì)學(xué)基于R(第3版)例題和習(xí)題數(shù)據(jù)(公開資源)exercisech2exercise2_3.RData")> boxplot(exercise2_3,-1,xlab="城市",ylab="氣溫",cex.lab=0.8,cex.axis=0.6) # 從第二列開始,到最后小提琴圖:> library(vioplot)> x1<-exercise2_3$北京> x2<-exercise2_3$沈陽> x3<-exercise2_3

12、$上海> x4<-exercise2_3$南昌> vioplot(x1,x2,x3,x4,names=c("北京","沈陽","上海","南昌")(2)點(diǎn)圖:> library(reshape)> table1_1<-melt(exercise2_3,id.vars=c("月份"),variable_name="城市")> table1_1<-rename(table1_1,c(value="溫度")>

13、 dotchart(table1_1$溫度,groups=table1_1$城市,xlab="溫度",pch=20)> library(lattice)> dotplot(溫度城市,data=table1_1,pch=19)核密度圖:> library(lattice)> dp1<-densityplot(溫度,group=城市,data=table1_1,auto.key=list(columns=1,x=0.01,y=0.95,cex=0.6),cex=0.5)> plot(dp1)> library(sm)> pare(

14、table1_1$溫度,table1_1$城市,lty=1:6,col=1:6)> legend("topleft",legend = levels(table1_1$城市),lty=1:6,col=1:6)(3)輪廓圖> matplot(t(exercise2_3,-1),type="b",xlab="城市",ylab="溫度",pch=1,xaxt="n")> axis(side=1,at=1:10,labels = c("北京","沈陽&qu

15、ot;,"上海","南昌","鄭州","武漢","廣州","???quot;,"重慶","昆明")> legend("bottomright",legend= names(exercise2_3,-1) # 取列名雷達(dá)圖:> library(fmsb)> table1<-data.frame(t(exercise2_3,2:11) #行列進(jìn)行轉(zhuǎn)換,并數(shù)據(jù)框> radarchart(table1,a

16、xistype=0,seg=4,maxmin=F,vlabels=exercise2_3,1)> legend(x="topleft",legend=names(exercise2_3,2:11), col=1:10, lty=1:10) #lty圖例(4)星圖:> matrix1<-as.matrix(exercise2_3,2:11)> rownames(matrix1)<-exercise2_3,1> stars(matrix1,key.loc=c(7,2,5),cex=0.8)臉譜圖:> library(aplpack)&g

17、t; faces(t(matrix1),nrow.plot = 5,ncol.plot = 2,face.type = 0)effect of variables: modified item Var "height of face " "1月" "width of face " "2月" "structure of face" "3月" "height of mouth " "4月" "width of mouth &quo

18、t; "5月" "smiling " "6月" "height of eyes " "7月" "width of eyes " "8月" "height of hair " "9月" "width of hair " "10月" "style of hair " "11月" "height of nose " &quo

19、t;12月" "width of nose " "1月" "width of ear " "2月" "height of ear " "3月" 2.4(1)散點(diǎn)圖:> plot(地區(qū)生產(chǎn)總值,最終消費(fèi)支出,xlab="",ylab='最終消費(fèi)支出')> abline(lm(最終消費(fèi)支出地區(qū)生產(chǎn)總值,data=exercise2_4)> points(固定資產(chǎn)投資,最終消費(fèi)支出,ylab='最終消費(fèi)支出&#

20、39;,pch=2,col="blue")> abline(lm(最終消費(fèi)支出固定資產(chǎn)投資,data=exercise2_4),col="blue")氣泡圖:> r<-sqrt(最終消費(fèi)支出/pi)> symbols(最終消費(fèi)支出,地區(qū)生產(chǎn)總值,circles=r, inches=0.3, fg="white",bg="lightblue",ylab="最終消費(fèi)支出",xlab="地區(qū)生產(chǎn)總值")> text(最終消費(fèi)支出,地區(qū)生產(chǎn)總值,rown

21、ames(exercise2_4)> mtext("氣泡大小=最終消費(fèi)支出",line=-2.5,adj=0.1)(2)星圖:> matrix1<-as.matrix(exercise2_4,2:4)> rownames(matrix1)<-exercise2_4,1> stars(matrix1,key.loc=c(7,2,5),cex=0.8)臉譜圖:> library(aplpack)> faces(matrix1,nrow.plot = 6,ncol.plot = 6,face.type = 0)2.5時(shí)序圖:>

22、 load("D:工作總結(jié)人大R語言統(tǒng)計(jì)學(xué)基于R(第3版)例題和習(xí)題數(shù)據(jù)(公開資源)exercisech2exercise2_5.RData")> table1<-ts(exercise2_5,start=2004)> plot(table1,2,xlab="年份",ylab="價(jià)格指數(shù)",type="n")> points(table1,2,type="o",xlab="年份",ylab="城鎮(zhèn)價(jià)格指數(shù)")> lines(table1,3,typ

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論