1. Setting Up R

Ensure R is installed on your computer. You can download it from CRAN or use RStudio for a more user-friendly interface.


2. Basic Functions: dnorm() and pnorm()

a) dnorm(): Probability Density Function (PDF)

The dnorm() function calculates the probability density at a specific value for a normal distribution.

# Example using dnorm()
dnorm(0)  # Probability density at x = 0

b) pnorm(): Cumulative Distribution Function (CDF)

The pnorm() function calculates the cumulative probability up to a specific value.

# Example using pnorm()
pnorm(1)  # Cumulative probability up to x = 1

3. Exploring Normal Distribution with dnorm() and pnorm()

a) Using dnorm() with Different Parameters

# Normal distribution with mean = 5, sd = 2
dnorm(5, mean = 5, sd = 2)  # Probability density at x = 5

b) Using pnorm() with Different Parameters

# Cumulative probability with mean = 5, sd = 2
pnorm(6, mean = 5, sd = 2)  # Cumulative probability up to x = 6

4. Visualizing Normal Distribution

Using ggplot2, we can visualize the normal distribution.

library(ggplot2)

# Create a data frame for normal distribution
x <- seq(-4, 8, length = 100)
y <- dnorm(x, mean = 5, sd = 2)

# Plot
ggplot(data = data.frame(x, y), aes(x = x, y = y)) +
  geom_line() +
  labs(title = "Normal Distribution (mean = 5, sd = 2)", x = "x", y = "Density") +
  theme_minimal()

5. Other Common Distributions

Besides normal distribution, other distributions include binomial, Poisson, and exponential distributions. Let’s explore the binomial distribution:

a) Using dbinom() for Binomial Distribution

# Binomial distribution
dbinom(3, size = 10, prob = 0.5)  # Probability of 3 successes in 10 trials

b) Using pnorm() for Binomial Distribution

# Cumulative probability for binomial
pnorm(3, mean = 5, sd = 2)  # Probability up to 3 successes