衣带渐宽终不悔分享 http://blog.sciencenet.cn/u/tuqiang2014 在康河的柔波里,做一条水草, 向青草更青处漫溯。

博文

环境与生态统计||探索性数据可视化

已有 3740 次阅读 2019-1-12 11:08 |系统分类:科研笔记

探索性数据分析(Exploratory Data Analysis, EDA)是一门学问。在我们拿到数据之后的第一冲动就是拿来建模,得出一个函数来描绘我们希望阐明的自然现象。然而,这只是一个比较浪漫的想法而已。所有统计模型都是基于一个或多个关于数据分布和关系特征的假设。学习统计学方法时,关键技巧就是有统计假设的意识和评价是否满足这些假设的意识。

Exploratory data analysis is an attitude, a state of flexibility, a willingness to look for those things that we believe are not there, as well as those that we believe to be there.

任何数据分析的第一步都应该是对数据分布,潜在关系以及数据中可能存在的问题展开探索性分析。与 EDA 区别的是传统统计分析(Formal Analysis),传统统计分析在假设样本分布后,把数据套入假设模型再做分析。EDA 所做的,就是重新检视我们对数据的理解,为之后的传统统计分析打下基础。

Exploratory data analysis 可以完成这些事情:

  • 让你最大程度得到数据的直觉

  • 发掘潜在的结构

  • 提取重要的变量

  • 删除异常值

  • 检验潜在的假设

  • 建立初步的模型

  • 决定最优因子的设置

对于我们茫然不知所措的数据,就像一个盖着红盖头的新娘,我们需要揭开来看一看。所以,用可视化工具进行探索性数据分析是一个不错的选择,可视化让我们对数据有一个大致的认识。尽管探索性数据分析和数据可视化的目标是不同的,探索性数据分析重在「探索」,为研究者服务;数据可视化重在「讲故事」,为观众服务。

1 数据可视化技术

数据可视化(Data Visualization)计算机图形学的一个子集,是计算机科学的一个分支。 科学可视化的目的是以图形方式说明科学数据,使科学家能够从数据中了解、说明和收集规律。当我们得到数据当然要看看它里面有着怎样的规律,这时我们有两种办法:一个是把它画出来,一个使用函数的形式写出来。也就是要把他归纳比原始数据更简单更容易为人们所接受的形式。而对于我们的数据,一下子要写他们的函数关系式,并不是一件容易的事,所以还是选择用图表来看一看比较好。有哪些可视化的工具呢?

R中有四大框架用于产生图形:

  • 基本图形

  • 网络

  • 栅格

  • ggplot2
    本章分离散数据和连续数据介绍几种可视化技术:

    1.1 分类数据的可视化技术

分类数据一般来说是离散的,主要可以分为以下两种:

  • nominal 变量是指没有自然的顺序的变量。

  • ordinal 变量是指有自然的顺序的变量。

  • 如果 ordinal 变量的范围是在两个值之间的,那么他还是 interval variable。
    得到分类数据第一直觉就是看看不同类别之间有什么差别,然后分析这些差别的来源。

    1.1.1 条(柱)形图

即使你不懂分类变量,你也可能非常熟悉条形图。条形图可以使用graphics库中的barplot得到,该绘图的功能可以用example(barplot)调用。另外一种是lattice包中的barchart函数,也可以用example(barchart)

在R中输入example(barplot)连续点击enter可以看到这个函数的几款基本图形:

同时给出示例代码:

> example(barplot)

barplt> require(grDevices) # for colours

barplt> tN <- table(Ni <- stats::rpois(100, lambda = 5))

barplt> r <- barplot(tN, col = rainbow(20))
Hit <Return> to see next plot: 

barplt> #- type = "h" plotting *is* 'bar'plot
barplt> lines(r, tN, type = "h", col = "red", lwd = 2)

barplt> barplot(tN, space = 1.5, axisnames = FALSE,
barplt+         sub = "barplot(..., space= 1.5, axisnames = FALSE)")
Hit <Return> to see next plot: 

barplt> barplot(VADeaths, plot = FALSE)
[1] 0.7 1.9 3.1 4.3

