统计学根据R第3版知识题目解析第二章Word文档下载推荐.docx
- 文档编号:16016433
- 上传时间:2022-11-17
- 格式:DOCX
- 页数:25
- 大小:436.99KB
统计学根据R第3版知识题目解析第二章Word文档下载推荐.docx
《统计学根据R第3版知识题目解析第二章Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《统计学根据R第3版知识题目解析第二章Word文档下载推荐.docx(25页珍藏版)》请在冰豆网上搜索。
addmargins(mytable1)#增加边界和
不满意满意Sum
电信业251338
航空业12719
金融业111526
旅游业271037
Sum7545120
三维列联表:
-ftable(exercise2_1,row.vars=c("
性别"
"
满意度"
),col.var="
行业"
);
mytable1
行业电信业航空业金融业旅游业
性别满意度
男不满意117711
满意6376
女不满意145416
满意7484
(2)
条形图:
count1<
-table(exercise2_1$行业)
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="
ylab="
频数"
barplot(count2,xlab="
barplot(count3,xlab="
帕累托图:
par(mai=c(0.7,0.7,0.1,0.8),cex=0.8)
x<
-sort(count1,decreasing=T)
bar<
-barplot(x,xlab="
ylim=c(0,1.2*max(count1)),col=2:
5)
text(bar,x,labels=x,pos=3)#条形图增加数值
y<
-cumsum(x)/sum(x)#cumsum累计求和
par(new=T)
plot(y,type="
b"
lwd=1.5,pch=15,axes=F)
axis(4)#右Y轴
mtext("
累积频率"
side=4,line=3)
累积分布曲线"
line=-2.5,cex=0.8,adj=0.75)
复式条形图:
-table(exercise2_1$满意度,exercise2_1$行业)
barplot(mytable1,xlab="
legend=rownames(mytable1),args.legend=list(x=13),beside=T)
脊形图:
library(vcd)
spine(行业~满意度,data=exercise2_1,xlab="
ylab="
margins=c(4,3.5,1,2.5))
马赛克图:
mosaicplot(~性别+行业+满意度,data=exercise2_1,col=2:
3)
(3)
饼图:
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/sum(count1)*100
labs<
library(plotrix)
fan.plot(count1,labels=labs,ticks=200)
2.2
(1)分10组,绘制频数分布表
\\工作总结\\人大\\R语言\\《统计学—基于R》(第3版)—例题和习题数据(公开资源)\\exercise\\ch2\\exercise2_2.RData"
library(actuar)
v<
-as.vector(exercise2_2$灯泡寿命)
gd1<
-grouped.data(v,breaks=10,right=FALSE)
table1<
-data.frame(gd1);
table1
Var.1v
1[2600,2800)1
2[2800,3000)4
3[3000,3200)12
4[3200,3400)13
5[3400,3600)27
6[3600,3800)20
7[3800,4000)19
8[4000,4200)4
(2)直方图
d<
-exercise2_2$灯泡寿命
hist(d,breaks=10,xlab="
寿命"
茎叶图:
stem(exercise2_2$灯泡寿命)
Thedecimalpointis2digit(s)totherightofthe|
26|0
28|968
0557********
32|7888990134569
34|11335667799112223344455559
0335********
38|22455566670055669
40|001017
2.3
(1)箱线图:
\\工作总结\\人大\\R语言\\《统计学—基于R》(第3版)—例题和习题数据(公开资源)\\exercise\\ch2\\exercise2_3.RData"
boxplot(exercise2_3[,-1],xlab="
城市"
气温"
cex.lab=0.8,cex.axis=0.6)#从第二列开始,到最后
小提琴图:
library(vioplot)
x1<
-exercise2_3$北京
x2<
-exercise2_3$沈阳
x3<
-exercise2_3$上海
x4<
-exercise2_3$南昌
vioplot(x1,x2,x3,x4,names=c("
北京"
沈阳"
上海"
南昌"
))
(2)点图:
library(reshape)
table1_1<
-melt(exercise2_3,id.vars=c("
月份"
),variable_name="
-rename(table1_1,c(value="
温度"
dotchart(table1_1$温度,groups=table1_1$城市,xlab="
pch=20)
library(lattice)
dotplot(温度~城市,data=table1_1,pch=19)
核密度图:
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(table1_1$温度,table1_1$城市,lty=1:
6,col=1:
6)
legend("
topleft"
legend=levels(table1_1$城市),lty=1:
(3)轮廓图
matplot(t(exercise2_3[,-1]),type="
xlab="
pch=1,xaxt="
n"
axis(side=1,at=1:
10,labels=c("
郑州"
武汉"
广州"
海口"
重庆"
昆明"
bottomright"
legend=names(exercise2_3[,-1]))#取列名
雷达图:
library(fmsb)
-data.frame(t(exercise2_3[,2:
11]))#行列进行转换,并数据框
radarchart(table1,axistype=0,seg=4,maxmin=F,vlabels=exercise2_3[,1])
legend(x="
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)
faces(t(matrix1),nrow.plot=5,ncol.plot=2,face.type=0)
effectofvariables:
modifieditemVar
heightofface"
1月"
widthofface"
2月"
structureofface"
3月"
heightofmouth"
4月"
widthofmouth"
5月"
smiling"
6月"
heightofeyes"
7月"
widthofeyes"
8月"
heightofhair"
9月"
widthofhair"
10月"
styleofhair"
11月"
heightofnose"
12月"
widthofnose"
widthofear"
heightofear"
2.4
(1)散点图:
plot(地区生产总值,最终消费支出,xlab="
ylab='
最终消费支出'
abline(lm(最终消费支出~地区生产总值,data=exercise2_4))
points(固定资产投资,最终消费支出,ylab='
pch=2,c
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 统计学 根据 知识 题目 解析 第二