Το Dataset Ασφάλισης περιλαμβάνει δεδομένα που σχετίζονται με το κόστος ασφάλισης υγείας για άτομα στις Ηνωμένες Πολιτείες. Κάθε γραμμή αντιστοιχεί σε έναν ασφαλισμένο και περιέχει δημογραφικά χαρακτηριστικά και πληροφορίες για τον τρόπο ζωής του, καθώς και το ποσό που πληρώνει σε ετήσια βάση για την ασφάλειά του. Το dataset χρησιμοποιείται ευρέως για σκοπούς στατιστικής ανάλυσης, εκπαίδευσης μηχανικής μάθησης και αναλυτικής προβλεπτικών μοντέλων.
| Μεταβλητή | Περιγραφή |
|---|---|
| age | Ηλικία του ασφαλισμένου |
| sex | Φύλο (male/female) |
| bmi | Δείκτης Μάζας Σώματος (BMI) |
| children | Αριθμός εξαρτώμενων παιδιών |
| smoker | Καπνιστής (yes/no) |
| region | Γεωγραφική περιοχή (π.χ. southeast) |
| charges | Ετήσιο κόστος ασφάλισης ($) |
## age sex bmi children
## Min. :18.00 Length:1338 Min. :15.96 Min. :0.000
## 1st Qu.:27.00 Class :character 1st Qu.:26.30 1st Qu.:0.000
## Median :39.00 Mode :character Median :30.40 Median :1.000
## Mean :39.21 Mean :30.66 Mean :1.095
## 3rd Qu.:51.00 3rd Qu.:34.69 3rd Qu.:2.000
## Max. :64.00 Max. :53.13 Max. :5.000
## smoker region charges
## Length:1338 Length:1338 Min. : 1122
## Class :character Class :character 1st Qu.: 4740
## Mode :character Mode :character Median : 9382
## Mean :13270
## 3rd Qu.:16640
## Max. :63770
ggplot(insurance, aes(x = age, y = bmi)) +
geom_point(color = "#0073C2", alpha = 0.6, size = 2.5) +
theme_minimal(base_size = 14) +
labs(
x = "Ηλικία (έτη)",
y = "Δείκτης Μάζας Σώματος (BMI)"
)
Παρατηρήσεις
Δεν παρατηρείται σαφής γραμμική συσχέτιση μεταξύ ηλικίας και BMI, γεγονός που δείχνει πως το βάρος δεν αυξάνεται απαραίτητα με την ηλικία.
Υπάρχει συγκέντρωση παρατηρήσεων γύρω από ηλικίες 20–60 και τιμές BMI 25–35, δηλαδή στο εύρος υπέρβαρου/παχυσαρκίας.
ggplot(insurance, aes(x=children, y=age, fill=factor(children))) + geom_boxplot() +labs(x="Children", y="Age")
Παρατηρήσεις
Τα άτομα χωρίς παιδιά παρουσιάζουν τη μεγαλύτερη διασπορά ηλικιών, με παρατηρήσεις από περίπου 20 έως και 65 ετών, γεγονός που υποδηλώνει μεγαλύτερη ποικιλομορφία σε αυτή την ομάδα.
Οι ασφαλισμένοι με 3 ή περισσότερα παιδιά φαίνεται να έχουν κατά μέσο όρο μεγαλύτερη ηλικία συγκριτικά με όσους έχουν 0–2 παιδιά, κάτι που είναι αναμενόμενο καθώς η ηλικία σχετίζεται με το χρόνο απόκτησης οικογένειας.
ggplot(insurance, aes(x=age)) + geom_histogram(binwidth=0.9, fill="pink", color="black") + labs(x="Age", y="Frequency")
Παρατηρήσεις
Γενικά, φαίνετα να υπάρχει μία ομοιόμορφη κατανομή σε όλο το εύρος των ηλικιακών ομάδων.
ggplot(insurance, aes(region)) + geom_bar(width=0.4, fill="grey", color="black") + labs( x="Region", y="Frequency")
Παρατηρήσεις
Το διάγραμμα δείχνει τη συχνότητα των ασφαλισμένων ανά περιοχή, με τη νοτιοανατολική (southeast) να έχει τη μεγαλύτερη συγκέντρωση. Οι υπόλοιπες περιοχές παρουσιάζουν παρόμοιο αριθμό παρατηρήσεων, με μικρές διαφορές μεταξύ τους.
p1 <- ggplot(insurance, aes(x = age, y = charges)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, colour = "red") +
ggtitle("charges ~ age")
p2 <- ggplot(insurance, aes(x = bmi, y = charges)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, colour = "red") +
ggtitle("charges ~ bmi")
p3 <- ggplot(insurance, aes(x = children, y = charges)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, colour = "red") +
ggtitle("charges ~ children")
p4 <- ggplot(insurance, aes(x = smoker, y = charges)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, colour = "red") +
ggtitle("charges ~ smoker")
(p1 | p2) / (p3 | p4)
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
m1 <- lm(charges ~ age + sex + children + bmi + smoker + region, data= insurance)
summary(m1)
##
## Call:
## lm(formula = charges ~ age + sex + children + bmi + smoker +
## region, data = insurance)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11304.9 -2848.1 -982.1 1393.9 29992.8
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -11938.5 987.8 -12.086 < 2e-16 ***
## age 256.9 11.9 21.587 < 2e-16 ***
## sexmale -131.3 332.9 -0.394 0.693348
## children 475.5 137.8 3.451 0.000577 ***
## bmi 339.2 28.6 11.860 < 2e-16 ***
## smokeryes 23848.5 413.1 57.723 < 2e-16 ***
## regionnorthwest -353.0 476.3 -0.741 0.458769
## regionsoutheast -1035.0 478.7 -2.162 0.030782 *
## regionsouthwest -960.0 477.9 -2.009 0.044765 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6062 on 1329 degrees of freedom
## Multiple R-squared: 0.7509, Adjusted R-squared: 0.7494
## F-statistic: 500.8 on 8 and 1329 DF, p-value: < 2.2e-16
coef(m1)
## (Intercept) age sexmale children bmi
## -11938.5386 256.8564 -131.3144 475.5005 339.1935
## smokeryes regionnorthwest regionsoutheast regionsouthwest
## 23848.5345 -352.9639 -1035.0220 -960.0510
m2 <- lm(charges ~ age + sex + children + bmi + smoker, data= insurance)
summary(m2)
##
## Call:
## lm(formula = charges ~ age + sex + children + bmi + smoker, data = insurance)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11837.2 -2916.7 -994.2 1375.3 29565.5
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -12052.46 951.26 -12.670 < 2e-16 ***
## age 257.73 11.90 21.651 < 2e-16 ***
## sexmale -128.64 333.36 -0.386 0.699641
## children 474.41 137.86 3.441 0.000597 ***
## bmi 322.36 27.42 11.757 < 2e-16 ***
## smokeryes 23823.39 412.52 57.750 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6070 on 1332 degrees of freedom
## Multiple R-squared: 0.7497, Adjusted R-squared: 0.7488
## F-statistic: 798 on 5 and 1332 DF, p-value: < 2.2e-16
coef(m2)
## (Intercept) age sexmale children bmi smokeryes
## -12052.4620 257.7350 -128.6399 474.4111 322.3642 23823.3925
m3 <- lm(charges ~ age + children + bmi + smoker, data= insurance)
summary(m3)
##
## Call:
## lm(formula = charges ~ age + children + bmi + smoker, data = insurance)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11897.9 -2920.8 -986.6 1392.2 29509.6
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -12102.77 941.98 -12.848 < 2e-16 ***
## age 257.85 11.90 21.675 < 2e-16 ***
## children 473.50 137.79 3.436 0.000608 ***
## bmi 321.85 27.38 11.756 < 2e-16 ***
## smokeryes 23811.40 411.22 57.904 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6068 on 1333 degrees of freedom
## Multiple R-squared: 0.7497, Adjusted R-squared: 0.7489
## F-statistic: 998.1 on 4 and 1333 DF, p-value: < 2.2e-16
coef(m3)
## (Intercept) age children bmi smokeryes
## -12102.7694 257.8495 473.5023 321.8514 23811.3998
m4 <- lm(charges ~ age + bmi + smoker, data= insurance)
summary(m4)
##
## Call:
## lm(formula = charges ~ age + bmi + smoker, data = insurance)
##
## Residuals:
## Min 1Q Median 3Q Max
## -12415.4 -2970.9 -980.5 1480.0 28971.8
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -11676.83 937.57 -12.45 <2e-16 ***
## age 259.55 11.93 21.75 <2e-16 ***
## bmi 322.62 27.49 11.74 <2e-16 ***
## smokeryes 23823.68 412.87 57.70 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6092 on 1334 degrees of freedom
## Multiple R-squared: 0.7475, Adjusted R-squared: 0.7469
## F-statistic: 1316 on 3 and 1334 DF, p-value: < 2.2e-16
coef(m4)
## (Intercept) age bmi smokeryes
## -11676.8304 259.5475 322.6151 23823.6845
| Model | R_squared | SSE | RMSE |
|---|---|---|---|
| Age, Sex, Children, BMI, Smoker, Region | 0.7509 | 48839532844 | 6041.680 |
| Age, Sex, Children, BMI, Smoker | 0.7497 | 49072964053 | 6056.101 |
| Age, Children, BMI, Smoker | 0.7497 | 49078450117 | 6056.439 |
| Age, BMI, Smoker | 0.7475 | 49513219514 | 6083.206 |