barplt> barplot(VADeaths, plot = FALSE, beside = TRUE)
     [,1] [,2] [,3] [,4]
[1,]  1.5  7.5 13.5 19.5
[2,]  2.5  8.5 14.5 20.5
[3,]  3.5  9.5 15.5 21.5
[4,]  4.5 10.5 16.5 22.5
[5,]  5.5 11.5 17.5 23.5

barplt> mp <- barplot(VADeaths) # default
Hit <Return> to see next plot: 

barplt> tot <- colMeans(VADeaths)

barplt> text(mp, tot + 3, format(tot), xpd = TRUE, col = "blue")

barplt> barplot(VADeaths, beside = TRUE,
barplt+         col = c("lightblue", "mistyrose", "lightcyan",
barplt+                 "lavender", "cornsilk"),
barplt+         legend = rownames(VADeaths), ylim = c(0, 100))
Hit <Return> to see next plot: 

barplt> title(main = "Death Rates in Virginia", font.main = 4)

barplt> hh <- t(VADeaths)[, 5:1]

barplt> mybarcol <- "gray20"

barplt> mp <- barplot(hh, beside = TRUE,
barplt+         col = c("lightblue", "mistyrose",
barplt+                 "lightcyan", "lavender"),
barplt+         legend = colnames(VADeaths), ylim = c(0,100),
barplt+         main = "Death Rates in Virginia", font.main = 4,
barplt+         sub = "Faked upper 2*sigma error bars", col.sub = mybarcol,
barplt+         cex.names = 1.5)
Hit <Return> to see next plot: 

barplt> segments(mp, hh, mp, hh + 2*sqrt(1000*hh/100), col = mybarcol, lwd = 1.5)

barplt> stopifnot(dim(mp) == dim(hh))  # corresponding matrices

barplt> mtext(side = 1, at = colMeans(mp), line = -2,
barplt+       text = paste("Mean", formatC(colMeans(hh))), col = "red")

barplt> # Bar shading example
barplt> barplot(VADeaths, angle = 15+10*1:5, density = 20, col = "black",
barplt+         legend = rownames(VADeaths))
Hit <Return> to see next plot: 

barplt> title(main = list("Death Rates in Virginia", font = 4))

barplt> # border :
barplt> barplot(VADeaths, border = "dark blue") 
Hit <Return> to see next plot: 

barplt> # log scales (not much sense here):
barplt> barplot(tN, col = heat.colors(12), log = "y")
Hit <Return> to see next plot: 

barplt> barplot(tN, col = gray.colors(20), log = "xy")
Hit <Return> to see next plot: 

barplt> # args.legend
barplt> barplot(height = cbind(x = c(465, 91) / 465 * 100,
barplt+                        y = c(840, 200) / 840 * 100,
barplt+                        z = c(37, 17) / 37 * 100),
barplt+         beside = FALSE,
barplt+         width = c(465, 840, 37),
barplt+         col = c(1, 2),
barplt+         legend.text = c("A", "B"),
barplt+         args.legend = list(x = "topleft"))
Hit <Return> to see next plot: 
>

lattice包中的barchart函数也可以这样获得示例:

> library(lattice)
> example("barchart")

brchrt> require(stats)

brchrt> ## Tonga Trench Earthquakes
brchrt> 
brchrt> Depth <- equal.count(quakes$depth, number=8, overlap=.1)

brchrt> xyplot(lat ~ long | Depth, data = quakes)
Hit <Return> to see next plot: 

brchrt> update(trellis.last.object(),
brchrt+        strip = strip.custom(strip.names = TRUE, strip.levels = TRUE),
brchrt+        par.strip.text = list(cex = 0.75),
brchrt+        aspect = "iso")
Hit <Return> to see next plot: 

brchrt> ## Examples with data from `Visualizing Data' (Cleveland, 1993) obtained
brchrt> ## from http://cm.bell-labs.com/cm/ms/departments/sia/wsc/
brchrt> 
brchrt> EE <- equal.count(ethanol$E, number=9, overlap=1/4)

