《统计建模与R软件》薛毅
第3章 数据描述性分析
3.2 数据的分布
总结
:绘制图形语法,直方图hist(),密度估计函数density(),绘图需配合plot()绘图,例如:plot(density(w), col=“blue”),茎叶图stem(),
3.2.2 直方图、经验分布图与QQ图
1. 直方图
直方图(histogram),将数据取值的范围分成若干区间(一般是等间隔的),在等间隔的情况下,每个区间长度称为组距。
R语言中,用函数hist()画出样本的直方图:
hist(x, breaks=“Sturges”, freq=NULL, probability=!freq, include.lowest=TRUE, right=TRUE, density=NULL, angle=45, col=NULL, border=NULL, main=paste(“Histogram of”, xname), xlim=range(breaks), ylim=NULL, xlab=xname, ylab, axes=TRUE, plot=TRUE, labels=FLASE, nclass=NULL, …)
其中x是由样本构成的向量。breaks规定直方图的组距:
freq是逻辑变量,col表示直方图中填充的颜色。
2. 核密度估计函数
核密度估计(kernel density estimate)函数density(),其目的是用已知样本估计密度,具体函数为:
density(x, bw=“nrd0”, adjust=1, kernel=c(“gaussian”, “epanechnikov”, “rectangular”, “triangular”, “biweight”, “cosine”, “optcosine”), window=kenrnel, width, give.Rken=FALSE, n=512, from, to, cut=3, na.rm=FLASE)
> w <- c(75.0, 64.0, 47.4, 66.9, 62.2, 62.2, 58.7, 63.5, 66.6, 64.0, 57.0, 69.0, 56.9, 50.0, 72.0)
> hist(w, freq=FALSE)
#纵轴显示密度