Built with datascienceportfol.io

HEALTH INSURANCE CHARGES DASHBOARD

Project photo

Project links

Skills

About this project

This report investigates the factors influencing health insurance charges in the
United States using the Health Insurance Dataset. The dataset contains information
on 1338 individuals, including personal attributes (age, gender, BMI, family size,
smoking habits), geographic factors, and medical insurance costs. The objective is
to understand how these features affect insurance costs and to develop predictive
models for estimating healthcare expenses.
Dataset Overview
The dataset includes the following variables:
• Age: The insured person's age (in years).
• Sex: Gender (male or female) of the insured.
• BMI (Body Mass Index): A measure of body fat based on height and
weight, ranging from 15.96 to 53.13.
• Children: The number of dependents covered, ranging from 0 to 5.
• Smoker: Whether the insured is a smoker (yes or no).
• Region: The geographic area of coverage (southeast, southwest, northeast,
northwest).
• Charges: The medical insurance costs incurred by the insured person (in
dollars).
Task 1: Visualizing Distributions and Summary Statistics
Age Distribution
Code
ggplot(health_data, aes(x = age)) + geom_histogram(fill = "light green", binwidth
= 5, color = "black") + ggtitle("Histogram visualization for the age variable of the
health insurance Data")

Interpretation: The age distribution shows that the dataset includes individuals
from 18 to 64 years, with the mean and median both around 39 years. This
indicates a fairly even distribution across the adult age range, with a slight

concentration in middle age. Such a distribution is beneficial for analyzing age-
related trends in insurance charges, as it provides a broad spectrum of age groups.

Sex Distribution
Code
ggplot(health_data, aes(x = sex, fill = sex)) + geom_bar(color = "black") +
scale_fill_manual(values = c(male = "seagreen", female = "pink", name = "sex"))
+ labs(x = "sex", y = "count", title = "Visualization showing the sex distribution")
+ theme_minimal()

Interpretation: The sex distribution visualized in the bar plot reveals the
proportion of males and females in the dataset. This is crucial for examining
potential gender-related differences in insurance charges. If there is a significant
disparity in charges between genders, it could indicate underlying factors such as
differing health risks or access to healthcare services.
BMI Distribution
Code
ggplot(health_data, aes(x = bmi)) + geom_histogram(fill = "light green", binwidth
= 5, color = "black") +
ggtitle("Histogram visualization for the BMI variable of the health data ")

Interpretation: The BMI distribution indicates a varied population in terms of
body weight, with the central tendency around 30.66, which is classified as
overweight. This suggests that many individuals in the dataset fall into categories
that may have higher associated health risks. Such information is vital as higher
BMI values can lead to increased medical expenses due to the higher likelihood of
weight-related health issues.
Children Distribution
Code
ggplot(health_data, aes(x = children, fill = children)) + geom_bar(fill =
"seagreen") + labs(x = "Number of Children", y = "Count", title = "Bar Chart
Visualization showing Children Distribution") + theme_minimal()

Interpretation: The number of children variable shows that most insured
individuals have few dependents, with the mean just above 1 and the median of 1.
This indicates that many people have no children, but having one or two children is
common. Analyzing the number of dependents is important as it can influence
insurance charges, with higher costs potentially associated with larger families.
Smoker Distribution
Code
ggplot(health_data, aes(x = smoker, fill = smoker)) + geom_bar() +
scale_fill_manual(values = c("yes" = "red", "no" = "seagreen")) + labs(x =
"smokers", y = "count", title = "Bar chart visualization showing smoker
distribution") + theme_minimal()

Interpretation: The smoker status, shown in the bar plot, highlights the proportion
of smokers versus non-smokers. Smoking is a significant risk factor for various
health conditions, influencing insurance costs. Identifying the prevalence of
smokers in the dataset is crucial for understanding how smoking habits impact
overall healthcare expenses.
Region Distribution
Code
ggplot(health_data, aes(x = region, fill = region)) + geom_bar(fill = "seagreen",
color = "black") + ggtitle("Bar chart visualization showing regional distribution")
+ xlab("Regions") + ylab("count")

Interpretation: The region distribution shows the geographic spread of the insured
individuals across four regions: southeast, southwest, northeast, and northwest.
This analysis helps understand regional cost differences due to varying medical
service prices, availability of healthcare facilities, and regional health behaviors.
Geographic factors can significantly impact insurance charges, and this
visualization provides insight into these regional variations.
Charges Distribution
Code
ggplot(health_data, aes(x = charges)) + geom_density(fill = "seagreen") + labs(x
= "charges", y = "density", title = "Density plot for medical charges") +
theme_minimal()

Interpretation: The charges distribution shows a wide range and right-skewed
distribution of insurance costs, indicating significant variability in healthcare
expenses among the insured. The mean charge is $13270, which is higher than the
median charge of $9382, suggesting that a few individuals incur very high charges,
skewing the average upward. This skewness highlights the presence of high-cost
cases that significantly impact the overall average.
DETAILED INTERPRETATION
Age
The age distribution indicates a balanced representation across the adult age range,
with a slight concentration in middle age (mean and median around 39 years). This
suggests that the dataset captures a broad spectrum of age-related healthcare costs.
Older individuals typically incur higher healthcare costs due to increased
susceptibility to chronic illnesses and age-related health issues. Analyzing the
relationship between age and insurance charges can help in understanding how
healthcare costs escalate with age.
Sex

The sex distribution shows the proportion of males and females in the dataset.
Gender can play a significant role in healthcare costs due to biological differences,
health behaviors, and access to healthcare services. For instance, certain health
conditions may be more prevalent in one gender, impacting insurance charges.
Analyzing gender-specific trends in insurance costs can provide insights into these
differences.
BMI
The BMI distribution indicates that a significant portion of the insured individuals
are overweight (mean BMI of 30.66). Higher BMI values are associated with
increased health risks such as cardiovascular diseases, diabetes, and hypertension,
leading to higher medical expenses. Understanding the impact of BMI on
insurance charges can help in identifying high-risk individuals and implementing
targeted health interventions to reduce costs.
Children
The distribution of the number of children shows that most insured individuals
have few dependents, with a mean of 1.095. The presence of dependents can
influence insurance charges as families with more children may have higher
healthcare needs and expenses. Analyzing the number of dependents helps in
understanding how family size affects insurance costs and can aid in designing
family-oriented insurance policies.
Smoker
The smoker status distribution reveals the proportion of smokers in the dataset.
Smoking is a major risk factor for numerous health conditions, leading to increased
medical costs. Understanding the prevalence of smokers in the dataset and their
impact on insurance charges is crucial for risk assessment and premium
calculation. Policies targeting smoking cessation can also be developed to reduce
healthcare costs.
Region
The region distribution shows the geographic spread of the insured individuals.
Geographic factors can significantly influence healthcare costs due to variations in
medical service prices, healthcare infrastructure, and regional health behaviors.
Analyzing regional differences in insurance charges can provide insights into how

location affects healthcare expenses and help in developing region-specific
healthcare policies.
Charges
The wide range and right-skewed distribution of insurance charges highlight the
variability in healthcare costs among the insured. The presence of high-cost cases
significantly impacts the average charge, indicating that some individuals incur
substantial medical expenses. Understanding the distribution of charges is crucial
for risk assessment and premium calculation. Identifying factors that contribute to
high medical costs can help in developing strategies to manage and reduce
healthcare expenses.
Conclusion
The analysis of the Health Insurance Dataset provides valuable insights into the
structure and distribution of various personal attributes, geographic factors, and
their impact on insurance charges. The visualizations and summary statistics lay
the groundwork for further analysis, such as regression modeling, to quantify the
relationships between these factors and insurance costs. By understanding these
relationships, predictive models can be developed to estimate healthcare expenses
based on personal and geographic attributes, aiding in risk assessment and
premium calculation.
Summary Statistics
Summary statistics for each variable were computed.
Code
summary_statistics <- summary(health_data)
summary_statistics

The summary statistics for the variables are as follows:
• Age:
o Range: 18 to 64 years
o Mean: 39.21 years
o Median: 39 years
o 1st Quartile (Q1): 27 years
o 3rd Quartile (Q3): 51 years
• Sex:
o Categories: Male, Female
o Proportion: Visualized in a bar plot
• BMI:
o Range: 15.96 to 53.13
o Mean: 30.66
o Median: 30.40
o 1st Quartile (Q1): 26.30
o 3rd Quartile (Q3): 34.69
• Children:
o Range: 0 to 5
o Mean: 1.095
o Median: 1
o 1st Quartile (Q1): 0
o 3rd Quartile (Q3): 2
• Smoker:
o Categories: Yes, No
o Proportion: Visualized in a bar plot
• Region:
o Categories: Southeast, Southwest, Northeast, Northwest
o Proportion: Visualized in a bar plot
• Charges:
o Range: $1122 to $63770
o Mean: $13270
o Median: $9382
o 1st Quartile (Q1): $4740
o 3rd Quartile (Q3): $16640

• Task 2: Now, test the assumption that all predictor variables are
independent using correlation coefficients or tests of associations.
Visualise your results using scatter plots and a correlation matrix.
A correlation matrix shows the correlation coefficients between pairs of
variables. The value of a correlation coefficient ranges from -1 to 1. Here’s
what these values represent:
• 1: Perfect positive correlation, meaning as one variable increases, the other
also increases.
• -1: Perfect negative correlation, meaning as one variable increases, the other
decreases.
• 0: No correlation, meaning there is no linear relationship between the
variables.
Detailed Explanation
Let's analyze the provided matrix:
Code
variables_correlation_matrix <- cor(health_data[, c("age", "bmi", "children",
"sex", "smoker", "region", "charges")])
variables_correlation_matrix

1. Age:
o age to age: 1.00 (perfect correlation, as expected since it's the same
variable).
o age to bmi: 0.109 (weak positive correlation).
o age to children: 0.042 (very weak positive correlation).
o age to sex: -0.021 (very weak negative correlation).
o age to smoker: -0.025 (very weak negative correlation).

o age to region: 0.002 (no correlation).
o age to charges: 0.299 (moderate positive correlation).
2. BMI (Body Mass Index):
o bmi to age: 0.109 (weak positive correlation).
o bmi to bmi: 1.00 (perfect correlation).
o bmi to children: 0.013 (very weak positive correlation).
o bmi to sex: 0.046 (very weak positive correlation).
o bmi to smoker: 0.004 (no correlation).
o bmi to region: 0.158 (weak positive correlation).
o bmi to charges: 0.198 (weak positive correlation).
3. Children:
o children to age: 0.042 (very weak positive correlation).
o children to bmi: 0.013 (very weak positive correlation).
o children to children: 1.00 (perfect correlation).
o children to sex: 0.017 (very weak positive correlation).
o children to smoker: 0.008 (no correlation).
o children to region: 0.017 (very weak positive correlation).
o children to charges: 0.068 (very weak positive correlation).
4. Sex:
o sex to age: -0.021 (very weak negative correlation).
o sex to bmi: 0.046 (very weak positive correlation).
o sex to children: 0.017 (very weak positive correlation).
o sex to sex: 1.00 (perfect correlation).
o sex to smoker: 0.076 (very weak positive correlation).
o sex to region: 0.005 (no correlation).
o sex to charges: 0.057 (very weak positive correlation).
5. Smoker:
o smoker to age: -0.025 (very weak negative correlation).
o smoker to bmi: 0.004 (no correlation).
o smoker to children: 0.008 (no correlation).
o smoker to sex: 0.076 (very weak positive correlation).
o smoker to smoker: 1.00 (perfect correlation).
o smoker to region: -0.002 (no correlation).
o smoker to charges: 0.787 (strong positive correlation).
6. Region:
o region to age: 0.002 (no correlation).
o region to bmi: 0.158 (weak positive correlation).
o region to children: 0.017 (very weak positive correlation).
o region to sex: 0.005 (no correlation).
o region to smoker: -0.002 (no correlation).

o region to region: 1.00 (perfect correlation).
o region to charges: -0.006 (no correlation).
7. Charges:
o charges to age: 0.299 (moderate positive correlation).
o charges to bmi: 0.198 (weak positive correlation).
o charges to children: 0.068 (very weak positive correlation).
o charges to sex: 0.057 (very weak positive correlation).
o charges to smoker: 0.787 (strong positive correlation).
o charges to region: -0.006 (no correlation).
o charges to charges: 1.00 (perfect correlation).

Key Insights:
1. Age and Charges:
o Moderate positive correlation (0.299). Older individuals tend to incur
higher charges.
2. BMI and Charges:
o Weak positive correlation (0.198). Higher BMI is associated with
higher charges, but the relationship is not strong.

3. Children and Charges:
o Very weak positive correlation (0.068). Having more dependents is
slightly associated with higher charges.

4. Sex and Charges:
o Very weak positive correlation (0.057). There is a slight tendency for
one gender to have higher charges, but it’s very minimal.

5. Smoker and Charges:
o Strong positive correlation (0.787). Being a smoker is strongly
associated with higher charges.

6. Region and Charges:
o No significant correlation (-0.006). The region does not significantly
impact charges.

Visualizations
The correlation matrix was visualized using the corrplot package.
Code
corrplot(variables_correlation_matrix, method = "color", addCoef.col = "black")

Understanding the Correlation Matrix
The image presents a correlation matrix, a visual representation of the relationships
between numerical variables. Each cell in the matrix displays the correlation
coefficient between two variables. The color intensity and shading indicate the
strength and direction of the correlation:
• Darker blue: Strong positive correlation (as one variable increases, the
other tends to increase)
• Lighter blue: Weak positive correlation
• White: No correlation
• Lighter red: Weak negative correlation (as one variable increases, the other
tends to decrease)
• Darker red: Strong negative correlation
Correlation between Charges and Other Variables
Let's focus on the last row of the matrix, which represents the correlations between
charges and the other variables:
• Age (0.3): There is a moderate positive correlation between age and charges.
As age increases, insurance charges tend to increase as well. This could be

attributed to factors like increased healthcare needs or risk associated with
aging.
• BMI (0.2): A weak positive correlation exists between BMI and charges.
Individuals with higher BMIs tend to have slightly higher insurance costs,
possibly due to a perceived higher risk of health issues associated with
obesity.
• Children (0.07): A very weak positive correlation is observed between the
number of children and charges. This suggests a minimal relationship, and
the presence of children has a negligible impact on insurance costs.
• Sex (0.06): A negligible correlation exists between sex and charges,
indicating that gender has little influence on insurance costs in this dataset.
• Smoker (0.79): A strong positive correlation is evident between smoker
status and charges. Individuals who smoke have significantly higher
insurance costs, likely due to the increased health risks associated with
smoking.
• Region (-0.01): There is virtually no correlation between region and
charges, suggesting that geographical location has minimal impact on
insurance costs in this dataset.
Additional Insights
• Among the predictor variables, age and smoker status exhibit the strongest
correlations with charges.
• BMI and the number of children have relatively weak relationships with
charges.
• Sex and region appear to have negligible or no impact on insurance costs.
Limitations
• This analysis is based solely on correlations, which measure the strength of
linear relationships between variables. It does not imply causation. Other
factors not included in this dataset could influence insurance charges.
• The correlation matrix does not provide information about the specific
nature of the relationships between variables. Further analysis, such as
regression modeling, would be necessary to understand the exact impact of
each variable on charges.
A scatter plot matrix was created to visualize the relationships between variables.
Code
pairs(~ age + bmi + sex + smoker + region + charges, data = health_data)

The image presents a matrix of scatter plots, where each cell represents the
relationship between two variables. The axes of each plot display the values of the
corresponding variables, and the dots represent individual data points.
Correlation between Charges and Other Variables
Let's focus on the last row of the matrix, which represents the relationships
between charges and the other variables:
• Age: The scatter plot shows a clear upward trend, indicating a positive
correlation between age and charges. As age increases, insurance charges
tend to increase as well. This could be attributed to factors like increased
healthcare needs or risk associated with aging.
• BMI: The scatter plot reveals a slight upward trend, suggesting a weak
positive correlation between BMI and charges. Individuals with higher BMIs
tend to have slightly higher insurance costs, possibly due to a perceived
higher risk of health issues associated with obesity.

• Sex: The scatter plot shows no clear pattern, indicating a negligible
correlation between sex and charges. Gender appears to have little influence
on insurance costs in this dataset.
• Smoker: The scatter plot exhibits a strong upward trend, signifying a strong
positive correlation between smoker status and charges. Individuals who
smoke have significantly higher insurance costs, likely due to the increased
health risks associated with smoking.
• Region: The scatter plot shows no clear pattern, suggesting a negligible
correlation between region and charges. Geographical location appears to
have minimal impact on insurance costs in this dataset.
Additional Insights
• Among the predictor variables, age and smoker status exhibit the strongest
correlations with charges, as evidenced by the steeper slopes in their
respective scatter plots.
• BMI shows a relatively weak relationship with charges, with a less
pronounced upward trend.
• Sex and region appear to have negligible or no impact on insurance costs, as
their scatter plots lack any discernible pattern.

Conclusion
Correlation between Charges and Predictor Variables
Based on the analysis of the correlation matrix and scatter plot matrix, it is
evident that several factors influence healthcare insurance charges.
• Age and smoker status emerge as the most significant predictors of
insurance costs. Older individuals and smokers tend to have substantially
higher charges.
• BMI exhibits a weak positive correlation with charges, suggesting that
weight is a contributing factor, albeit to a lesser extent.
• Number of children and sex have negligible impacts on insurance charges.
• Region also appears to have minimal influence on the cost of insurance.
It's important to note that correlation does not imply causation. While these
variables are associated with higher charges, other factors not included in the
dataset may also contribute to the variation in insurance costs. Further analysis,

such as regression modeling, could provide deeper insights into the relative
importance of each predictor and the underlying mechanisms driving the
relationships.
In summary, the data suggests that age and smoking habits are the primary drivers
of healthcare insurance charges in this dataset, while other factors have a more
limited impact.

Task 3: Using linear regression modelling. describe the variables which you
believe have influence on charge and describe your model with coefficients.
Note, you may consider other models beyond taught material which may be
more appropriate for modelling the outcome variable.
Model 1: Charges ~ smoker + age + bmi
Code
linear_regression_model1 <- lm(charges ~ smoker + age + bmi, data =
health_data) summary(linear_regression_model1)

• Model: Predicts charges based on smoker status, age, and BMI.
• Key Findings:

o All predictors (smoker, age, bmi) are highly significant (p-value < 2e-
16), indicating they strongly influence charges.

o The model explains 74.75% of the variability in charges (R-squared).
o The coefficients indicate that:

▪ Smokers have charges approximately $23,823 higher than non-
smokers, controlling for age and BMI.

▪ For each additional year of age, charges increase by about
$259.55, holding other variables constant.
▪ For each additional unit of BMI, charges increase by about
$322.62, controlling for smoker and age.

Model 2: Charges ~ smoker + age + bmi + sex + children + region
Code
linear_regression_model2 <- lm(charges ~ smoker + age + bmi + sex + children
+ region, data = health_data) summary(linear_regression_model2)

• Model: Includes all available predictors: smoker, age, bmi, sex, number of
children, and region.

• Key Findings:

o Smoker, age, bmi, and children are highly significant predictors (p-
value < 0.001).

o Sex and region are not significant predictors (p-value > 0.05).
o The model explains 75.07% of the variability in charges, a slight
improvement over Model 1.
o Adding sex and region to the model did not significantly improve the
overall fit.

Model 3: Charges ~ smoker + age + bmi + children + region
Code
linear_regression_model3 <- lm(charges ~ smoker + age + bmi + children +
region, data = health_data) summary(linear_regression_model3)

• Model: Similar to Model 2 but without the sex variable.
• Key Findings:
o The results are very similar to Model 2.
o Removing sex did not substantially change the model's performance.

Comparison and Conclusions
• Model 1 provides a strong baseline model with significant predictors
(smoker, age, bmi).

• Models 2 and 3 show that adding sex and region does not significantly
improve the model's predictive power.
• Smoker, age, and bmi are consistently strong predictors of charges across
all models.
• Children is also a significant predictor, but its impact is smaller compared
to smoker, age, and bmi.
Further Analysis
• Consider interactions: Explore if the effects of age, BMI, or smoking status
vary across different levels of other predictors.
• Transformations: Investigate if transforming variables (e.g., log
transformation for charges) improves model fit.

• Other predictors: Incorporate additional relevant variables (e.g., pre-
existing conditions, income) if available.

• Model validation: Assess the model's performance on a separate validation
dataset to evaluate its generalizability.
In conclusion, based on these models, smoker status, age, and BMI are the most
important factors influencing healthcare charges. While children also play a role,
sex and region appear to have limited impact. Further analysis can refine the model
and provide deeper insights into the factors driving healthcare costs.
Residuals and Fitted Values for Model 3
The residuals and fitted values for Model 3 were calculated.
Code
residuals_for_model3 <- data.frame(residuals = resid(linear_regression_model3),
Fitted = fitted(linear_regression_model3))
Residuals vs Fitted Plot
A plot was created for the residuals and fitted values for Model 3.
Code
ggplot(residuals_for_model3, aes(x = Fitted, y = residuals)) +
geom_point() +
geom_hline(yintercept = 0, linetype = "dashed", color = "seagreen") +
labs(title = "Residuals vs Fitted Plot", x = "Fitted values", y = "Residuals")

The Residuals vs Fitted plot is a diagnostic tool used in regression analysis to
assess the assumptions of the model and identify potential issues. It plots the
residuals (the difference between the actual and predicted values) against the fitted
values (the predicted values from the model).
Analysis of the Provided Plot
The plot shows a clear pattern in the residuals. We can observe the following:
1. Heteroscedasticity: The spread of the residuals is not constant across the
fitted values. As the fitted values increase, the spread of the residuals also
increases. This violates the assumption of homoscedasticity, which states
that the variance of the errors should be constant.
2. Non-linearity: There seems to be a slight curve or pattern in the residuals,
suggesting that the relationship between the dependent variable and the
independent variables might not be linear as assumed in the model.
Implications

• Heteroscedasticity: If the errors are not constant, the standard errors of the
coefficients will be incorrect, leading to unreliable hypothesis tests and
confidence intervals.
• Non-linearity: If the relationship is not linear, the model may not be
capturing the true relationship between the variables, leading to biased and
inefficient estimates.
Q-Q Plot for Residuals
A Q-Q plot was created for the residuals.
Code
ggplot(residuals_for_model3, aes(sample = residuals)) +
stat_qq() +
stat_qq_line() +
labs(title = "Q-Q plot of residuals", x = "Theoretical Quantiles", y = "Sample
Quantiles")

The provided Q-Q plot shows a clear deviation from the expected normal
distribution (the straight line). Here's a breakdown of the observations:
1. Non-Linearity: The points on the plot do not follow a straight line,
especially in the tails. This indicates that the residuals are not normally
distributed.
2. Heavy Tails: The plot shows that the tails of the distribution are heavier
than those of a normal distribution. This means there are more extreme
values (outliers) in the residuals than expected under normality.
Implications
• Non-Normality: The assumption of normally distributed residuals is a key
assumption in linear regression. When this assumption is violated, it can
affect the validity of hypothesis tests and confidence intervals.
• Outliers: The presence of outliers can influence the regression model,
potentially leading to biased results.
DASHBOARDS

Conclusion
This analysis provides insights into the factors influencing health insurance
charges. Visualizing the data and performing linear regression modeling helped
identify significant predictors such as smoking status, age, BMI, and geographic
region. The evaluation of model assumptions using residual plots and Q-Q plots
confirmed the adequacy of the linear regression models. Future work could involve
exploring more complex models or incorporating additional variables to enhance
predictive accuracy.