版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精选优质文档-倾情为你奉上实验四 绘制常用统计图形、对图形进行参数设置【实验类型】验证性【实验学时】2 学时【实验目的】1、掌握基本统计图形的绘制方法和所表达的意义;2、掌握图形参数的设置与多图环境设置;3、了解 ggplot2 绘图包和其它绘图包的使用方法。【实验内容】1、绘制基本的统计图形,包括散点图、箱线图、Q-Q 图和协同图等;2、对图形进行参数设置,包括添加图题、标签、点、线和颜色等;3、使用 gglplot2 和其它绘图包绘制常见统计图形。【实验方法或步骤】第一部分、课件例题:4.1data(cars) #调取数据集,用data()可查看R所有数据集cars #车速与制动距离的数据
2、(R自带)attach(cars) #连接数据集par(mai=c(0.9, 0.9, 0.6, 0.3) #图形边缘空白(边距)的宽度for (i in c("p", "l", "b", "c", "o", "h", "s", "S", "n") #9种类型 plot(speed, dist, type=i, main = paste("type = "", i, "&quo
3、t;", sep = "") # "为双引号detach() #取消连接数据集4.2df<data.frame(Age=c(13,13,14,12,12,15,11,15,14,14,14,15,12,13,12,16,12,11,15), Height=c(144,166,163,143,152,169,130,159,160,175,161,170,146,159,150,183,165,146,169), Weight=c(38.1,44.5,40.8,34.9,38.3,50.8,22.9,51.0,46.5,51.0,46.5,60.3,
4、37.7,38.1,45.1,68.0,58.1,38.6,50.8) #数据框pairs(df) #多组图pairs( Age + Height + Weight, data=df) #与上述结果相4.3coplot(WeightHeight|Age, data=df) #年龄条件下的协同图4.4点图VADeaths #Virginia州在1940年的人口死亡率数据(R自带)me1<- apply(VADeaths, 1, mean) #矩阵的行向量的均值me2<- apply(VADeaths, 2, mean) #矩阵的列向量的均值dotchart(VADeaths, gda
5、ta=me2, gpch=19, #按类型分类 main = "Death Rates in Virginia - 1940")dotchart(t(VADeaths), gdata=me1, gpch=19, #按年龄分类 main = "Death Rates in Virginia - 1940")4.5饼图pie.sales<-c(39, 200, 42, 15, 67, 276, 27, 66);names(pie.sales)<-c("EUL","PES","EFA",&
6、quot;EDD","ELDR","EPP","UNE","other") #各候选人的得票结果# figure1,默认色彩,逆时针pie(pie.sales,radius = 0.9,main ="Ordinary chart")# figure2,彩虹色彩,顺时针pie(pie.sales,radius=0.9,col=rainbow(8),clockwise =TRUE,main="Rainbow colours")# figure3,灰度色彩,顺时针pie(
7、pie.sales,radius =0.9,clockwise =TRUE,col =gray(seq(0.4,1.0,length=8),main="Grey colours")# figure4,阴影色彩,逆时针pie(pie.sales,radius=0.9,density=10,angle=15+15*1:8,main="The density of shading lines")4.6条形图pie.sales<-c(39, 200, 42, 15, 67, 276, 27, 66);par(mai=c(0.9, 0.9, 0.3, 0.3
8、) #定义图像边距# figure1, 添加一条线r<barplot(pie.sales,space=1,col=rainbow(8);lines(r,pie.sales,type='h',col=1,lwd=2)# figure2,用text()添加平均值mp <- barplot(VADeaths);tot<-colMeans(VADeaths); text(mp, tot+ 3, format(tot), xpd = TRUE, col = "blue") # figure3, 添加条形的颜色barplot(VADeaths, spa
9、ce = 0.5, col = c("lightblue", "mistyrose", "lightcyan", "lavender", "cornsilk")# figure4, 条形平行排列barplot(VADeaths, beside = TRUE, col = c("lightblue", "mistyrose","lightcyan", "lavender", "cornsilk"),
10、 legend = rownames(VADeaths),ylim = c(0, 100)4.7直方图df<data.frame(Age=c(13,13,14,12,12,15,11,15,14,14,14,15,12,13,12,16,12,11,15), Height=c(144,166,163,143,152,169,130,159,160,175,161,170,146,159,150,183,165,146,169), Weight=c(38.1,44.5,40.8,34.9,38.3,50.8,22.9,51.0,46.5,51.0,46.5,60.3,37.7,38.1,4
11、5.1,68.0,58.1,38.6,50.8) #数据框par(mai=c(0.9, 0.9, 0.6, 0.3) #图形边距attach(df) #连接数据框# figure1,增加直方图和外框的颜色,以及相应的频数hist(Height, col="lightblue", border="red", labels = TRUE, ylim=c(0, 7.2)# figure2,使用线条阴影并利用text()标出频数,用lines()绘出数据的密度曲线(蓝色)和正态分布密度曲线(红色)r<-hist(Height,breaks=12,freq=
12、FALSE,density=10,angle = 15+30*1:6);text(r$mids, 0, r$counts, adj=c(.5, -.5),cex=1.2 );lines(density(Height),col="blue",lwd=2);x<-seq(from=130, to=190, by=0.5);lines(x, dnorm(x,mean(Height), sd(Height), col="red", lwd=2)detach() #取消连接数据框4.8箱线图(1)x<c(25,45,50,54,55,61,64,68,
13、72,75,75,78,79,81,83,84,84,84,85,86,86,86,87,89,89,89,90,91,91,92,100)fivenum(x) #上、下四分位数,中位数, 最大和最小值boxplot(x) #绘制箱线图(2)InsectSprays #数据框,其中count为昆虫数目,spray为杀虫剂的类型boxplot(countspray,data =InsectSprays,col="lightgray")#矩形箱线图boxplot(countspray,data=InsectSprays,notch=TRUE,col=2:7,add=TRUE)4
14、.9 QQ图df<-data.frame(Age=c(13,13,14,12,12,15,11,15,14,14,14,15,12,13,12,16,12,11,15),Height=c(144,166,163,143,152,169,130,159,160,175,161,170,146,159,150,183,165,146,169),Weight=c(38.1,44.5,40.8,34.9,38.3,50.8,22.9,51.0,46.5,51.0,46.5,60.3,37.7,38.1,45.1,68.0,58.1,38.6,50.8) #数据框par(mai=c(0.9, 0.
15、9, 0.6, 0.3)attach(df)qqnorm(Weight) #数据的正态Q-Q图qqline(Weight) #在Q-Q图上增加一条理论直线y =x +qqnorm(Height)qqline(Height)detach()4.10 三维透视图perspy <- x <- seq(-7.5, 7.5, by = 0.5) #定义域f<-function(x,y)r<-sqrt(x2+y2) + 2-52 #加上一个很小的量2-52是为了避免在下一行运算时分母为零z<-sin(r)/r;z<-outer(x,y,f) #对f作外积运算形成网格pa
16、r(mai=c(0.0,0.2,0.0,0.1) #图像边距persp(x,y,z,theta=30,phi=15,expand=.7,col="lightblue",xlab="X",ylab="Y",zlab="Z") #绘制三维图4.11 等值线contoury<-x <- seq(-3, 3, by = 0.125) #定义域f<-function(x,y)z<-3*(1-x)2*exp(-x2-(y+1)2)-10*(x/5-x3-y5)*exp(-x2-y2)-1/3*exp(-
17、(x+1)2 -y2);z <- outer(x, y, f) #对函数f作外积运算形成网格par(mai=c(0.8, 0.8, 0.2, 0.2) #图像边距contour(x,y,z,levels=seq(-6.5,8,by=0.75),xlab="X",ylab="Y",col="blue") #绘制等值线4.12 添加点、线、文字或符号data(iris) #调用数据op<-par(mai=c(1,1,0.3,0.3),cex=1.1) #定义图形参数x<-iris$Petal.Length;y<-i
18、ris$Petal.Widthplot(x,y,type="n",xlab="Petal Length",ylab="Petal Width",cex.lab=1.3)Species<-c("setosa","versicolor","virginica")pch<-c(24,22,25) #图中点的形状for(i in 1:3)index<-iris$Species=Speciesi;points(xindex,yindex,pc=pchi,col=i+1
19、,bg=i+1) #添加点par(op) #访问当前图形参数设置text(c(3, 2.5, 4),c(0.25, 1.5, 2.25),labels=Species,font=2,col=c(2,3,4),cex=1.5) #添加文字说明4.13 添加直线、线段和图例data(cars)Q1<-function(beta,data) sum(abs(data,2-beta1-beta2*data,1) #偏差的绝对值之和Qinf<-function(beta,data) max(abs(data,2-beta1-beta2*data,1)z1<-optim(c(-17,4)
20、,Q1,data=cars);zinf<-optim(c(-17, 4),Qinf,data =cars);lm.sol<-lm(distspeed,data=cars) #线性回归op<-par(mai=c(.9,.9,.5,0.1),cex=1.1) #绘图参数plot(cars,main="Stopping Distance versus Speed",ylim=c(0,140),xlab="Speed (mph)",ylab="Distance (ft)",pch=19,col="magenta&q
21、uot;,cex.lab=1.2)abline(lm.sol,lwd=2,col="blue") #加线abline(a = z1$par1, b = z1$par2, lty = 4, lwd=2, col="red")abline(a = zinf$par1, b = zinf$par2, lty=5, lwd=2, col="green")pre<-predict(lm.sol); x0 <- cars$speed23; y0 <- cars$dist23segments(x0, y0, x1 = x0, y1
22、 = pre23, col= 1, lwd=2) #加线段和符号expr<-expression(paste("(", xi,",", yi, ")"); text(x0+1.5, y0, expr);expr1<-expression(min=sum(beta0+beta1*xi-yi)2,i=1,n);expr2<-expression(min=sum(abs(beta0+beta1*xi-yi),i=1,n);expr3<-expression(min=max(abs(beta0+beta1*xi-yi)
23、,i)legend(4, 140, legend=c(expr1, expr2, expr3),col=c("blue", "red", "green"),lty=c(1,4,5),lwd=2);par(op) #加图例4.14 添加图题、坐标轴与边框plot(cars,main ="", axes = F) # 散点图,不含图题、坐标轴title(main = " 制动距离与车速 ") # 添加图题axis(side = 1); axis(side = 2) # 添加坐标轴box(lty =
24、2, lwd = 2, col = 2) # 添加边框4.15绘制多边形和阴影区域。#绘制多边形op <- par(mai=c(0.9, 0.9, 0.6, 0.3)x <- c(1, 15, 20, 30, 15); y <- c(10, 1, 20, 15, 30)plot(x, y, type="n", main = "Polygon")polygon(x,y,density=5,angle=15,lwd=2,border="red",lty=2,col="yellow2")#绘制正态分布的
25、上侧分位数x<-seq(-4,4,by=0.1);plot(x,dnorm(x),type="l",lwd=2,col=4,xlim=c(-3,3),ylim=c(-0.01,0.4),ylab="Normal Density",main="Shadow");abline(h=0,v=0)z<-qnorm(1-0.05);xx<-seq(z,4,by=0.1)polygon(c(xx,z),c(dnorm(xx),dnorm(4),col="yellow1")text(z,-0.015,expre
26、ssion(Zalpha),adj=0.4,cex=1.1)text(2,0.02,expression(alpha),adj=0.5,cex=1.5)legend(-3,0.4,expression(alpha=0.05),adj=0.2)par(op)4.16par(omi=c(.5,.5,.5,.5);par(mfrow=c(3, 2)par(mar=c(3,2,2,1) # figrue 1plot(c(0,10),c(0,10),type="n",axes=F,xlab="",ylab="")text(5,5,labels=
27、"图1",cex=1.5);box(which="figure",lwd=2);box(lwd=2,lty=2)par(mar=c(3,3,2,1) # figrue 2boxplot(countspray,data=InsectSprays,col="lightgray")boxplot(countspray,data=InsectSprays,notch=TRUE,col=2:7,add=TRUE);box(which ="figure",lwd=2)Height<-c(144,166,163,143,1
28、52,169,130,159,160,175,161,170,146,159,150,183,165,146,169)par(mar=c(4.5, 4.5, 2, 1) # figrue 3hist(Height, col="lightblue", border="red", labels = TRUE, ylim=c(0, 7.2);box(which = "figure", lwd=2)plot(c(0,10),c(0,10), type="n", axes=F, xlab="", ylab
29、="")text(5,5, labels="图4", cex=1.5)par(mar=c(3, 2, 2, 1) # figrue 4box(lwd=2, lty=2); box(which = "figure",lwd=2)par(mar=c(3, 3, 2, 1) # figrue 5plot(cars); box(which = "figure",lwd=2)par(mar=c(2, 2, 1, 1) # figrue 6plot(c(0,10),c(0,10), type="n", ax
30、es=F, xlab="", ylab="")box(); text(5,5, labels="mfg=c(3,2,3,2)", cex=1.5)box(which = "figure", lwd=2); box(which = "outer", lwd=2)mtext("总图题", line=1, outer=T, cex=1.5)4.17op<-par(lwd=2, omi = c(.1, .1, .1, .1) # alayout(matrix(1:4, 2, 2
31、)layout.show(4)layout(matrix(1:6, 3, 2, byrow=TRUE) # blayout.show(6)layout(matrix(c(1,2,3,3), 2, 2, byrow=TRUE) # clayout.show(3)layout(matrix(1:4, 2, 2, byrow=TRUE), widths=c(3,1), heights=c(1,3) # dlayout.show(4)layout(matrix(c(1,1,2,1), 2, 2), widths=c(2,1), heights=c(1,2)layout.show(2) # elayou
32、t(matrix(c(0,1,2,3), 2, 2), widths=c(1,3), heights=c(1,3)layout.show(3) # fpar(op) #恢复原来的图形参数par(mfrow = c(1,1) #取消一页多图4.18library(ggplot2)library(gridExtra) # 加载包 ( 需先安装 )# 散点图p1<-ggplot(iris,aes(x=Petal.Length,y=Petal.Width)+(base_family="STKaiti",base_size=9)+geom_point(aes(colour=Sp
33、ecies)+labs(title="散点图");p1# 箱线图p2<-ggplot(iris,aes(x = Species,y = Sepal.Length)+theme_gray(base_family = "STKaiti",base_size = 9)+geom_violin(aes(fill = Species),show.legend = F)+labs(title = " 箱线图 ")+theme(plot.title = element_text(hjust = 0.5);p2#19 # 融合汽缸数 (cyl)
34、 和档位数 (gear) 这两个变量library(reshape2)mtcars.m<-melt(mtcars, id = c("mpg", "disp", "hp", "drat","wt", "qsec", "am" ,"vs", "carb") #id 中不含 cyl 和 gearhead(mtcars)mtcars.m#20p1<-ggplot(data = mtcars); summary(p
35、1)p2 <- ggplot(data = mtcars, mapping = aes(x = wt, y = hp, color =gear); summary(p2) #aes() 指定了横纵坐标分别为 wt 和 hp, 颜色为gear 这三种图形属性p <- ggplot(mtcars, aes(x = mpg, y = wt, color = factor(gear)#设定默认的映射关系p + geom_point()#沿用默认的映射关系来绘制散点图p + geom_point(aes(shape = factor(carb)#添加图层中的shape的映射关系p + geo
36、m_point(aes(y = carb)#修改默认的y的映射关系, 注意图中y轴名称仍然是默认的wtp + geom_point(aes(color = NULL)#删除默认的color映射关系#21#矩阵散点图和平行坐标图分析 iris 中变量间的关系#GGally包中的ggscatmat()可绘制矩阵散点图library(GGally)ggscatmat(data = iris,1:5,columns = 1:4,color = "Species" , alpha = 0.8)+theme_bw(base_family = "STKaiti" ,
37、base_size = 10)+theme(plot.title = element_text(hjust = 0.5)+ggtitle("矩阵散点图") #columns表示绘制矩阵散点图的变量, color 为指定数据中的分组变量#使用平行坐标图分析每个样本在各个特征上的变化情况ggparcoord(data = iris,1:5,columns = 1:4,groupColumn = "Species",scale = "center")+theme_bw(base_family = "STKaiti",ba
38、se_size = 10)+theme(plot.title = element_text(hjust = 0.5),legend.position = "bottom")+ggtitle("平行坐标图")+labs(x = "")#22 例4.6: :直方图探索 120 年来奥运会运动员数据集的信息# 读取数据,数据融合library(readr); library(dplyr)athlete_events <- read_csv("F:/文档/大学课程/R语言/ch04/athlete_events.csv&quo
39、t;)noc_regions <- read_csv("F:/文档/大学课程/R语言/ch04/noc_regions.csv")athletedata <- inner_join(athlete_events,noc_regions,1:2,by=c("NOC"="NOC")summary(athletedata); head(athletedata); str(athletedata) # 查看数据# 查看每个国家参与奥运会运动员人数plotdata <- athletedata%>%group_by(re
40、gion)%>%summarise(number=n()%>% arrange(desc(number)# 可视化前40个人数多的国家的参与人数ggplot(plotdata1:30,aes(x=reorder(region,number),y=number)+ theme_bw(base_family = "STKaiti")+ geom_bar(aes(fill=number),stat = "identity",show.legend = F)+ coord_flip()+scale_fill_gradient(low = "
41、#56B1F7", high = "#132B43")+ labs(x="地区",y="运动员人数",title="不同地区奥运会运动员人数")+ theme(axis.text.x = element_text(vjust = 0.5), plot.title = element_text(hjust = 0.5)#23 例4.7: :热力图探索 120 年来奥运会数据集男女运动员变化# 可视化数据,分析参赛运动员男女人数的变化library(RColorBrewer)# 人数最多的30个地区,不同年份
42、运动员人数变化region30 <- athletedata%>%group_by(region)%>% summarise(number=n()%>% arrange(desc(number)region30 <- region30$region1:30# 不同性别下的,可视化人数最多的15个地区,不同年份运动员人数变化plotdata <- athletedataathletedata$region %in%region301:15,%>% group_by(region,Year,Sex)%>% summarise(number=n()#绘
43、热力图ggplot(data=plotdata, aes(x=Year,y=region) + theme_bw(base_family = "STKaiti") + geom_tile(aes(fill = number),colour = "white")+ scale_fill_gradientn(colours=rev(brewer.pal(10,"RdYlGn")+ scale_x_continuous(breaks=unique( plotdata$Year) + theme(axis.text.x = element_t
44、ext(angle = 90,vjust = 0.5)+ facet_wrap(Sex,nrow = 2)#24 例4.8: :表情图探索奥运会数据集各地区奖牌数量# “USA”,“Germany”,“France” ,“UK”,“Russia”,“China”6个地区获奖情况library(ggChernoff)# 查看不同季节举办的的奥运会运动员人数变化region6 <- c("USA","Germany","France" ,"UK","Russia","China&qu
45、ot;)index <- (athletedata$region %in% region6)&(!is.na(athletedata$Medal)&(athletedata$Season="Summer")plotdata <- athletedataindex,plotdata2 <- plotdata%>%group_by(Year,region)%>% summarise(Medalnum=n()# 绘制表情图ggplot(plotdata2,aes(x=Year,y=Medalnum)+ theme_bw(base_fa
46、mily = "STKaiti")+ geom_line()+ geom_chernoff(fill = 'goldenrod1')+ facet_wrap(region,ncol = 2)+ labs(x="举办时间",y="奖牌数")#26 例4.10: :使用韦恩图分析集合之间的关系#分析几个向量之间的交集library(VennDiagram) #VennDiagram包最多可以绘制5个集合的韦恩图library(grid)library(futile.logger)#绘制4个数组的韦恩图vcol <-
47、c("red","blue","green","DeepPink")T<-venn.diagram(list(First =c(1:30), Second=seq(1,50,by = 2), Third =seq(2,50,by = 2), Four = c(20,70), filename = NULL,lwd = 0.5, fill = vcol,alpha = 0.5,margin = 0.1)grid.draw(T)#27 例4.11: :使用奥运会 120 年的运动员数据集树形图可视化# 树图可视化
48、数据library(treemap); library(readr); library(dplyr)athlete_events <- read_csv("F:/文档/大学课程/R语言/ch04/athlete_events.csv")noc_regions <- read_csv("F:/文档/大学课程/R语言/ch04/noc_regions.csv")athletedata <- inner_join(athlete_events,noc_regions,1:2,by=c("NOC"="NOC&quo
49、t;)plotdata <- athletedata%>% group_by(region,Sex)%>% summarise(number=n()# 计算奖牌数量plotdata2 <- athletedata!is.na(athletedata$Medal),%>% group_by(region,Sex)%>% summarise(Medalnum=n()# 合并数据plotdata3 <- inner_join(plotdata2,plotdata,by=c("region", "Sex")# 使用tre
50、emap 可视化数据treemap(plotdata3,index = c("Sex","region"),vSize = "number", vColor = "Medalnum",type="value",palette="RdYlGn", title = "不同性别下每个国家的运动员人数",fontfamily.title = "STKaiti", title.legend = "奖牌数量",fontfamil
51、y.legend="STKaiti")#28 例4.12: :可视化美国的各个飞机场之间的航班联系#使用飞机航线数据可视化library(maps); library(geosphere)# 读取飞机航线的数据usaairline <- read.csv("F:/文档/大学课程/R语言/ch04/usaairline.csv")airportusa <- read.csv("F:/文档/大学课程/R语言/ch04/airportusa.csv")map("state",col="palegre
52、en", fill=TRUE, bg="black", lwd=0.1)# 添加起点的位置points(x=airportusa$Longitude, y=airportusa$Latitude, pch=19, cex=0.4,col="tomato")col.1 <- adjustcolor("orange", alpha=0.4)# 添加边for(i in 1:nrow(usaairline) node1 <- usaairlinei,c("Latitude.x","Longi
53、tude.x") node2 <- usaairlinei,c("Latitude.y","Longitude.y") arc <- gcIntermediate( c(node1$Longitude.x, node1$Latitude.x), c(node2$Longitude.y, node2$Latitude.y), n=1000, addStartEnd=TRUE ) lines(arc, col=col.1, lwd=0.2) #29 例4.13: :利用航班数量展示国家之间联系的频繁程度#利用igraph库可视化社交网络
54、图library(igraph)# 读取节点和边的数据vertexdata <- read.csv("F:/文档/大学课程/R语言/ch04/vertex.csv")edgedata <- read.csv("F:/文档/大学课程/R语言/ch04/edge.csv")# Country:国家; airportnumber:机场数量; vtype:节点的类型; etype:边的类型;# Country.x, Country.y:连线的两个点; connectnumber:连接的数量# 定义网络图g <- graph_from_data_
55、frame(edgedata,vertices = vertexdata,directed = TRUE)# 添加边的宽度E(g)$width <- log10(E(g)$connectnumber)#生成节点和边的颜色colrs <- c("gray50", "tomato", "gold")V(g)$color <- colrsV(g)$vtypeE(g)$color <- colrsE(g)$etype# plot 4个图 - 2 rows, 2 columns,每个图使用不同的图像样式par(mfrow
56、=c(2,2), mar=c(0,0,0,0)plot(g, layout = layout_in_circle(g), edge.arrow.size=0.4, vertex.size = 10*log10(V(g)$airportnumber), vertex.label.cex = 0.6)plot(g, layout = layout_with_fr(g), edge.arrow.size=0.4, vertex.size = 10*log10(V(g)$airportnumber), vertex.label.cex = 0.6)plot(g, layout = layout_on_
57、sphere(g), edge.arrow.size=0.4, vertex.size = 10*log10(V(g)$airportnumber), vertex.label.cex = 0.6)plot(g, layout = layout_randomly(g), edge.arrow.size=0.4, vertex.size = 10*log10(V(g)$airportnumber), vertex.label.cex = 0.6)#30 例4.14:构造函数绘制 3D 可视化图# 使用plot3D 包绘制3D 图像library(plot3D)library(ggplot2)x
58、<- y <- seq(0,10,by = 0.5)# 生成网格数据并计算Zxy <- mesh(x,y)z <- sin(xy$x) + cos(xy$y) + sin(xy$x) * cos(xy$y)par(mfrow = c(1,2)hist3D(x,y,z,phi = 45, theta = 45,space = 0.1,colkey = F,bty = "g")surf3D(xy$x,xy$y,z,colkey = F,border = "black",bty = "b2")# 使用plotly 包
59、绘制3D 图像library(plotly)plot_ly(x = xy$x, y = xy$y, z = z,showscale = FALSE)%>% add_surface()第二部分、教材例题:1.#二项分布n<-20p<-0.2k<-seq(0,n)plot(k,dbinom(k,n,p),type='h',main='Binomial distribution,n=20,p=0.2',xlab='k')#泊松分布lambda<-4.0k<-seq(0,20)plot(k,dpois(k,lambda
60、),type='h', main='Poisson distribution, lambda=5.5',xlab='k')#几何分布p<-0.5k<-seq(0,10)plot(k,dgeom(k,p),type='h', main='Geometric distribution,p=0.5',xlab='k')#几何分布p<-0.5k<-seq(0,10)plot(k,dgeom(k,p),type='h', main='Geometric dist
61、ribution,p=0.5',xlab='k')#超几何分布N<-30M<-10n<-10k<-seq(0,10)plot(k,dhyper(k,N,M,n),type='h',main='Hypergeometric distribution,N=30,M=10,n=10',xlab='k')#负二项分布n<-10p<-0.5k<-seq(0,40)plot(k,dnbinom(k,n,p),type='h',main='Negative Binomia
62、l distribution,n=10,p=0.5',xlab='k')#正态分布curve(dnorm(x,0,1), xlim=c(-5,5), ylim=c(0,.8), col= ' red ' , lwd=2, lty=3)curve(dnorm(x,0,2), add=T, col= ' blue ' , lwd=2, lty=2)curve(dnorm(x,0,1/2), add=T, lwd=2, lty=1)title(main="Gaussian distributions")legend(par(
63、'usr')2, par('usr')4, xjust=1, c('sigma=1','sigma=2','sigma=1/2'), lwd=c(2,2,2), lty=c(3,2,1), col=c('red','blue',par("fg")#t分布curve(dt(x,1), xlim=c(-3,3), ylim=c(0,.4),col= ' red ' , lwd=2, lty=1)curve(dt(x,2), add=T, col= ' green ' , lwd=2, lty=2)curve(dt(x,10), add=T, col= ' orange ' , lwd=2, lty=3)curve(dnor
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年二手音响设备买卖合同模板
- 环保设备租赁合同模板
- 2024年城市公共服务领域农民工合同
- 青峰岭土坝课程设计
- 山西省2024-2025学年九年级9月月考语文试题(含答案)
- 2024年大数据中心建设与分包合同
- 工地围挡合同模板模板
- 2024年多功能会议室租赁合同
- 汽车模拟驾驶课程设计
- 广告搭建协议合同模板
- 小班美术《小刺猬背果果》课件
- 家庭教育指导说明报告
- 档案移交方案
- 高中英语外研版(2019)选择性必修第一册各单元主题语境与单元目标
- 人教版数学三年级上册《1-4单元综合复习》试题
- 2024年水利工程行业技能考试-水利部质量检测员笔试历年真题荟萃含答案
- 医学与大数据:信息技术在医疗中的应用
- (新版)三级物联网安装调试员技能鉴定考试题库大全-上(单选题汇总)
- 2024年室内装饰设计师(高级工)考试复习题库(含答案)
- 教育培训行业2024年生产与制度改革方案
- PCB文字喷印工艺
评论
0/150
提交评论