brchrt> ## Constructing panel functions on the fly; prepanel
brchrt> xyplot(NOx ~ C | EE, data = ethanol,
brchrt+        prepanel = function(x, y) prepanel.loess(x, y, span = 1),
brchrt+        xlab = "Compression Ratio", ylab = "NOx (micrograms/J)",
brchrt+        panel = function(x, y) {
brchrt+            panel.grid(h = -1, v = 2)
brchrt+            panel.xyplot(x, y)
brchrt+            panel.loess(x, y, span=1)
brchrt+        },
brchrt+        aspect = "xy")
Hit <Return> to see next plot: 

brchrt> ## Extended formula interface 
brchrt> 
brchrt> xyplot(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width | Species,
brchrt+        data = iris, scales = "free", layout = c(2, 2),
brchrt+        auto.key = list(x = .6, y = .7, corner = c(0, 0)))
Hit <Return> to see next plot: 

brchrt> ## user defined panel functions
brchrt> 
brchrt> states <- data.frame(state.x77,
brchrt+                      state.name = dimnames(state.x77)[[1]],
brchrt+                      state.region = state.region)

brchrt> xyplot(Murder ~ Population | state.region, data = states,
brchrt+        groups = state.name,
brchrt+        panel = function(x, y, subscripts, groups) {
brchrt+            ltext(x = x, y = y, labels = groups[subscripts], cex=1,
brchrt+                  fontfamily = "HersheySans")
brchrt+        })
Hit <Return> to see next plot: 

brchrt> ## Stacked bar chart
brchrt> 
brchrt> barchart(yield ~ variety | site, data = barley,
brchrt+          groups = year, layout = c(1,6), stack = TRUE,
brchrt+          auto.key = list(space = "right"),
brchrt+          ylab = "Barley Yield (bushels/acre)",
brchrt+          scales = list(x = list(rot = 45)))
Hit <Return> to see next plot: 

brchrt> bwplot(voice.part ~ height, data=singer, xlab="Height (inches)")
Hit <Return> to see next plot: 

brchrt> dotplot(variety ~ yield | year * site, data=barley)
Hit <Return> to see next plot: 

brchrt> ## Grouped dot plot showing anomaly at Morris
brchrt> 
brchrt> dotplot(variety ~ yield | site, data = barley, groups = year,
brchrt+         key = simpleKey(levels(barley$year), space = "right"),
brchrt+         xlab = "Barley Yield (bushels/acre) ",
brchrt+         aspect=0.5, layout = c(1,6), ylab=NULL)
Hit <Return> to see next plot: 

brchrt> stripplot(voice.part ~ jitter(height), data = singer, aspect = 1,
brchrt+           jitter.data = TRUE, xlab = "Height (inches)")
Hit <Return> to see next plot: 

brchrt> ## Interaction Plot
brchrt> 
brchrt> xyplot(decrease ~ treatment, OrchardSprays, groups = rowpos,
brchrt+        type = "a",
brchrt+        auto.key =
brchrt+        list(space = "right", points = FALSE, lines = TRUE))
Hit <Return> to see next plot: 

brchrt> ## longer version with no x-ticks
brchrt> 
brchrt> ## Not run: 
brchrt> ##D bwplot(decrease ~ treatment, OrchardSprays, groups = rowpos,
brchrt> ##D        panel = "panel.superpose",
brchrt> ##D        panel.groups = "panel.linejoin",
brchrt> ##D        xlab = "treatment",
brchrt> ##D        key = list(lines = Rows(trellis.par.get("superpose.line"),
brchrt> ##D                   c(1:7, 1)),
brchrt> ##D                   text = list(lab = as.character(unique(OrchardSprays$rowpos))),
brchrt> ##D                   columns = 4, title = "Row position"))
brchrt> ## End(Not run)
brchrt> 
brchrt> 
brchrt> 
brchrt> 
>

是不是感觉example()很好用?
到这里我们需要知道条形图与柱形图有什么区别?

  • 排版需要

  • 柱形图可以和折线图结合

1.1.1 点图(dotplot)

