Question 1:
The data set appears to have 1338 observations and 7 total variables.
## age sex bmi children smoker region charges
## 1 19 female 27.900 0 yes southwest 16884.924
## 2 18 male 33.770 1 no southeast 1725.552
## 3 28 male 33.000 3 no southeast 4449.462
## 4 33 male 22.705 0 no northwest 21984.471
## 5 32 male 28.880 0 no northwest 3866.855
## 6 31 female 25.740 0 no southeast 3756.622
The variables we will be using are “bmi” and “charges” as our x and y variables respectively for this project.
Question 2:
There does seem to be a positive correlation in the data, but it doesn’t seem particularly strong. It’s scattered all over the bottom of the graph, but the higher charges do seem to correlate with higher BMI values.
A straight-line regression model might help to see more patterns in the data.
Question 3:
ggplot(data, aes(x = bmi, y = charges)) +
geom_point(size = .8) +
geom_smooth(method = "lm", formula = y ~ x, se = TRUE) +
theme_grey()## (Intercept) bmi
## 1192.937 393.873
##
## Call:
## lm(formula = charges ~ bmi, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -20956 -8118 -3757 4722 49442
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1192.94 1664.80 0.717 0.474
## bmi 393.87 53.25 7.397 2.46e-13 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 11870 on 1336 degrees of freedom
## Multiple R-squared: 0.03934, Adjusted R-squared: 0.03862
## F-statistic: 54.71 on 1 and 1336 DF, p-value: 2.459e-13
Amount Paid = 1192.94 + 393.87x
The estimated slope is approximately 393.87. In this data set, it means for a 1 unit increase in BMI, we can expect the cost of care to increase by $393.87.
The y-intercept is 1192.94. This is meaningful as it means that we can expect the cost of care to start at $1192.94 no matter the BMI. This is a consistent starting point for all charges in this dataset - though a BMI of zero, as the y-intercept would suggest, is not physically possible.
Question 4:
When examining the summary statistics from the last step, we were provided with a p value of 2.46e-13. In standard decimal form, this is a decimal with 12 zeroes between the decimal point and the first non-zero digit, which is to say, it is minuscule.
When compared with an alpha level of .05, we can safely reject the null hypothesis. There is statistically significant evidence at the .05 alpha level to conclude that BMI significantly contributes to the straight-line prediction of the cost of care. This is to say, the slope of the line is significantly different from zero.
In the context of this data set, we can conclude that a higher BMI is in fact associated with a higher cost of care for patients.
Question 5:
When examining the summary statistics from step 3, we were provided the “Multiple R-squared” value of .03934. This leads us to a sample correlation coefficient of roughly .198. This value indicates a very weak positive linear relationship between the patient’s BMI and cost of care. Our r-squared value of .03934 indicates that only 3.93% of the variation in hospital care can be explained by a patient’s BMI. The remaining variation can be assumed to be due to other causes such as age, treatments received, or being a smoker, though these causes are not the only potential causes of variation.
Question 6:
##
## Pearson's product-moment correlation
##
## data: data$bmi and data$charges
## t = 7.3966, df = 1336, p-value = 2.459e-13
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.1463052 0.2492822
## sample estimates:
## cor
## 0.198341
Upon finding our confidence interval, we have found that the confidence interval is [.1463052, .2492822]. That is to say, we are 95% confident that the true population correlation coefficient between a patient’s BMI and their cost of care is between .1463052 and .2492822. This confidence interval agrees with our conclusion from Question 4 as our confidence interval does not include zero.
Question 7:
Upon viewing our diagnostic plots, we can come to a few conclusions about our regression diagnostics.
- Existence - Reasonable/Met
For any value of BMI, there is a cost of care associated with it. The data exists and has measurable values. As we have 1338 observations of patients, this assumption is met.
- Independence - Reasonable/Met
Because these points are individual patients, one patient’s cost does not influence the cost of another patient’s care. Each observation is an independent patient that does not have their total cost of care impacted by another individual’s cost of care.
- Linearity - Reasonable
Based on the Residuals vs Fitted plot, we can conclude that linearity is reasonable. The plot follows a linear trend up until the end where points become sparse. From this, we can conclude that linearity is not violated.
- Homoscedasticity - Violated
The line in the Scale-Location plot climbs from left to right, implying that the average size of errors grows larger as predicted cost increases. We can also see that points fan out much further on the right than they do on the left, which is much more tightly clustered. This is to say, heteroscedasticity is present in this data.
- Normality - Violated
At the end of our Q-Q Residuals plot, values skew violently away from the line, indicating a heavy right-skew in the data, or incredibly high costs for some patients that do not fit our initial assumptions of how quickly cost should rise based on BMI.
Question 8:
Upon examining the violations in the previous question, I will attempt to address the heteroscedasticity and non-normality found in the previous model. This is to say, I will be addressing the non-constant variance and right-skew. To do this, I will be considering and reviewing a natural log transformation of the cost of care. Taking the log of this variable should pull the extreme variables closer to the mean and lead to more normality in the residuals. While this is a very small change, it should be enough to address the issues without simply cleaning the data of the worst of the outliers and getting rid of potentially valuable data.
##
## Call:
## lm(formula = log(charges) ~ bmi, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.48894 -0.63536 0.03136 0.68007 1.95182
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 8.485243 0.127833 66.378 < 2e-16 ***
## bmi 0.020005 0.004089 4.892 1.12e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.9117 on 1336 degrees of freedom
## Multiple R-squared: 0.0176, Adjusted R-squared: 0.01687
## F-statistic: 23.94 on 1 and 1336 DF, p-value: 1.117e-06
Upon examining the new plots, we can see that the Q-Q Residuals plot hugs the line much closer, and the Scale-Location plot has flattened out significantly. The Residuals vs Fitted plot continues to support linearity, though it hugs much closer to the horizontal zero line than it did before. These changes have significantly improved upon the previous model’s shortcomings.
Question 9:
q9data <- data.frame(bmi = 25)
prediction1 <- predict(model2, newdata = q9data, interval = "prediction", level = .95)
head(prediction1)## fit lwr upr
## 1 8.985364 7.195521 10.77521
## fit lwr upr
## 1 7985.347 1333.445 47820.32
We can predict, based on these findings, that the cost of treatment for someone with a BMI of 25 would be roughly $7985.35. The model we used had been transformed using log, and thus was generated on the logarithmic scale \[ \widehat{(log(Cost))}\approx 8.985 \] When transformed back, we simply exponentiated the value. \[ \widehat{Cost} = exp(8.985) = $7985.35 \]
The 95% prediction for one individual was also impacted by the fact we transformed our previous model. When back-transformed to the original scale, we found that the costs for this patient should be within $1333.45 and $47820.32
When we interpret these findings with context, our model concludes that their medical charges should be roughly $7985.35. We are also 95% confident that any charges will fall within the interval of $1333.45 and $47820.32.
Question 10:
The objective of this study was to determine if BMI was a reasonable determinant of patient cost in a hospital setting. The data set was comprised of roughly 1.3k observations each independent of the others.
The initial model which used simple linear regression indicated a highly statistically significant positive relationship between BMI and cost, residual plots revealed issues with normality and variance due to a heavy right-skew in the data attributed to high medical costs.
To improve the model, a natural logarithmic transformation was applied to the model. The model corrected the previously mentioned violations and reaffirmed the initial findings that BMI is a statistically significant but weak predictor, explaining approximately 3.93% of variation in medical charges.
To test the model, we proceeded to test the findings on a fictional individual with a BMI of 25. When examined and back-transformed, we found that the results made logical sense, and that the model predicted an individual with a BMI of 25 would come out of the hospital with an average cost of $7985.35.
The 95% prediction interval for the potential costs, however, is incredibly wide, ranging from $1333.45 to $47.829.32. This, however, is reasonable, considering the fact we determined that BMI as a factor is only accountable for 4% of the change in cost. All the other factors lead to a much wider prediction interval overall. It would be interesting, for example, to see the impact of being a smoker or a non-smoker, as being a smoker in and of itself would imply a higher cost overall.