#Q1 Make a single plot that examines the association between radius_mean and radius_sd separately for each diagnosis (hint: aes() should have three arguments).
library(tidyverse)
── 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.0 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.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
Rows: 569 Columns: 31
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (1): diagnosis
dbl (30): radius_mean, texture_mean, perimeter_mean, area_mean, smoothness_m...
ℹ 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.
ggplot(biopsies, aes(x = radius_mean, y = radius_sd, color = diagnosis)) +geom_point() +labs(x ="Radius Mean", y ="Radius SD", color ="Diagnosis") +ggtitle("Association between Radius Mean and Radius SD by Diagnosis")
#Q2 Calculate the correlation between these two variables for each diagnosis.
# A tibble: 2 × 2
diagnosis correlation
<fct> <dbl>
1 B -0.0278
2 M 0.639
#Q3 Give at least a two-sentence interpretation of the results in the last two questions. In particular, comment on: “Is the relationship between radius_mean and radius_sd different for benign biopsies vs. malignant biopsies?” Yes “If so, can you give an explanation for this difference?” There is an upward drift observed in the plot for malignant biopsies, and the bigger the radius standard deviation is, the bigger the radius mean becomes. However, based on the plot, most benign biospies tend to have lower radius standard deviation and smaller variation of radius mean.
#Q4 Split the data set into a roughly 80-20 train-test set split.
#Q10 Is there any evidence that your model is overfitting? Explain in at least two sentences. Yes, because the misclassification rate on the testing data (9.23%) is higher than that on the training data (5.69%), indicating that the model may have learned the noise in the training data too well and is struggling to generalize to unseen data. This discrepancy suggests that the model’s performance might degrade when applied to new data.
#Q11 Move back to your simple model for the next few questions.Report the total number of false negatives in the test data set.
`summarise()` has grouped output by 'biopsies_test$diagnosis'. You can override
using the `.groups` argument.
# A tibble: 4 × 3
# Groups: biopsies_test$diagnosis [2]
`biopsies_test$diagnosis` test_predicted_classes n
<fct> <chr> <int>
1 B B 70
2 B M 10
3 M B 29
4 M M 21
#Q12 What can you change about your classification rule to lower the number of false negatives? To lower the number of false negatives, one approach is to adjust the classification threshold used to determine predictions. Decreasing the threshold increases the sensitivity of the model, making it more likely to classify malignant cases correctly.
#Q13 Make the change you identified in the previous question and calculate the new number of false negatives.
`summarise()` has grouped output by 'biopsies_test$diagnosis'. You can override
using the `.groups` argument.
# A tibble: 4 × 3
# Groups: biopsies_test$diagnosis [2]
`biopsies_test$diagnosis` test_predicted_classes n
<fct> <chr> <int>
1 B B 44
2 B M 36
3 M B 12
4 M M 38
There are 12 false negatives.
#Q14 Calculate the testing misclassification rate using your new classification rule.
#Q15 Did your misclassification rule go up or down? Answer this question and explain why it went up or down in at least two sentences.
It went up from 0.3 to 0.369. By lowering the threshold, we skew the error, which leads to a decrease in specificity, resulting in more false positives and, consequently, a higher misclassification rate. This occurs because the model becomes more liberal in classifying cases as positive, potentially increasing both true positives and false positives.