knitr::opts_chunk$set(echo=FALSE)
library(dslabs)
library(ggplot2)

Research Question

How do mean radius and mean texture measurements differ between benign and malignant breast tumors, and which of the two variables shows a clearer distinction between the tumor classes?

Specific Objectives

  1. To examine the distribution of benign and malignant tumor cases in the dataset.
  2. To explore the distributions of mean radius and mean texture measurements.
  3. To compare mean radius and mean texture measurements across benign and malignant tumor classes.
  4. To identify which of the two variables demonstrates a clearer distinction between the tumor classifications.

Step 1: The Data

Dataset Description

The data set used in this analysis is the Breast Cancer Wisconsin Diagnostic data set (brca), which is commonly used for medical classification tasks.

The data set contains 569 observations and 31 variables. Each observation represents measurements taken from a digitized image of a breast mass.

The variables describe characteristics of cell nuclei, such as size, texture, and shape.

The outcome variable is:

Class:

B = Benign (non-cancerous) M = Malignant (cancerous)

Understanding this outcome is important because early detection of malignant tumors can significantly improve treatment outcomes and survival rates.

Data Source:The data set was obtained from the dslabs data set object brca.

Data Preparation and Structure

The original data set is stored as a list containing:

  • x: numeric feature matrix (measurements)

  • y: classification labels

To make the data set suitable for analysis, it was converted into a structured data frame:

data(brca)
breast_cancer <- as.data.frame(brca$x)
breast_cancer$Class <- as.factor(brca$y)
class(breast_cancer)
## [1] "data.frame"
names(breast_cancer)
##  [1] "radius_mean"       "texture_mean"      "perimeter_mean"   
##  [4] "area_mean"         "smoothness_mean"   "compactness_mean" 
##  [7] "concavity_mean"    "concave_pts_mean"  "symmetry_mean"    
## [10] "fractal_dim_mean"  "radius_se"         "texture_se"       
## [13] "perimeter_se"      "area_se"           "smoothness_se"    
## [16] "compactness_se"    "concavity_se"      "concave_pts_se"   
## [19] "symmetry_se"       "fractal_dim_se"    "radius_worst"     
## [22] "texture_worst"     "perimeter_worst"   "area_worst"       
## [25] "smoothness_worst"  "compactness_worst" "concavity_worst"  
## [28] "concave_pts_worst" "symmetry_worst"    "fractal_dim_worst"
## [31] "Class"
summary(breast_cancer)
##   radius_mean      texture_mean   perimeter_mean     area_mean     
##  Min.   : 6.981   Min.   : 9.71   Min.   : 43.79   Min.   : 143.5  
##  1st Qu.:11.700   1st Qu.:16.17   1st Qu.: 75.17   1st Qu.: 420.3  
##  Median :13.370   Median :18.84   Median : 86.24   Median : 551.1  
##  Mean   :14.127   Mean   :19.29   Mean   : 91.97   Mean   : 654.9  
##  3rd Qu.:15.780   3rd Qu.:21.80   3rd Qu.:104.10   3rd Qu.: 782.7  
##  Max.   :28.110   Max.   :39.28   Max.   :188.50   Max.   :2501.0  
##  smoothness_mean   compactness_mean  concavity_mean    concave_pts_mean 
##  Min.   :0.05263   Min.   :0.01938   Min.   :0.00000   Min.   :0.00000  
##  1st Qu.:0.08637   1st Qu.:0.06492   1st Qu.:0.02956   1st Qu.:0.02031  
##  Median :0.09587   Median :0.09263   Median :0.06154   Median :0.03350  
##  Mean   :0.09636   Mean   :0.10434   Mean   :0.08880   Mean   :0.04892  
##  3rd Qu.:0.10530   3rd Qu.:0.13040   3rd Qu.:0.13070   3rd Qu.:0.07400  
##  Max.   :0.16340   Max.   :0.34540   Max.   :0.42680   Max.   :0.20120  
##  symmetry_mean    fractal_dim_mean    radius_se        texture_se    
##  Min.   :0.1060   Min.   :0.04996   Min.   :0.1115   Min.   :0.3602  
##  1st Qu.:0.1619   1st Qu.:0.05770   1st Qu.:0.2324   1st Qu.:0.8339  
##  Median :0.1792   Median :0.06154   Median :0.3242   Median :1.1080  
##  Mean   :0.1812   Mean   :0.06280   Mean   :0.4052   Mean   :1.2169  
##  3rd Qu.:0.1957   3rd Qu.:0.06612   3rd Qu.:0.4789   3rd Qu.:1.4740  
##  Max.   :0.3040   Max.   :0.09744   Max.   :2.8730   Max.   :4.8850  
##   perimeter_se       area_se        smoothness_se      compactness_se    
##  Min.   : 0.757   Min.   :  6.802   Min.   :0.001713   Min.   :0.002252  
##  1st Qu.: 1.606   1st Qu.: 17.850   1st Qu.:0.005169   1st Qu.:0.013080  
##  Median : 2.287   Median : 24.530   Median :0.006380   Median :0.020450  
##  Mean   : 2.866   Mean   : 40.337   Mean   :0.007041   Mean   :0.025478  
##  3rd Qu.: 3.357   3rd Qu.: 45.190   3rd Qu.:0.008146   3rd Qu.:0.032450  
##  Max.   :21.980   Max.   :542.200   Max.   :0.031130   Max.   :0.135400  
##   concavity_se     concave_pts_se      symmetry_se       fractal_dim_se     
##  Min.   :0.00000   Min.   :0.000000   Min.   :0.007882   Min.   :0.0008948  
##  1st Qu.:0.01509   1st Qu.:0.007638   1st Qu.:0.015160   1st Qu.:0.0022480  
##  Median :0.02589   Median :0.010930   Median :0.018730   Median :0.0031870  
##  Mean   :0.03189   Mean   :0.011796   Mean   :0.020542   Mean   :0.0037949  
##  3rd Qu.:0.04205   3rd Qu.:0.014710   3rd Qu.:0.023480   3rd Qu.:0.0045580  
##  Max.   :0.39600   Max.   :0.052790   Max.   :0.078950   Max.   :0.0298400  
##   radius_worst   texture_worst   perimeter_worst    area_worst    
##  Min.   : 7.93   Min.   :12.02   Min.   : 50.41   Min.   : 185.2  
##  1st Qu.:13.01   1st Qu.:21.08   1st Qu.: 84.11   1st Qu.: 515.3  
##  Median :14.97   Median :25.41   Median : 97.66   Median : 686.5  
##  Mean   :16.27   Mean   :25.68   Mean   :107.26   Mean   : 880.6  
##  3rd Qu.:18.79   3rd Qu.:29.72   3rd Qu.:125.40   3rd Qu.:1084.0  
##  Max.   :36.04   Max.   :49.54   Max.   :251.20   Max.   :4254.0  
##  smoothness_worst  compactness_worst concavity_worst  concave_pts_worst
##  Min.   :0.07117   Min.   :0.02729   Min.   :0.0000   Min.   :0.00000  
##  1st Qu.:0.11660   1st Qu.:0.14720   1st Qu.:0.1145   1st Qu.:0.06493  
##  Median :0.13130   Median :0.21190   Median :0.2267   Median :0.09993  
##  Mean   :0.13237   Mean   :0.25427   Mean   :0.2722   Mean   :0.11461  
##  3rd Qu.:0.14600   3rd Qu.:0.33910   3rd Qu.:0.3829   3rd Qu.:0.16140  
##  Max.   :0.22260   Max.   :1.05800   Max.   :1.2520   Max.   :0.29100  
##  symmetry_worst   fractal_dim_worst Class  
##  Min.   :0.1565   Min.   :0.05504   B:357  
##  1st Qu.:0.2504   1st Qu.:0.07146   M:212  
##  Median :0.2822   Median :0.08004          
##  Mean   :0.2901   Mean   :0.08395          
##  3rd Qu.:0.3179   3rd Qu.:0.09208          
##  Max.   :0.6638   Max.   :0.20750
str(breast_cancer)
## 'data.frame':    569 obs. of  31 variables:
##  $ radius_mean      : num  13.5 13.1 9.5 13 8.2 ...
##  $ texture_mean     : num  14.4 15.7 12.4 18.4 16.8 ...
##  $ perimeter_mean   : num  87.5 85.6 60.3 82.6 51.7 ...
##  $ area_mean        : num  566 520 274 524 202 ...
##  $ smoothness_mean  : num  0.0978 0.1075 0.1024 0.0898 0.086 ...
##  $ compactness_mean : num  0.0813 0.127 0.0649 0.0377 0.0594 ...
##  $ concavity_mean   : num  0.0666 0.0457 0.0296 0.0256 0.0159 ...
##  $ concave_pts_mean : num  0.04781 0.0311 0.02076 0.02923 0.00592 ...
##  $ symmetry_mean    : num  0.188 0.197 0.181 0.147 0.177 ...
##  $ fractal_dim_mean : num  0.0577 0.0681 0.069 0.0586 0.065 ...
##  $ radius_se        : num  0.27 0.185 0.277 0.184 0.156 ...
##  $ texture_se       : num  0.789 0.748 0.977 2.342 0.957 ...
##  $ perimeter_se     : num  2.06 1.38 1.91 1.17 1.09 ...
##  $ area_se          : num  23.56 14.67 15.7 14.16 8.21 ...
##  $ smoothness_se    : num  0.00846 0.0041 0.00961 0.00435 0.00897 ...
##  $ compactness_se   : num  0.0146 0.019 0.0143 0.0049 0.0165 ...
##  $ concavity_se     : num  0.0239 0.017 0.0198 0.0134 0.0159 ...
##  $ concave_pts_se   : num  0.01315 0.00649 0.01421 0.01164 0.00592 ...
##  $ symmetry_se      : num  0.0198 0.0168 0.0203 0.0267 0.0257 ...
##  $ fractal_dim_se   : num  0.0023 0.00243 0.00297 0.00178 0.00258 ...
##  $ radius_worst     : num  15.11 14.5 10.23 13.3 8.96 ...
##  $ texture_worst    : num  19.3 20.5 15.7 22.8 22 ...
##  $ perimeter_worst  : num  99.7 96.1 65.1 84.5 57.3 ...
##  $ area_worst       : num  711 630 315 546 242 ...
##  $ smoothness_worst : num  0.144 0.131 0.132 0.097 0.13 ...
##  $ compactness_worst: num  0.1773 0.2776 0.1148 0.0462 0.1357 ...
##  $ concavity_worst  : num  0.239 0.189 0.0887 0.0483 0.0688 ...
##  $ concave_pts_worst: num  0.1288 0.0728 0.0623 0.0501 0.0256 ...
##  $ symmetry_worst   : num  0.298 0.318 0.245 0.199 0.31 ...
##  $ fractal_dim_worst: num  0.0726 0.0818 0.0777 0.0617 0.0741 ...
##  $ Class            : Factor w/ 2 levels "B","M": 1 1 1 1 1 1 1 1 1 1 ...
sum(is.na(breast_cancer))
## [1] 0

