library(readr)
## Warning: package 'readr' was built under R version 4.5.2
library(estadistica)
## Warning: package 'estadistica' was built under R version 4.5.3
library(moments)
## Warning: package 'moments' was built under R version 4.5.2
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.5.3
######
Sleep <- read_csv("Health_Sleep_Statistics.csv")
## Rows: 100 Columns: 12
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): Gender, Physical Activity Level, Dietary Habits, Sleep Disorders, ...
## dbl (5): User ID, Age, Sleep Quality, Daily Steps, Calories Burned
## time (2): Bedtime, Wake-up Time
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Sleep=as.data.frame(unclass(Sleep),
stringsAsFactors = TRUE)
names(Sleep)
## [1] "User.ID" "Age"
## [3] "Gender" "Sleep.Quality"
## [5] "Bedtime" "Wake.up.Time"
## [7] "Daily.Steps" "Calories.Burned"
## [9] "Physical.Activity.Level" "Dietary.Habits"
## [11] "Sleep.Disorders" "Medication.Usage"
n=nrow(Sleep)
Clases=round(1+3.33*log10(n),0)
ggplot(Sleep, aes(x=Age))+
geom_histogram(bins=Clases,
color="white",
fill="red")+
labs(title="Histograma de Edad de los pacientes",
x="Clases correspondientes a la edad",
y="Frecuencia Absoluta")

#opción2
#Tabla de distribución de frecuencia
min=min(Sleep$Age)
max=max(Sleep$Age)
Clases=round(1+3.33*log10(n),0)
#ancho de clase
C=round(diff(range(Sleep$Age))/Clases,0)
#La secuencia de los cortes
c(seq(min,max,by=C))#límite inferior
## [1] 22 26 30 34 38 42 46 50
Age.cut=cut(Sleep$Age,
breaks =c(22,26,30,34,38,42,46,51),#límite inferior
right = FALSE)
data.clase=data.frame(Age.cut)
ggplot(data.clase,aes(x=Age.cut))+
geom_bar(fill="red")+
labs(title="Histograma de edad",
x="Clase de edad",
y="Frecuencia absoluta")
