library(readr)
library(fdth)
##
## Attaching package: 'fdth'
## The following objects are masked from 'package:stats':
##
## sd, var
library(stats)
library(moments)
PrecipMensual <- read_csv("C:/Users/vite_/Downloads/PrecipMensual.csv")
## Rows: 89 Columns: 17
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (17): CLAVE, x, y, ene, feb, mar, abr, may, jun, jul, ago, sep, oct, nov...
##
## ℹ 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.
View(PrecipMensual)
data <- data.frame(PrecipMensual)
# 1) Seleccion del mes
julio <- data$jul
head(julio)
## [1] 116.0000 127.0000 116.1935 165.7097 89.0000 138.8387
tabla <- fdt(julio)
tabla
## Class limits f rf rf(%) cf cf(%)
## [55.22,94.8989) 3 0.03 3.37 3 3.37
## [94.8989,134.578) 28 0.31 31.46 31 34.83
## [134.578,174.257) 25 0.28 28.09 56 62.92
## [174.257,213.936) 17 0.19 19.10 73 82.02
## [213.936,253.614) 8 0.09 8.99 81 91.01
## [253.614,293.293) 5 0.06 5.62 86 96.63
## [293.293,332.972) 0 0.00 0.00 86 96.63
## [332.972,372.651) 3 0.03 3.37 89 100.00
# 2) Histograma
hist(julio, col = "green")

# 3) Medidas de tendencia central
media <- mean(julio)
media
## [1] 167.0886
mediana <- median(julio)
mediana
## [1] 149.7692
moda <- (table(julio))
moda <- as.numeric(names(moda[moda == max(moda)]))
moda
## [1] 55.77778 89.00000 91.41379 96.28000 96.37037 97.73077 102.76923
## [8] 104.53846 105.12000 106.95000 107.41177 108.36667 109.68750 111.05882
## [15] 112.00000 113.16129 114.18750 114.50000 115.87500 116.00000 116.19355
## [22] 119.70968 121.90323 124.34375 124.93750 127.00000 127.64000 129.40000
## [29] 129.56250 130.33333 132.53846 136.50000 138.56000 138.83871 140.28571
## [36] 142.40625 144.40000 144.90625 145.21875 146.25926 147.72414 148.73684
## [43] 148.81482 148.85714 149.76923 150.20000 150.42857 153.68000 158.21875
## [50] 162.26087 163.60870 164.69565 165.70968 168.23077 170.67857 174.18518
## [57] 174.60870 175.34483 176.00000 181.70370 182.70588 186.87500 193.33333
## [64] 199.41177 199.44000 202.52174 203.10000 207.19231 207.61905 209.00000
## [71] 209.17241 210.30000 212.85000 216.95238 222.14286 227.27778 228.70968
## [78] 235.34783 242.82759 243.45833 247.51852 253.83871 265.76667 271.00000
## [85] 271.94737 275.82609 345.80769 367.39130 368.96154
# 3.1 Medidas de dispersion
varianza <- var(julio)
varianza
## [1] 3734.117
desviacionEst <- sd(julio)
desviacionEst
## [1] 61.10742
rango <- range(julio)
rango
## [1] 55.77778 368.96154
cuartiles <- summary(julio)
cuartiles
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 55.78 121.90 149.77 167.09 203.10 368.96
# 3.2 Medidas de forma
curtosis <- kurtosis(julio)
curtosis
## [1] 4.539007
sesgo <- skewness(julio)
sesgo
## [1] 1.166588
# 4) Identificación de outliers
str(julio)
## num [1:89] 116 127 116 166 89 ...
outliers <- boxplot.stats(julio)
outliers
## $stats
## [1] 55.77778 121.90323 149.76923 203.10000 275.82609
##
## $n
## [1] 89
##
## $conf
## [1] 136.1704 163.3680
##
## $out
## [1] 367.3913 368.9615 345.8077
# 5) Transformación adecuada a los datos
logaritmo <- log(julio)
hist(logaritmo, col = "red")

#logaritmo es más simetrico
raiz <- sqrt(julio)
hist(raiz, col = "blue")

reciproca <- 1/julio
hist(reciproca, col = "yellow")

cuadrado <- julio**2
hist(cuadrado, col = "orange")

cubica <- julio**3
hist(cubica, col = "orange")

# 6) Grafica Q-Q
x <- rnorm(julio, mean = media, sd = 100)
y <- rchisq(julio, df = 100)
qqplot(x,y)

# 7) Diagrama de caja y bigotes (boxplot)
boxplot(julio)

boxplot(julio, horizontal = TRUE)