There were no missing data, this step ensures the data is in a format suitable for statistical analysis and visualization.

Step 2: Data Health

Choice of Variables

Two explanatory variables were selected:

  • radius_mean (average size of the cell nucleus)

  • texture_mean (variation in cell texture)

These variables are relevant because cancerous cells often differ in size and texture compared to normal cells.

2.1 Outcome Variable Distribution

ggplot(breast_cancer, aes(x = Class)) +
  geom_bar(fill = "steelblue") +
  labs(title = "Distribution of Tumor Classes",
       x = "Class (B = Benign, M = Malignant)",
       y = "Count")

Interpretation:

The bar chart shows that benign (B) tumors have a count of approximately 357, while malignant (M) tumors have a count of approximately 212. Benign cases are clearly more frequent in this data set than malignant ones.This is common in medical data sets and may affect model balance.

2.2 Distribution of Radius Mean

ggplot(breast_cancer, aes(x = radius_mean)) +
  geom_histogram(bins = 30, fill = "darkgreen", 
                 color = "white") + theme_classic()+
  labs(title = "Distribution of Radius Mean",
       x = "Radius Mean",
       y = "Frequency")

Interpretation:

The histogram depicts the distribution of radius mean values across the data set. The distribution exhibits a right-skewed pattern, with the highest frequency of observations concentrated between radius mean values of 12 and 14, reaching a peak frequency of approximately 65 to 67.

