新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)R語言教程:R語言標準分布
在來自獨立源的數(shù)據(jù)的隨機集合中,通常觀察到數(shù)據(jù)的分布是正常的。 這意味著,在繪制水平軸上的變量值和垂直軸上的值的計數(shù)的圖形時,我們得到鐘形曲線。 曲線的中心表示數(shù)據(jù)集的平均值。 在圖中,50%的值位于平均值的左側,另外50%位于圖表的右側。 這在統(tǒng)計學中被稱為正態(tài)分布。

r語言有四個內(nèi)置函數(shù)來產(chǎn)生正態(tài)分布。 它們描述如下。
dnorm(x, mean, sd)
pnorm(x, mean, sd)
qnorm(p, mean, sd)
rnorm(n, mean, sd)
以下是在上述功能中使用的參數(shù)的描述 -
- x是數(shù)字的向量。
- p是概率的向量。
- n是觀察的數(shù)量(樣本大?。?/li>
- mean是樣本數(shù)據(jù)的平均值。 它的默認值為零。
- sd是標準偏差。 它的默認值為1。
dnorm()
該函數(shù)給出給定平均值和標準偏差在每個點的概率分布的高度。
# Create a sequence of numbers between -10 and 10 incrementing by 0.1.
x <- seq(-10, 10, by = .1)
# Choose the mean as 2.5 and standard deviation as 0.5.
y <- dnorm(x, mean = 2.5, sd = 0.5)
# Give the chart file a name.
png(file = "dnorm.png")
plot(x,y)
# Save the file.
dev.off()
當我們執(zhí)行上面的代碼,它產(chǎn)生以下結果 -
pnorm()
該函數(shù)給出正態(tài)分布隨機數(shù)的概率小于給定數(shù)的值。 它也被稱為“累積分布函數(shù)”。
# Create a sequence of numbers between -10 and 10 incrementing by 0.2.
x <- seq(-10,10,by = .2)
# Choose the mean as 2.5 and standard deviation as 2.
y <- pnorm(x, mean = 2.5, sd = 2)
# Give the chart file a name.
png(file = "pnorm.png")
# Plot the graph.
plot(x,y)
# Save the file.
dev.off()
當我們執(zhí)行上面的代碼,它產(chǎn)生以下結果 -
qnorm()
該函數(shù)采用概率值,并給出累積值與概率值匹配的數(shù)字。
# Create a sequence of probability values incrementing by 0.02.
x <- seq(0, 1, by = 0.02)
# Choose the mean as 2 and standard deviation as 3.
y <- qnorm(x, mean = 2, sd = 3)
# Give the chart file a name.
png(file = "qnorm.png")
# Plot the graph.
plot(x,y)
# Save the file.
dev.off()
當我們執(zhí)行上面的代碼,它產(chǎn)生以下結果 -
RNORM()
此函數(shù)用于生成分布正常的隨機數(shù)。 它將樣本大小作為輸入,并生成許多隨機數(shù)。 我們繪制一個直方圖來顯示生成的數(shù)字的分布。
# Create a sample of 50 numbers which are normally distributed.
y <- rnorm(50)
# Give the chart file a name.
png(file = "rnorm.png")
# Plot the histogram for this sample.
hist(y, main = "Normal DIstribution")
# Save the file.
dev.off()
當我們執(zhí)行上面的代碼,它產(chǎn)生以下結果 -
當前標題:創(chuàng)新互聯(lián)R語言教程:R語言標準分布
文章起源:http://m.fisionsoft.com.cn/article/dhigcpp.html


咨詢
建站咨詢
