library(tidyverse)
## Warning: package 'purrr' was built under R version 4.4.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.0.4
## ── 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
library(dplyr)
library(ggplot2)
library(pastecs)
## Warning: package 'pastecs' was built under R version 4.4.3
##
## Attaching package: 'pastecs'
##
## The following objects are masked from 'package:dplyr':
##
## first, last
##
## The following object is masked from 'package:tidyr':
##
## extract
df <- read.csv("traffic_data.csv")
violfine <- df$ViolFine
stat.desc(violfine)
## nbr.val nbr.null nbr.na min max range
## 9.548000e+03 2.916000e+03 0.000000e+00 0.000000e+00 5.200000e+02 5.200000e+02
## sum median mean SE.mean CI.mean.0.95 var
## 9.099470e+05 9.800000e+01 9.530237e+01 8.284820e-01 1.624001e+00 6.553580e+03
## std.dev coef.var
## 8.095418e+01 8.494457e-01
df_clean <- df %>%
filter(!is.na(ViolFine))
ggplot(df_clean, aes(x = ViolFine)) +
geom_histogram(bins = 30, fill = "skyblue", color = "black") +
theme_minimal() +
labs(title = "Histogram of ViolFine (Original)", x = "Fine Amount", y = "Count")

df_clean <- df_clean %>%
mutate(LogFine = log(ViolFine + 1))
ggplot(df_clean, aes(x = LogFine)) +
geom_histogram(bins = 30, fill = "lightgreen", color = "black") +
theme_minimal() +
labs(title = "Histogram of ViolFine (Log Transformed)", x = "Log(Fine + 1)", y = "Count")
