R语言怎么检验分布是不是T分布

Python015

R语言怎么检验分布是不是T分布,第1张

ks.test()实现了KS检验,可以检验任意样本是不是来自给定的连续分布。

你这里的用法就是:

ks.test(data,pt,df=df) #data是样本的数据,df是要检验的t分布的自由度

我们可以用很多方法分析一个单变量数据集的分布。最简单的办法就是直接看数

字。利用函数summary 和fivenum 会得到两个稍稍有点差异的汇总信息。此外,stem

(\茎叶"图)也会反映整个数据集的数字信息。

>attach(faithful)

>summary(eruptions)

Min. 1st Qu. Median Mean 3rd Qu. Max.

1.600 2.163 4.000 3.488 4.454 5.100

>fivenum(eruptions)

[1] 1.6000 2.1585 4.0000 4.4585 5.1000

>stem(eruptions)

The decimal point is 1 digit(s) to the left of the |

16 | 070355555588

18 | 000022233333335577777777888822335777888

20 | 00002223378800035778

22 | 0002335578023578

24 | 00228

26 | 23

28 | 080

30 | 7

32 | 2337

34 | 250077

36 | 0000823577

38 | 2333335582225577

40 | 0000003357788888002233555577778

42 | 03335555778800233333555577778

44 | 02222335557780000000023333357778888

46 | 0000233357700000023578

48 | 00000022335800333

50 | 0370

茎叶图和柱状图相似,R 用函数hist 绘制柱状图。

>hist(eruptions)

>## 让箱距缩小,绘制密度图

>hist(eruptions, seq(1.6, 5.2, 0.2), prob=TRUE)

>lines(density(eruptions, bw=0.1))

>rug(eruptions) # 显示实际的数据点

更为精致的密度图是用函数density 绘制的。在这个例子中,我们加了一条

由density 产生的曲线。你可以用试错法(trial-and-error)选择带宽bw(bandwidth)

因为默认的带宽值让密度曲线过于平滑(这样做常常会让你得到非常有\意思"的密度

分布)。(现在已经有一些自动的带宽挑选方法2,在这个例子中bw = "SJ"给出的结

果不错。)

我们可以用函数ecdf 绘制一个数据集的经验累积分布(empirical cumulative

distribution)函数。

>plot(ecdf(eruptions), do.points=FALSE, verticals=TRUE)

显然,这个分布和其他标准分布差异很大。那么右边的情况怎么样呢,就是火山

爆发3分钟后的状况?我们可以拟合一个正态分布,并且重叠前面得到的经验累积密

度分布。

>long <- eruptions[eruptions >3]

>plot(ecdf(long), do.points=FALSE, verticals=TRUE)

>x <- seq(3, 5.4, 0.01)

>lines(x, pnorm(x, mean=mean(long), sd=sqrt(var(long))), lty=3)

分位比较图(Quantile-quantile (Q-Q) plot)便于我们更细致地研究二者的吻合

程度。

par(pty="s") # 设置一个方形的图形区域

qqnorm(long)qqline(long)

上述命令得到的QQ图表明二者还是比较吻合的,但右侧尾部偏离期望的正态分布。

我们可以用t 分布获得一些模拟数据以重复上面的过程

x <- rt(250, df = 5)

qqnorm(x)qqline(x)

这里得到的QQ图常常会出现偏离正态期望的长尾区域(如果是随机样本)。我们可以用

下面的命令针对特定的分布绘制Q-Q图

qqplot(qt(ppoints(250), df = 5), x, xlab = "Q-Q plot for t dsn")

qqline(x)

最后,我们可能需要一个比较正规的正态性检验方法。R提供了Shapiro-Wilk 检

>shapiro.test(long)

Shapiro-Wilk normality test

data: long

W = 0.9793, p-value = 0.01052

和Kolmogorov-Smirnov 检验

>ks.test(long, "pnorm", mean = mean(long), sd = sqrt(var(long)))

One-sample Kolmogorov-Smirnov test

data: long

D = 0.0661, p-value = 0.4284

alternative hypothesis: two.sided

(注意一般的统计分布理论(distribution theory)在这里可能无效,因为我们用同样

的样本对正态分布的参数进行估计的。)

转载于:

http://www.biostatistic.net/thread-2413-1-1.html

Yellowstone National Park, established by the U.S. Congress and signed into law by President Ulysses S. Grant on March 1, 1872, is a national park located primarily in the U.S. state of Wyoming, although it also extends into Montana and Idaho. Yellowstone, widely held to be the first national park in the world, is known for its wildlife and its many geothermal features, especially Old Faithful Geyser, one of the most popular features in the park. It has many types of ecosystems, but the subalpine forest is dominant.

Yellowstone National Park spans an area of 3,468.4 square miles (8,983 km2), comprising lakes, canyons, rivers and mountain ranges. Yellowstone Lake is one of the largest high-altitude lakes in North America and is centered over the Yellowstone Caldera, the largest supervolcano on the continent. The caldera is considered an active volcano. It has erupted with tremendous force several times in the last two million years. Half of the world's geothermal features are in Yellowstone, fueled by this ongoing volcanism. Lava flows and rocks from volcanic eruptions cover most of the land area of Yellowstone. The park is the centerpiece of the Greater Yellowstone Ecosystem, the largest remaining, nearly intact ecosystem in the Earth's northern temperate zone.

The Yellowstone Park Foundation is a 501(c)3, non-profit organization created in 1996. A group of concerned citizens, working with the National Park Service, started the Foundation in order to protect, preserve, and enhance Yellowstone National Park.

The Foundation works to fund important projects and programs, many of which are beyond the financial capacity of the National Park Service. The Foundation receives no annual government fundingit relies instead upon the generous support of private citizens, foundations, and corporations to ensure that Yellowstone's great gifts to the world will never diminish.

Since its inception, the Yellowstone Park Foundation has successfully funded more than 100 projects in Yellowstone.