The distribution gradually tapers toward the right, with values extending as far as 28, suggesting the presence of tumors with considerably larger radius measurements at the upper end of the data set.

2.3 Distribution of Texture Mean

ggplot(breast_cancer, aes(x = texture_mean)) +
  geom_histogram(bins = 30, fill = "purple", color = "white") +
  labs(title = "Distribution of Texture Mean",
       x = "Texture Mean",
       y = "Frequency")

Interpretation:

The histogram illustrates the distribution of texture mean values across the data set. The distribution follows a relatively bell-shaped pattern, centered around values of 18 to 20, with peak frequencies reaching approximately 53 to 55. A slight right skew is observed, with values extending toward 40, indicating the presence of a small number of cases with notably higher texture mean measurements.

Step 3: Relationship Between Variables and Outcome

3.1 Radius Mean vs Class

ggplot(breast_cancer, aes(x = Class, y = radius_mean, fill = Class)) +
  geom_boxplot() +
  labs(title = "Radius Mean by Tumor Class",
       x = "Class",
       y = "Radius Mean")

Interpretation:

The boxplot presents a comparison of radius mean values between benign (B) and malignant (M) tumor classes. Benign tumors recorded a median radius mean of approximately 12, while malignant tumors recorded a notably higher median of approximately 17 to 18.

The boxes show minimal overlap, with the malignant group displaying a wider interquartile range, and a few outliers are visible above the benign group at approximately 17 and below at approximately 9. This clear separation suggests that radius mean is a highly effective feature in distinguishing between benign and malignant tumors.

3.2 Texture Mean vs Class

ggplot(breast_cancer, aes(x = Class, y = texture_mean, fill = Class)) +
  geom_boxplot() +
  labs(title = "Texture Mean by Tumor Class",
       x = "Class",
       y = "Texture Mean")

Interpretation:

The boxplot illustrates the comparison of texture mean values between benign and malignant tumor classes. Benign tumors recorded a median texture mean of approximately 18, while malignant tumors recorded a higher median of approximately 22 to 23.

Several outliers are visible in both classes, particularly in the benign group where values extend toward 30 and beyond. The considerable overlap between the interquartile ranges of both classes indicates that texture mean alone possesses limited discriminatory power in differentiating between the two tumor classifications.

Limitations of the Analysis

Conclusion

Based on the exploratory data analysis conducted, radius mean demonstrated a clearer distinction between the two tumor classes between benign and malignant tumors, as evidenced by the clear separation observed in the boxplot with minimal overlap between the two classes. Texture mean, while showing some differential between classes, exhibited considerable overlap, limiting its discriminatory power as a standalone feature.

The data set reflects an imbalance between tumor classes, with benign cases outnumbering malignant cases. This observation should be taken into consideration in any subsequent classification or predictive modeling.

Overall, the findings suggest that radius mean is a more reliable feature in differentiating tumor classifications, and both features should ideally be used in conjunction with additional variables to strengthen analytical outcomes.