Las librericas que vamos a utilizar para una distribucion de frecuencias son, fdth y ggplot2, vamos a cargarlas y a instalarlas
library("fdth")
## Warning: package 'fdth' was built under R version 4.3.3
##
## Attaching package: 'fdth'
## The following objects are masked from 'package:stats':
##
## sd, var
library("ggplot2")
## Warning: package 'ggplot2' was built under R version 4.3.3
#Funcion para distribucion de frecuencias
tabla.edades<-fdt(x=insurance$age,breaks ="Sturges" )
tabla.edades
## Class limits f rf rf(%) cf cf(%)
## [17.82,21.722) 194 0.14 14.50 194 14.50
## [21.722,25.623) 112 0.08 8.37 306 22.87
## [25.623,29.525) 111 0.08 8.30 417 31.17
## [29.525,33.427) 106 0.08 7.92 523 39.09
## [33.427,37.328) 101 0.08 7.55 624 46.64
## [37.328,41.23) 104 0.08 7.77 728 54.41
## [41.23,45.132) 110 0.08 8.22 838 62.63
## [45.132,49.033) 115 0.09 8.59 953 71.23
## [49.033,52.935) 87 0.07 6.50 1040 77.73
## [52.935,56.837) 108 0.08 8.07 1148 85.80
## [56.837,60.738) 99 0.07 7.40 1247 93.20
## [60.738,64.64) 91 0.07 6.80 1338 100.00
#Realizar un historgrama de la informacion
hist(insurance$age,breaks = "Sturges")
#Diagrama de dispersion de las edades
datos.edades1 <- data.frame(x = 1:length(insurance$age), edad= insurance$age)
ggplot(datos.edades1, aes(x=x, y=edad))+
geom_point() +
geom_hline(yintercept = median(insurance$age), col='red') +
ggtitle(label = "Dispersión de edades1", subtitle = paste("media = ", median(insurance$age)))
mean(insurance$age)
## [1] 39.20703
median(insurance$age)
## [1] 39