distribution in R

R
Author

Tony Duan

Published

November 28, 2023

Code
library(ggplot2)
library(tidyverse)

1 Normal distribution or Gaussian distribution

1.1 standard deviation is a measure that indicates how much data scatter around the mean.

mean 0 and standard deviation 1 Normal distribution is call standard normal distribution

1.2 Same R function for Normal distribution

1.2.1 rnorm() Random number generator

create 1000 number from Normal distribution with mean 0 and standard deviation 1

Code
v1= rnorm(1000,mean = 0, sd = 1)
data001=as.data.frame(v1)

ggplot001=ggplot(data001, aes(v1)) + geom_histogram()
ggplot001

1.2.2 pnorm() Cumulatatie probability distribution

the cumulative probability <1 from Normal distribution with mean 0 and standard deviation 1

Code
v1= pnorm(1,mean = 0, sd = 1)
v1
[1] 0.8413447

1.3 qnorm() Quantile distribution(reverse pnorm)

the number from cumulative probability<0.8413447 from Normal distribution with mean 0 and standard deviation 1

Code
v1= qnorm(0.8413447,mean = 0, sd = 1)
v1
[1] 0.9999998

1.4 example

Code
mean = 192.9
sd = 7.1

1.4.1 1

Code
#less than 200
v1= 1-pnorm(200,mean = mean, sd = sd)
v1
[1] 0.1586553
Code
#bigger than 200 is same as less than 200

1.4.2 2

Code
v1= qnorm(0.9,mean = mean, sd = sd)
v1
[1] 201.999

1.4.3 3

Code
v1= rnorm(500,mean = mean, sd = sd)
data001=as.data.frame(v1)

ggplot001=ggplot(data001, aes(v1)) + geom_histogram()
ggplot001

2 Reference

https://www.youtube.com/watch?v=esskJJF8pCc

https://www.youtube.com/watch?v=q8baE17TAiU

https://www.youtube.com/watch?v=X5NXDK6AVtU