R语言 偏度和峰度
在统计学中, 偏度 和 峰度 是说明数据分布形状的测量方法,或者简单地说,两者都是分析数据集形状的数字方法,与绘制图形和直方图不同,后者是图形方法。这些是正态性测试,用于检查分布的不规则性和不对称性。要在R语言中计算偏度和峰度,需要使用 时刻 包。
倾斜度
偏度是一种统计数字方法,用于测量分布或数据集的不对称性。它告诉人们大多数数据值在分布中围绕平均值的位置。
公式:

其中,



n 代表观察值的总数
存在3种类型的偏度值,在此基础上决定图表的不对称性。这些类型如下:
正偏斜
如果偏度系数大于0,即
,那么该图被称为正偏,大多数数据值小于平均值。大多数数值都集中在图表的左边。
例子:
# Required for skewness() function
library(moments)
# Defining data vector
x <- c(40, 41, 42, 43, 50)
# output to be present as PNG file
png(file = "positiveskew.png")
# Print skewness of distribution
print(skewness(x))
# Histogram of distribution
hist(x)
# Saving the file
dev.off()
输出:
[1] 1.2099
图形表示:

零偏度或对称性
如果偏度系数等于0或近似于0,即
,则表示该图是对称的,数据是正态分布。
例子:
# Required for skewness() function
library(moments)
# Defining normally distributed data vector
x <- rnorm(50, 10, 10)
# output to be present as PNG file
png(file = "zeroskewness.png")
# Print skewness of distribution
print(skewness(x))
# Histogram of distribution
hist(x)
# Saving the file
dev.off()
输出:
[1] -0.02991511
图形表示:

负偏斜
如果偏度系数小于0,即
,则表示该图为负偏态,大部分数据值大于平均值。大多数数值都集中在图表的右侧。
例子:
# Required for skewness() function
library(moments)
# Defining data vector
x <- c(10, 11, 21, 22, 23, 25)
# output to be present as PNG file
png(file = "negativeskew.png")
# Print skewness of distribution
print(skewness(x))
# Histogram of distribution
hist(x)
# Saving the file
dev.off()
输出:
[1] -0.5794294
图形表示:

峰度
峰度是统计学中的一种数字方法,用来衡量数据分布中的峰值的尖锐程度。
公式:

其中,
代表峰度系数
代表数据向量中的
值
代表数据向量的平均值
n 代表观察值的总数
存在3种类型的Kurtosis值,在此基础上衡量峰值的尖锐程度。这些类型如下:
柏拉图式
如果峰度系数小于3,即
,那么数据分布是柏拉图式的。桔梗并不意味着图表是平顶的。
例子:
# Required for kurtosis() function
library(moments)
# Defining data vector
x <- c(rep(61, each = 10), rep(64, each = 18),
rep(65, each = 23), rep(67, each = 32), rep(70, each = 27),
rep(73, each = 17))
# output to be present as PNG file
png(file = "platykurtic.png")
# Print skewness of distribution
print(kurtosis(x))
# Histogram of distribution
hist(x)
# Saving the file
dev.off()
输出:
[1] 2.258318
图形表示:

中峰型
如果峰度系数等于3或近似于3,即
,那么数据分布是中峰型的。对于正态分布,峰度值大约等于3。
例子:
# Required for kurtosis() function
library(moments)
# Defining data vector
x <- rnorm(100)
# output to be present as PNG file
png(file = "mesokurtic.png")
# Print skewness of distribution
print(kurtosis(x))
# Histogram of distribution
hist(x)
# Saving the file
dev.off()
输出:
[1] 2.963836
图形表示法:

峰度
如果峰度系数大于3,即
,则数据分布为Leptokurtic,并在图形上显示一个尖峰。
例子:
# Required for kurtosis() function
library(moments)
# Defining data vector
x <- c(rep(61, each = 2), rep(64, each = 5),
rep(65, each = 42), rep(67, each = 12), rep(70, each = 10))
# output to be present as PNG file
png(file = "leptokurtic.png")
# Print skewness of distribution
print(kurtosis(x))
# Histogram of distribution
hist(x)
# Saving the file
dev.off()
输出:
[1] 3.696788
图形表示法:

极客教程