在描述离散变量的时候我们可以称为点图,在连续变量里面叫散点图,顾名思义就是由一些散乱的点组成的图表,这些点在哪个位置,是由其X值和Y值确定的。所以也叫做XY散点图。在graphics包中有dotplot函数可以来获得点图,同样地可以用example(dotplot)获得观赏,这里就不再演示了。
(散)点图可以用来:

  • 可以展示数据的分布和聚合情况

    • 得到趋势线公式

  • 辅助制图

    #col=15:16用于设置颜色,lcolor设置穿过点的线的颜色,pch=2:3,用于设置点的表示图形,labels和main用于设置显示的信息,cex=1.5表示标签字体放大5倍
    par(mfrow=c(1,2))
    dotchart(Bug_Metrics_Software[,,1],gcolor=1:5,col=6:10,lcolor = "black",pch=15:19,labels=names(Bug_Metrics_Software[,,1]), main="Before Release Bug Frequency",xlab="Frequency Count")
    dotchart(Bug_Metrics_Software[,,2],gcolor=1:5,col=6:10,lcolor = "black",pch=15:19,labels=names(Bug_Metrics_Software[,,2]), main="After Release Bug Frequency",xlab="Frequency Count")

Dot_plot)
Dot Plot in Statistics: What it is and How to read one
散点图是什么?有什么用?
数据可视化·图表篇——散点图

1.1.3脊柱图

和条形图不同的是,脊柱图是长度相同,宽度根据频率变化,脊柱图可以使用spineplot函数实现,脊柱图是马赛克图的一个特例,马赛克图可以通过mosaicplot函数实现,我们使用Titanic数据进行举例.

Mosaic plot常常用来展示Categorical data(分类数据)(关于不同的数据类别,参照连接 更严谨英文比较好的朋友可以看[1]),mosaic plot 强大的地方在于它能够很好的展示出2个或者多个分类型变量(categorical variable)的关系. 它也可以定义为用图像的方式展示分类型数据。

ShiftOperator <- matrix(c(40, 35, 28, 26, 40, 22, 52, 46, 49),nrow=3,dimnames=list(c("Shift 1", "Shift 2", "Shift 3"), c("Operator 1", "Opereator 2", "Operator 3")),byrow=TRUE)
spineplot(ShiftOperator)
abline(h=0.33,lwd=3,col="red")
abline(h=0.67,lwd=3,col="red")
abline(v=0.33,lwd=3,col="green")
abline(v=0.67,lwd=3,col="green")

# 获得Class的频率
> xtabs(Freq~Class,data=Titanic)
Class
 1st  2nd  3rd Crew 
 325  285  706  885 
#获得基于class的survived的变量比率:
> prop.table( xtabs(Freq~Class+Survived,data=Titanic),margin=1)
      Survived
Class         No       Yes
  1st  0.3753846 0.6246154
  2nd  0.5859649 0.4140351
  3rd  0.7478754 0.2521246
  Crew 0.7604520 0.2395480
#重复上述步骤计算Sex 以及Age变量的频率:
> xtabs(Freq~Sex,data=Titanic)
Sex
  Male Female 
  1731    470 
> prop.table(xtabs(Freq~Sex+Survived,data=Titanic),margin=1)
        Survived
Sex             No       Yes
  Male   0.7879838 0.2120162
  Female 0.2680851 0.7319149
> xtabs(Freq~Age,data=Titanic)
Age
Child Adult 
  109  2092 
> prop.table(xtabs(Freq~Age+Survived,data=Titanic), margin=1)
       Survived
Age            No       Yes
  Child 0.4770642 0.5229358
  Adult 0.6873805 0.3126195
> mosaicplot(Titanic,col=c("red","green"))

DataStory:

理解Titanic号船员基于变量Class,Sex,Age的存活率。马赛克图的分割过程是这样的:

  • 依据船舱等级将方块按比例分为四部分,相应部分的宽度和频率成比例;

  • 每块再依据性别被划分为两部分,共8块;

  • 再依据年龄划分为16块;

  • 最后依据是否存活划分为32块。

输出的结果表明:高等仓的存活率比低等仓好,女性使用救生系统的优先程度比男性高,小孩比成人高。

