Code
library(ggplot2)
library(tidyverse)Tony Duan
November 28, 2023
mean 0 and standard deviation 1 Normal distribution is call standard normal distribution



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

https://www.youtube.com/watch?v=esskJJF8pCc
https://www.youtube.com/watch?v=q8baE17TAiU
https://www.youtube.com/watch?v=X5NXDK6AVtU
---
title: "Distribution"
subtitle: "distribution in R"
author: "Tony Duan"
date: "2023-11-28"
image: "https://www.nlm.nih.gov/oet/ed/stats/img/Distribution_14.png"
categories: [R]
execute:
warning: false
error: false
format:
html:
toc: true
toc-location: left
code-fold: show
code-tools: true
number-sections: true
code-block-bg: true
code-block-border-left: "#31BAE9"
---
```{r}
library(ggplot2)
library(tidyverse)
```
# Normal distribution or Gaussian distribution
## 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
{width="800"}
## Same R function for Normal distribution
{width="800"}
{width="800"}
### rnorm() Random number generator
create 1000 number from Normal distribution with mean 0 and standard deviation 1
```{r}
v1= rnorm(1000,mean = 0, sd = 1)
data001=as.data.frame(v1)
ggplot001=ggplot(data001, aes(v1)) + geom_histogram()
ggplot001
```
### pnorm() Cumulatatie probability distribution
the cumulative probability <1 from Normal distribution with mean 0 and standard deviation 1
```{r}
v1= pnorm(1,mean = 0, sd = 1)
v1
```
## qnorm() Quantile distribution(reverse pnorm)
the number from cumulative probability<0.8413447 from Normal distribution with mean 0 and standard deviation 1
```{r}
v1= qnorm(0.8413447,mean = 0, sd = 1)
v1
```
## example
{width="700"}
Flipper lengths of a certain kind of penguin are normally distributed with mean 192.9 mm and standard deviation 7.1 mm.
```{r}
mean = 192.9
sd = 7.1
```
### What is the probability that a randomly-selected penguin has a flipper less than 200 mm long? More than 200 mm?
```{r}
#less than 200
v1= 1-pnorm(200,mean = mean, sd = sd)
v1
#bigger than 200 is same as less than 200
```
### What is the 90th percentile for flippers length in these penguins?
```{r}
v1= qnorm(0.9,mean = mean, sd = sd)
v1
```
### Simulate 500 random selections from this population and plot the results.
```{r}
v1= rnorm(500,mean = mean, sd = sd)
data001=as.data.frame(v1)
ggplot001=ggplot(data001, aes(v1)) + geom_histogram()
ggplot001
```
# Reference
https://www.youtube.com/watch?v=esskJJF8pCc
https://www.youtube.com/watch?v=q8baE17TAiU
https://www.youtube.com/watch?v=X5NXDK6AVtU