如何在 R 中制作钟形曲线?
为了在 R 中制作钟形曲线,我们将使用正态分布的帮助,这将导致关于平均值对称的钟形曲线。一半的数据将落在平均值的左侧,另一半将落在右侧。
在概率论中,正态分布是实值随机变量的一种连续概率分布。
数学公式:
在哪里,
是意思
是标准差。
对于正态分布,我们使用dnorm()函数来获取给定 x、μ 和 σ 参数的正态分布的概率密度函数值。
Syntax: dnorm(x, mean, sd) (sd=Standard Deviation)
Parameters:-
- X is a vector of numbers.
- Mean is the mean value of the sample data. Its default value is zero.
- Sd is the standard deviation. Its default value is 1.
Returns:-The probability distribution at each point for a given mean and standard deviation.
方法
- 创建一个数字序列
- 获取给定均值和标准差的每个点的概率分布
- 用适当的属性绘制数据
示例 1:
R
# sequence of numbers between -10 and 10 incrementing by 0.1.
x <- seq(-12, 12, by = .1)
# getting probability distribution for each point
y <- dnorm(x, mean = 5, sd = 1)
# Plot graph
plot(x,y)
R
# sequence of numbers between -10 and 10 incrementing by 0.1.
x <- seq(-5, 5, by = .5)
# getting probability distribution
y <- dnorm(x, mean = 1, sd = 1.5)
# plot data
plot(x,y, col="red")
输出:
示例 2:
电阻
# sequence of numbers between -10 and 10 incrementing by 0.1.
x <- seq(-5, 5, by = .5)
# getting probability distribution
y <- dnorm(x, mean = 1, sd = 1.5)
# plot data
plot(x,y, col="red")
输出: