Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

R dnorm() pnorm() qnorm() Functions - The Normal Distribution Family

R dnorm() pnorm() qnorm() Functions - The Normal Distribution Family

R Language Examples R Language Examples

R provides four core functions for the normal distribution: dnorm() the density function, pnorm() the cumulative probability, qnorm() the quantile function, and rnorm() random number generation.

They answer different questions respectively: What is the probability density of a certain value? What is the cumulative probability? What is the quantile corresponding to a certain probability?

The syntax of each function is as follows:

dnorm(x, mean = 0, sd = 1)   # 密度函数

pnorm(q, mean = 0, sd = 1)   # 累积分布函数 P(X <= q)

qnorm(p, mean = 0, sd = 1)   # 分位数函数

Parameter Description:

Example

Suppose exam scores follow N(70, 10)

dnorm: Probability density at a score of 70

print

(

paste

(

"dnorm(70):"

,

round

(

dnorm

(

70

,

mean

=

70

,

sd

=

10

)

,

4

)

)

)

pnorm: Probability of a score below 85

print

(

paste

(

"P(score <= 85):"

,

round

(

pnorm

(

85

,

mean

=

70

,

sd

=

10

)

,

4

)

)

)

pnorm: Probability of a score above 85

print

(

paste

(

"P(score > 85):"

,

round

(

1

pnorm

(

85

,

mean

=

70

,

sd

=

10

)

,

4

)

)

)

qnorm: The cutoff for the top 10%

print

(

paste

(

"Top 10% score cutoff:"

,

round

(

qnorm

(

0.9

,

mean

=

70

,

sd

=

10

)

,

2

)

)

)

The output of the code above is:

[1] "dnorm(70): 0.0399"

[1] "P(score <= 85): 0.9332"

[1] "P(score > 85): 0.0668"

[1] "前 10% 分数线: 82.82"

R Language Examples R Language Examples