4.1

#2f
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.2.0
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.3     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
f.y <- function(y) {
  pdf <- ifelse(y <= 1, 0, 4/y^5)
  return(pdf)
}

F.y <- function(y) {
  CDF <- case_when(y <= 1 ~ 0,
                   y > 1 ~ 1 - 1/y^4)
  return(CDF)
}

(data <- data.frame(y = seq(0, 5, length = 300))
  %>% mutate(f = f.y(y), F = F.y(y))
) %>% head
           y f F
1 0.00000000 0 0
2 0.01672241 0 0
3 0.03344482 0 0
4 0.05016722 0 0
5 0.06688963 0 0
6 0.08361204 0 0
(ggplot(data = data)
  + geom_line(aes(x = y, y = f))
  + theme_classic(base_size = 14)
)

(ggplot(data = data)
  + geom_line(aes(x = y, y = F))
  + theme_classic(base_size = 14)
)

#3e
library(tidyverse)

f.y <- function(y) {
  pdf <- 1/(pi*(1 + y^2))
  return(pdf)
}

F.y <- function(y) {
  CDF <- 1/2 + atan(y)/pi
  return(CDF)
}

(data <- data.frame(y = seq(-10, 10, length = 500))
  %>% mutate(f = f.y(y), F = F.y(y))
) %>% head
           y           f          F
1 -10.000000 0.003151583 0.03172552
2  -9.959920 0.003176745 0.03185234
3  -9.919840 0.003202209 0.03198017
4  -9.879760 0.003227979 0.03210903
5  -9.839679 0.003254060 0.03223893
6  -9.799599 0.003280458 0.03236988
(ggplot(data = data)
  + geom_line(aes(x = y, y = f))
  + theme_classic(base_size = 14)
)

(ggplot(data = data)
  + geom_line(aes(x = y, y = F))
  + theme_classic(base_size = 14)
)