1.1.4 饼图和四折图

饼图很简单,但是有时并不利于分析和观察,饼图使用pie()函数实现。.四折图是展示22k的三维列联表的一种方式,这种方法是获得k个2*2的列联表的饼图,列联表的四个子区域的频率用四分之一圆表示,半径和频率的平方根成比例,和饼图相比,四折图的半径是不同的。四折图可以使用fourfoldplot函数实现。

par(mfrow=c(1,2))
 pie(Severity_Counts[1:5])
 title("Severity Counts Post-Release of JDT Software")
 fourfoldplot(UCBAdmissions,mfrow=c(2,3),space=0.4) 
 title("四折图")

1.2 l连续变量数据的可视化技术

连续变量是在任意两个值之间具有无限个值的数值变量。连续变量可以是数值变量,也可以是日期/时间变量。例如,零件的长度,或者收到付款的日期和时间。
如果您有离散变量而且想要将其包括在回归或方差分析模型中,可以决定是将其视为连续预测变量(协变量),还是类别变量(因子)。如果离散变量具有许多水平,那么最好将其视为连续变量。将预测变量视为连续变量意味着简单线性或多项式函数足以描述响应和预测变量之间的关系。当您将预测变量视为类别变量时,离散响应值将与变量的每个水平拟合,而不必考虑预测变量水平的顺序。使用此信息,除了可以进行分析以外,还可以确定哪个变量最适合您的情况。

1.2.1 箱线图

箱线图基于最小值、下四分位数、中位数、上四分位数和最大值组成,可以使用graphics包中的boxplot函数和lattice包中的bwplot函数实现,如

 library(RSADBE)
 data(resistivity) 
 boxplot(resistivity, range=0)
 library(lattice)
 resistivity2 <- data.frame(rep(names( resistivity),each=8),c(resistivity[,1],resistivity[,2])) 
 names(resistivity2)<- c("Process","Resistivity")
 par(mfrow=c(1,2))
 boxplot(fw$count,fw$speed,names = c("count","speed"),xlab="var",ylab="value",range = 0,col="gray90")
 boxplot(grass$rich~grass$graze,data=grass,horizontal=TRUE,range=0)
 bwplot(Resistivity~Process, data=resistivity2,notch=TRUE)

箱线图有一个叫做notch的重要选项,可以用来比较中位数。顶凹口和底凹口为中位数加减1.57(IQR)/n1/2.如果NOTCH不重合,则说明在统计学上,几组数据的中位数存在显著性差异

1.1.3折线图

折线图对于分类数据和连续型数据都适用,如果数据为连续数据,则使用plot()命令就可实现,只要设置type=选项即可.如果数据的顺序是任意的,那么做出的折线也是任意的,这样无法观察趋势,因此需要将其排序一下,使其具有某种趋势,如:

load("D:\\Users\\Administrator\\Desktop\\RStudio\\Environmental_and_Ecological_Statistics_with_R\\DataCode\\Data\\Beginning.Rdata")
par(mfrow=c(1,3))
plot(Nile,type="l")
plot(sort(mf$Length),mf$NO3,type="l")
plot(rain,type="b",axes = FALSE,xlab="month",tlab=rain)
month=c("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec")
axis(side=1,at=1:length(rain),labels=month)
axis(side=2)
box()

week<-c(1,2,3,4,5,6)
x<-c(3,8,19,24,6,1)
y<-c(1,25,21,3,2,1)

par(mfrow=c(1,2))
plot(week,x,col="red",pch=22,bg="yellow",xlim=c(0,6),ylim=c(0,30),lwd=2,xlab="WEEK",ylab="STUDENT",main="lesson",sub="class",col.main="green",font.main=2,asp=0,cex=1.2,type="b",lty=1)
lines(week,y,col="green",pch=16,bg="yellow",xlim=c(0,6),ylim=c(0,30),lwd=2,xlab="WEEK",ylab="STUDENT",main="lesson",sub="class",col.main="green",font.main=2,asp=0,cex=1.2,type="b",lty=2)
grid(nx=6,ny=6,lwd=2)
abline(h=18,col="black",lty=1,lwd=2)

