1 + 1[1] 2
Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.
When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:
1 + 1[1] 2
You can add options to executable code like this
[1] 4
The echo: false option disables the printing of code (only output is displayed).
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
library(tidyr)
library(viridis)Loading required package: viridisLite
library(dplyr)fraud_detect<- read_csv("healthcare_fraud_detection-selected-columns-2.csv")Rows: 10000 Columns: 12
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (6): Provider_ID, Claim_ID, Patient_Gender, Diagnosis_Code, Insurance_T...
dbl (5): Patient_Age, Procedure_Code, Claim_Amount, Approved_Amount, Is_Fraud
date (1): Claim_Submission_Date
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(fraud_detect)# A tibble: 6 × 12
Provider_ID Claim_ID Patient_Age Patient_Gender Diagnosis_Code Procedure_Code
<chr> <chr> <dbl> <chr> <chr> <dbl>
1 P0052 C0000000 37 Male I25.10 36415
2 P0121 C0000001 21 Female E11.9 99213
3 P0140 C0000002 78 Female J06.9 93000
4 P0202 C0000003 65 Male I10 93000
5 P0135 C0000004 36 Male M54.5 85025
6 P0241 C0000005 44 Female E11.9 80053
# ℹ 6 more variables: Claim_Amount <dbl>, Approved_Amount <dbl>,
# Insurance_Type <chr>, Claim_Submission_Date <date>, Patient_State <chr>,
# Is_Fraud <dbl>
nrow(fraud_detect)[1] 10000
min(fraud_detect$Approved_Amount)[1] 50.35
max(fraud_detect$Approved_Amount)[1] 4270.89
min(fraud_detect$Claim_Amount)[1] 60.21
max(fraud_detect$Claim_Amount)[1] 6590.7
PublicIns <- fraud_detect |>
filter(
Patient_State == "IL",
Approved_Amount >= 100,
Approved_Amount <= 500) |>
arrange(Claim_Submission_Date)ggplot(fraud_detect, aes(x=Claim_Amount, y=Approved_Amount)) +
geom_point()ggplot(data = fraud_detect) +
stat_summary(
mapping = aes(x = Claim_Amount, y = Approved_Amount),
fun.min = min,
fun.max = max,
fun = median
)p1 <- fraud_detect |>
ggplot(aes(x=Claim_Amount, fill=Insurance_Type)) +
geom_histogram(position="identity")+
scale_fill_discrete(name = "Insurance_Type",
labels = c("Self-Pay", "Medicaid","Medicare", "Private")) +
labs(x = "Claim Amounts",
y = "Frequency of Claims",
title = "Histogram of Claim Amounts",
caption = "Fraud Simulation")
p1`stat_bin()` using `bins = 30`. Pick better value `binwidth`.
p2 <- fraud_detect |>
ggplot(aes(Insurance_Type, Claim_Amount, fill = Insurance_Type)) +
labs(x = "Insurance Type", y = "Claim Amount",
title = "Side-by-Side Boxplot of Claim Amount",
caption = "Kaggle Fraud Simulation Data") +
geom_boxplot()+
scale_fill_grey(name = "Insurance_Type",
labels = c("Self-Pay", "Medicaid","Medicare", "Private"))
p2ggplot(data = fraud_detect) +
geom_bar(aes(x = Insurance_Type, fill = Patient_Gender), position = "stack") +
labs(x = "Insurance Type", y = "Frequency",
title = "Stacked Bar Graph of Insurance Type by Gender")ggplot(data = PublicIns) +
geom_bar(aes(x = Insurance_Type, fill = Patient_Gender), position = "stack") +
labs(x = "Insurance Type", y = "Frequency",
title = "Stacked Bar Graph of Insurance Type by Gender in Illinois")p5 <- PublicIns |>
ggplot(aes(Insurance_Type, Claim_Amount, fill = Insurance_Type)) +
labs(x = "Insurance Type", y = "Claim Amount",
title = "Side-by-Side Boxplot of Claim Amount",
caption = "Kaggle Fraud Simulation Data") +
geom_boxplot()+
scale_fill_grey(name = "Insurance_Type",
labels = c("Self-Pay", "Medicaid","Medicare", "Private"))
p5