Statistical Distribution Each distribution has four functions:d―density (density function), p―distribution function, q―quantile function, r―random number function.The normal curve is bell-shaped, with both ends low and high in the middle. It is symmetrical on the left and right because its curve is bell-shaped, so people often call it bell-shaped curve.
1. rnorm
Generate random numbers of normal distributions
rnorm(n, mean = 0, sd = 1)
rnorm(100) rnorm(10,2,5)
2. dnorm
Probability density distribution
dnorm(x, mean = 0, sd = 1, log = FALSE)
dnorm(1) # Probability when x=1 in the standard normal distribution.# Make a picturex <- seq(-1,1,0.01) plot(x,dnorm(x))
3. pnorm
Cumulative probability
pnorm(q, mean = 0, sd = 1, = TRUE, = FALSE)
pnorm(0) # In normal distribution, the cumulative probability of x from negative infinite to 0 (integral)pnorm(1.644854) # Default =TRUE, P[X ≤ x] pnorm(1.644854, =FALSE) #P[X > x]
This function takes the probability value and gives the number whose accumulated value matches the probability value, the inverse function of pnorm.
qnorm(p, mean = 0, sd = 1, = TRUE, = FALSE)
qnorm(0.95) # x value with accumulated value of 0.95qnorm(c(0.5,0.8,0.6,0.3)) qnorm(pnorm(0))
5. Normal distribution test
It can be used to detect whether the data is a normal distribution through density maps, QQ maps and normal distribution assumptions.
# P<0.05, then the distribution is a non-normal distribution.x1 <- rnorm(50) x2 <- runif(30) (x1) (x2) (rnorm(100, mean = 5, sd = 3)) (runif(100, min = 2, max = 4))
This is the end of this article about the implementation example of R language normal distribution. For more relevant R language normal distribution content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!