sp=spline(week,x,n=1000)
sp1=spline(week,y,n=1000)

plot(sp,col="red",type="l",xlim=c(0,6),ylim=c(0,30),lwd=2,xlab="WEEK",ylab="STUDENT",main="lesson",sub="class",col.main="green",font.main=2)
lines(sp1,col="green",type="l",xlim=c(0,6),ylim=c(0,30),lwd=2,xlab="WEEK",ylab="STUDENT",main="lesson",sub="class",col.main="green",font.main=2)
legend("topright",legend=c("x","y"),col=c("red","green"),lwd=2,lty=c(1,2))

直方图

直方图可以通过hist函数和histogram函数实现,我们使用galton数据作为举例.

 data(galton)
 par(mfrow=c(2,2)) 
 hist(galton$parent,breaks="FD",xlab="Height of Parent", main="Histogram for Parent Height with Freedman-Diaconis Breaks",xlim=c(60,75))
 hist(galton$parent,xlab="Height of Parent",main= "Histogram for Parent Height with Sturges Breaks",xlim=c(60,75))
 hist(galton$child,breaks="FD",xlab="Height of Child", main="Histogram for Child Height with Freedman-Diaconis Breaks",xlim=c(60,75))
 hist(galton$child,xlab="Height of Child",main="Histogram for Child Height with Sturges Breaks",xlim=c(60,75))

3.散点图

直方图可以用来理解变量的性质,散点图可以用来理解变量间的关系,两个变量可以使用plot(x,y)函数,x,y为两个向量,如果数据为两列数据框,则会默认将第一列作为x,第二列作为y,如果为多列数据框,则会生成散点图矩阵,可以使用pairs函数做散点图矩阵,例如:

library(lattice)
 data(DCD) 
 par(mfrow=c(2,3)) 
 plot(DCD$Drain_Current, DCD$GTS_Voltage,type="b",xlim=c(1,2.2),ylim=c(0.6,2.4),xlab="Current Drain", ylab="Voltage")
 points(DCD$Drain_Current,DCD$GTS_Voltage/1.15,type="b",col="green")
 # points函数用来向图表中加入其它点,plot()同样可以使用xlab和ylab自定义坐标轴标签。
 plot(0:25,rep(1,26),pch=0:25,cex=2)
 count<-c(9,25,15,2,14,25,24,47)
 speed<-c(2,3,5,9,14,24,29,34)
 fw<-data.frame(count,speed)
 row.names(fw)<-c("Raw","Torridge","Ouse","Exe","Lyn","Brook","Ditch","Fal")
 plot(fw$count,fw$speed,pch="+",cex=4,col="gray90")
 plot(fw$count,fw$speed,xlim=c(0,30),ylim=c(0,50))
 plot(count~speed,data=fw)
 abline(lm(count~speed,data=fw),lty=3,lwd=2,col="gray90")

如果变量较多,使用散点图矩阵会将所有图全部显示,但是散点图矩阵是对称的,我们只需显示一半即可,因此需要自定义两个函数,如:

panel.hist <- function(x, ...) { 
usr<- par("usr"); on.exit(par(usr)) 
par(usr = c(usr[1:2], 0, 1.5) ) 
h <- hist(x, plot = FALSE) 
breaks<- h$breaks; nB<- length(breaks) 
y <- h$counts; 
y <- y/max(y) 
rect(breaks[-nB], 0, breaks[-1], y, col="cyan", ...)
}  

panel.cor <- function(x, y, digits=2, prefix="", cex.cor, ...) { 
usr<- par("usr"); on.exit(par(usr)) 
par(usr = c(0, 1, 0, 1)) 
r <- abs(cor(x,y,use="complete.obs")) 
txt<- format(c(r, 0.123456789), digits=digits)[1] 
txt<- paste(prefix, txt, sep="") 
if(missing(cex.cor)) cex.cor<- 0.8/strwidth(txt) 
text(0.5, 0.5, txt, cex = cex.cor * r) 
}

data(Gasoline)
pairs(Gasoline,diag.panel=panel.hist,lower.panel=panel.smooth,upper.panel=panel.cor)


还有一种双变量箱线图用来展示可视化数据集的位置,扩散,偏斜异常值( location, spread, skewness, and outliers

要理解二元箱线图先知道Tukey depth,相关的解释见:Centerpoint (geometry))。aplpack包的bagplot(x, y)功能可为单变量箱线图提供双变量版本,包含一半的点。双变量中位值是近似的。围栏将其内外的点分隔开。显示离群值。

pannel.bagplot<-function(x,y){
  library(aplpack)
  bagplot(x,y,verbose = FALSE,create.plot = TRUE,add=TRUE)
}
pairs(Gasoline[-19,-c(1,4,5,13)],upper.panel=pannel.bagplot)

4.帕累托图

帕累托法则也称为80-20法则,帕累托图就是基于此生成的,可以使用qcc包的pareto.chart函数实现。

帕累托图又叫排列图、主次图,是按照发生频率大小顺序绘制的直方图,表示有多少结果是由已确认类型或范畴的原因所造成。它是将出现的质量问题和质量改进项目按照重要程度依次排列而采用的一种图表。可以用来分析质量问题,确定产生质量问题的主要因素。按等级排序的目的是指导如何采取纠正措施:项目班子应首先采取措施纠正造成最多数量缺陷的问题。从概念上说,帕累托图与帕累托法则一脉相承,该法则认为相对来说数量较少的原因往往造成绝大多数的问题或缺陷。

> library(qcc)
> Reject_Freq = c(9,22,15,40,8)
> names(Reject_Freq) = c("No Addr.", "Illegible", "Curr. Customer", "No Sign.", "Other")
> Reject_Freq
      No Addr.      Illegible Curr. Customer       No Sign.          Other 
             9             22             15             40              8 
> options(digits=2)
> pareto.chart(Reject_Freq)

Pareto chart analysis for Reject_Freq
                 Frequency Cum.Freq. Percentage Cum.Percent.
  No Sign.            40.0      40.0       42.6         42.6
  Illegible           22.0      62.0       23.4         66.0
  Curr. Customer      15.0      77.0       16.0         81.9
  No Addr.             9.0      86.0        9.6         91.5
  Other                8.0      94.0        8.5        100.0

5,数据平滑(Smoothing)

统计学图像处理中,通过建立近似函数尝试抓住数据中的主要模式,去除噪音、结构细节或瞬时现象,来平滑一个数据集。在平滑过程中,信号数据点被修改,由噪音产生的单独数据点被降低,低于毗邻数据点的点被提升,从而得到一个更平滑的信号。平滑可以两种重要形式用于数据分析:一、若平滑的假设是合理的,可以从数据中获得更多信息;二、提供灵活而且稳健的分析。有许多不同的算法可用于平滑。数据平滑通常通过最简单的密度估计或直方图完成。

data(CT)
plot.ts(CT$Temperature,col="red",pch=1)
CT_3RSS<-smooth(CT$Temperature,kind = "3RSS")
library(LearnEDA)
CT_3RSSH<-han(CT_3RSS)
require(graphics)
lines(CT_3RSS,col="blue",pch=2)
lines(CT_3RSSH,col="green",pch=3)
legend(20,90,c("Original","CT_3RSS","CT_3RSSH"),col=c("red","blue","green"),pch="_")

数据平滑处理
数据预处理—剔除异常值,平滑处理,标准化(归一化)

参考:
数据科学导论:探索性数据分析
探索性数据分析
什么是数据可视化?
数据可视化概览
UCI-STAT201B统计方法-分类数据分析 Lecture 1
条形图与柱形图有什么区别?
R语言之数据可视化
如何用R画折线图,散点图,平滑曲线图
数据可视化 - 马赛克图(mosaic plot)
Beginning R: The Statistical Programming Language



https://blog.sciencenet.cn/blog-1835014-1156647.html

上一篇:环境与生态统计||探索性数据分析
下一篇:scRNA-seq拟时分析工具STREAM简介[附在线版]
收藏 IP: 123.151.22.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-3-29 03:31

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部