Transformaciòn de variables

Aplicaciones

Cargar conjuntos de datos

telco <- read.csv("https://raw.githubusercontent.com/VictorGuevaraP/Estadistica-R/master/Caso_telefon%C3%ADa.csv",

                  encoding = "latin1", sep = ";", stringsAsFactors = T)

head(telco)

Transformacion cuadrada

hist(telco$Edad, 12)

Para sacar la raiz cuadrada, simplemente se puede utilizar la funcion sqrt

sqrt(telco$Edad)
##  [1] 5.196152 5.291503 5.291503 4.582576 5.385165 5.099020 6.324555 6.324555
##  [9] 5.477226 5.196152 5.291503 4.898979 5.099020 5.744563 4.582576 6.324555
## [17] 5.000000 6.164414 5.916080 5.567764 5.291503 5.099020 5.099020 5.744563
## [25] 5.830952 4.690416 5.099020 6.244998 5.567764 4.690416 5.291503 5.916080
## [33] 4.690416 6.324555 5.830952 4.472136 5.830952 4.472136 5.385165 5.744563
## [41] 4.795832 5.916080 4.898979 5.656854 5.656854 5.196152 6.082763 5.656854
## [49] 5.744563 5.916080 6.244998 5.830952 6.164414 6.244998 6.082763 5.656854
## [57] 6.082763 5.000000 5.099020 6.324555 6.324555 5.477226 5.291503 4.898979
## [65] 5.744563 4.582576 5.291503 4.582576 5.385165 6.000000 5.830952 4.472136
## [73] 5.830952 4.472136 5.385165 5.567764 4.690416 6.164414 6.000000 5.744563
hist(sqrt(telco$Edad))

Tranformacion exponencial

exp(telco$Edad)
##  [1] 5.320482e+11 1.446257e+12 1.446257e+12 1.318816e+09 3.931334e+12
##  [6] 1.957296e+11 2.353853e+17 2.353853e+17 1.068647e+13 5.320482e+11
## [11] 1.446257e+12 2.648912e+10 1.957296e+11 2.146436e+14 1.318816e+09
## [16] 2.353853e+17 7.200490e+10 3.185593e+16 1.586013e+15 2.904885e+13
## [21] 1.446257e+12 1.957296e+11 1.957296e+11 2.146436e+14 5.834617e+14
## [26] 3.584913e+09 1.957296e+11 8.659340e+16 2.904885e+13 3.584913e+09
## [31] 1.446257e+12 1.586013e+15 3.584913e+09 2.353853e+17 5.834617e+14
## [36] 4.851652e+08 5.834617e+14 4.851652e+08 3.931334e+12 2.146436e+14
## [41] 9.744803e+09 1.586013e+15 2.648912e+10 7.896296e+13 7.896296e+13
## [46] 5.320482e+11 1.171914e+16 7.896296e+13 2.146436e+14 1.586013e+15
## [51] 8.659340e+16 5.834617e+14 3.185593e+16 8.659340e+16 1.171914e+16
## [56] 7.896296e+13 1.171914e+16 7.200490e+10 1.957296e+11 2.353853e+17
## [61] 2.353853e+17 1.068647e+13 1.446257e+12 2.648912e+10 2.146436e+14
## [66] 1.318816e+09 1.446257e+12 1.318816e+09 3.931334e+12 4.311232e+15
## [71] 5.834617e+14 4.851652e+08 5.834617e+14 4.851652e+08 3.931334e+12
## [76] 2.904885e+13 3.584913e+09 3.185593e+16 4.311232e+15 2.146436e+14
plot(exp(telco$Edad))

Transformacion logaritmica

log(telco$Edad)
##  [1] 3.295837 3.332205 3.332205 3.044522 3.367296 3.258097 3.688879 3.688879
##  [9] 3.401197 3.295837 3.332205 3.178054 3.258097 3.496508 3.044522 3.688879
## [17] 3.218876 3.637586 3.555348 3.433987 3.332205 3.258097 3.258097 3.496508
## [25] 3.526361 3.091042 3.258097 3.663562 3.433987 3.091042 3.332205 3.555348
## [33] 3.091042 3.688879 3.526361 2.995732 3.526361 2.995732 3.367296 3.496508
## [41] 3.135494 3.555348 3.178054 3.465736 3.465736 3.295837 3.610918 3.465736
## [49] 3.496508 3.555348 3.663562 3.526361 3.637586 3.663562 3.610918 3.465736
## [57] 3.610918 3.218876 3.258097 3.688879 3.688879 3.401197 3.332205 3.178054
## [65] 3.496508 3.044522 3.332205 3.044522 3.367296 3.583519 3.526361 2.995732
## [73] 3.526361 2.995732 3.367296 3.433987 3.091042 3.637586 3.583519 3.496508
log(telco$Edad, base=2)
##  [1] 4.754888 4.807355 4.807355 4.392317 4.857981 4.700440 5.321928 5.321928
##  [9] 4.906891 4.754888 4.807355 4.584963 4.700440 5.044394 4.392317 5.321928
## [17] 4.643856 5.247928 5.129283 4.954196 4.807355 4.700440 4.700440 5.044394
## [25] 5.087463 4.459432 4.700440 5.285402 4.954196 4.459432 4.807355 5.129283
## [33] 4.459432 5.321928 5.087463 4.321928 5.087463 4.321928 4.857981 5.044394
## [41] 4.523562 5.129283 4.584963 5.000000 5.000000 4.754888 5.209453 5.000000
## [49] 5.044394 5.129283 5.285402 5.087463 5.247928 5.285402 5.209453 5.000000
## [57] 5.209453 4.643856 4.700440 5.321928 5.321928 4.906891 4.807355 4.584963
## [65] 5.044394 4.392317 4.807355 4.392317 4.857981 5.169925 5.087463 4.321928
## [73] 5.087463 4.321928 4.857981 4.954196 4.459432 5.247928 5.169925 5.044394
hist(log(telco$Edad, base=2))

Comparacion de transformaciones

# Obtener solo transformaciones
 
edad_sqrt <- sqrt(telco$Edad)
edad_exp <- exp(telco$Edad)
edad_ln <- log(telco$Edad)
edad_log2 <- log(telco$Edad, base=2)
edad_log5 <- log(telco$Edad, base=5)

Ver graficamente

par(mfrow=c(3,2))
hist(telco$Edad)
hist(edad_sqrt)
hist(edad_exp)
hist(edad_ln)
hist(edad_log2)
hist(edad_log5)

par(mfrow=c(1,1))
par(mfrow=c(3,2))
plot(density(telco$Edad), main = "Distribucion de edades originales")
plot(density(edad_sqrt), main = "Disatribucion de edades transformadas - sqrt")
plot(density(edad_exp), main = "Disatribucion de edades transformadas - exp")
plot(density(edad_ln), main = "Disatribucion de edades transformadas - log")
plot(density(edad_log2), main = "Disatribucion de edades transformadas - log2")
plot(density(edad_log5), main = "Disatribucion de edades transformadas - log5")

par(mfrow=c(1,1))
library(PerformanceAnalytics)
## Warning: package 'PerformanceAnalytics' was built under R version 4.3.2
## Loading required package: xts
## Warning: package 'xts' was built under R version 4.3.2
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.3.2
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
## 
##     legend
chart.Correlation(cor(telco[,4:8]), histogram = TRUE)
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

Transformacion cuadrada

hist(telco$Monto, 12)

Para sacar la raiz cuadrada, simplemente se puede utilizar la funcion sqrt

sqrt(telco$Monto)
##  [1]  9.523655  9.782638 10.700467 10.295630  9.949874  9.497368 10.124228
##  [8]  9.602083 10.492855  9.823441  9.396808  9.252027  9.471008  9.423375
## [15]  9.165151  9.176056  9.576012  8.608136  9.423375  9.570789  8.944272
## [22]  9.402127  8.860023  9.396808  9.252027  9.412757  8.876936  9.033272
## [29]  9.289779  9.154234  9.523655  9.782638  9.964939  9.126883  9.864076
## [36]  9.099451  9.710819  9.823441  8.876936 10.009995  9.082951  9.088454
## [43]  9.721111  9.289779  9.396808  9.148770  9.154234  9.170605  9.121403
## [50]  9.208692  9.944848 10.913295 10.168579 10.469002 10.295630 10.029955
## [57] 10.148892 10.511898 10.601887  9.523655 10.606602 10.406729 10.295630
## [64]  9.949874  9.497368 10.124228  9.602083 10.492855  9.823441  9.591663
## [71]  9.176056  9.402127  8.860023  9.396808  9.252027  9.412757  8.876936
## [78]  9.033272  9.289779  9.154234
hist(sqrt(telco$Monto))

Tranformacion exponencial

exp(telco$Monto)
##  [1] 2.457590e+39 3.647388e+41 5.329889e+49 1.084464e+46 9.889030e+42
##  [6] 1.490604e+39 3.274797e+44 1.101416e+40 6.543686e+47 8.117410e+41
## [11] 2.229476e+38 1.498331e+37 9.040970e+38 3.675784e+38 3.025077e+36
## [16] 3.694838e+36 6.680423e+39 1.517823e+32 3.675784e+38 6.044697e+39
## [21] 5.540622e+34 2.463952e+38 1.236280e+34 2.229476e+38 1.498331e+37
## [26] 3.009477e+38 1.668803e+34 2.744288e+35 3.017267e+37 2.476724e+36
## [31] 2.457590e+39 3.647388e+41 1.334879e+43 1.502209e+36 1.806563e+42
## [36] 9.111358e+35 8.994347e+40 8.117410e+41 1.668803e+34 3.283274e+43
## [41] 6.749860e+35 7.459749e+35 1.098572e+41 3.017267e+37 2.229476e+38
## [46] 2.241032e+36 2.476724e+36 3.343227e+36 1.359255e+36 6.732433e+36
## [51] 8.947965e+42 5.302404e+51 8.054701e+44 3.968946e+47 1.084464e+46
## [56] 4.898069e+43 5.399228e+44 9.762033e+47 6.526792e+48 2.457590e+39
## [61] 7.213221e+48 1.081664e+47 1.084464e+46 9.889030e+42 1.490604e+39
## [66] 3.274797e+44 1.101416e+40 6.543686e+47 8.117410e+41 9.017628e+39
## [71] 3.694838e+36 2.463952e+38 1.236280e+34 2.229476e+38 1.498331e+37
## [76] 3.009477e+38 1.668803e+34 2.744288e+35 3.017267e+37 2.476724e+36
plot(exp(telco$Monto))

Transformacion logaritmica

log(telco$Monto)
##  [1] 4.507557 4.561218 4.740575 4.663439 4.595120 4.502029 4.629863 4.523960
##  [9] 4.701389 4.569543 4.480740 4.449685 4.496471 4.486387 4.430817 4.433195
## [17] 4.518522 4.305416 4.486387 4.517431 4.382027 4.481872 4.363099 4.480740
## [25] 4.449685 4.484132 4.366913 4.401829 4.457830 4.428433 4.507557 4.561218
## [33] 4.598146 4.422449 4.577799 4.416428 4.546481 4.569543 4.366913 4.607168
## [41] 4.412798 4.414010 4.548600 4.457830 4.480740 4.427239 4.428433 4.432007
## [49] 4.421247 4.440296 4.594109 4.779963 4.638605 4.696837 4.663439 4.611152
## [57] 4.634729 4.705016 4.722064 4.507557 4.722953 4.684905 4.663439 4.595120
## [65] 4.502029 4.629863 4.523960 4.701389 4.569543 4.521789 4.433195 4.481872
## [73] 4.363099 4.480740 4.449685 4.484132 4.366913 4.401829 4.457830 4.428433
log(telco$Monto, base=2)
##  [1] 6.503031 6.580447 6.839204 6.727920 6.629357 6.495056 6.679480 6.526695
##  [9] 6.782671 6.592457 6.464342 6.419539 6.487036 6.472488 6.392317 6.395748
## [17] 6.518850 6.211402 6.472488 6.517276 6.321928 6.465974 6.294621 6.464342
## [25] 6.419539 6.469235 6.300124 6.350497 6.431289 6.388878 6.503031 6.580447
## [33] 6.633722 6.380245 6.604368 6.371559 6.559186 6.592457 6.300124 6.646739
## [41] 6.366322 6.368070 6.562242 6.431289 6.464342 6.387156 6.388878 6.394034
## [49] 6.378512 6.405992 6.627899 6.896030 6.692092 6.776104 6.727920 6.652486
## [57] 6.686501 6.787903 6.812498 6.503031 6.813781 6.758889 6.727920 6.629357
## [65] 6.495056 6.679480 6.526695 6.782671 6.592457 6.523562 6.395748 6.465974
## [73] 6.294621 6.464342 6.419539 6.469235 6.300124 6.350497 6.431289 6.388878
hist(log(telco$Monto, base=2))

Comparacion de transformaciones

# Obtener solo transformaciones
 
Monto_sqrt <- sqrt(telco$Monto)
Monto_exp <- exp(telco$Monto)
Monto_ln <- log(telco$Monto)
Monto_log2 <- log(telco$Monto, base=2)
Monto_log5 <- log(telco$Monto, base=5)

Ver graficamente

par(mfrow=c(3,2))
hist(telco$Monto)
hist(Monto_sqrt)
hist(Monto_exp)
hist(Monto_ln)
hist(Monto_log2)
hist(Monto_log5)

par(mfrow=c(1,1))
par(mfrow=c(3,2))
plot(density(telco$Monto), main = "Distribucion de Montos originales")
plot(density(Monto_sqrt), main = "Disatribucion de Montos transformadas - sqrt")
plot(density(Monto_exp), main = "Disatribucion de Montos transformadas - exp")
plot(density(Monto_ln), main = "Disatribucion de Montos transformadas - log")
plot(density(Monto_log2), main = "Disatribucion de Montos transformadas - log2")
plot(density(Monto_log5), main = "Disatribucion de Montos transformadas - log5")

par(mfrow=c(1,1))
library(PerformanceAnalytics)
chart.Correlation(cor(telco[,4:8]), histogram = TRUE)
## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

Transformacion cuadrada

hist(telco$Minutos, 12)

Para sacar la raiz cuadrada, simplemente se puede utilizar la funcion sqrt

sqrt(telco$Minutos)
##  [1] 5.744563 5.630275 6.316645 6.268971 6.148170 6.610598 6.789698 6.131884
##  [9] 6.480741 6.557439 6.693280 6.131884 5.196152 5.486347 5.147815 5.319774
## [17] 5.449771 5.700877 4.969909 4.979960 5.674504 5.167204 5.603570 5.576737
## [25] 5.167204 5.839521 5.215362 5.329165 7.042727 5.347897 6.107373 5.822371
## [33] 6.164414 6.457554 6.188699 6.971370 5.761944 6.403124 6.457554 5.882176
## [41] 6.892024 5.916080 6.066300 6.603030 5.932959 6.148170 6.140033 6.442049
## [49] 7.092249 5.796551 7.211103 7.099296 6.016644 6.308724 7.886698 6.752777
## [57] 6.971370 6.300794 5.069517 6.356099 6.804410 6.603030 7.429670 6.252999
## [65] 7.183314 6.640783 6.244998 7.224957 7.321202 6.024948 4.929503 5.639149
## [73] 5.744563 5.630275 5.603570 5.186521 4.183300 5.468089 6.024948 5.639149
hist(sqrt(telco$Minutos))

Tranformacion exponencial

exp(telco$Minutos)
##  [1] 2.146436e+14 5.849720e+13 2.129854e+17 1.168889e+17 2.608143e+16
##  [6] 9.520700e+18 1.049484e+20 2.135367e+16 1.739275e+18 4.727839e+18
## [11] 2.860176e+19 2.135367e+16 5.320482e+11 1.181038e+13 3.227036e+11
## [16] 1.952243e+12 7.916735e+12 1.301879e+14 5.334254e+10 5.895263e+10
## [21] 9.644558e+13 3.941510e+11 4.333579e+13 3.210394e+13 3.941510e+11
## [26] 6.448249e+14 6.498452e+11 2.157562e+12 3.475412e+21 2.635252e+12
## [31] 1.581919e+16 5.279380e+14 3.185593e+16 1.288487e+18 4.300101e+16
## [36] 1.278533e+21 2.621663e+14 6.398435e+17 1.288487e+18 1.063137e+15
## [41] 4.255865e+20 1.586013e+15 9.594822e+15 8.614685e+18 1.937161e+15
## [46] 2.608143e+16 2.359945e+16 1.054924e+18 6.998620e+21 3.911061e+14
## [51] 3.831008e+22 7.734672e+21 5.265750e+15 1.927172e+17 1.030663e+27
## [56] 6.365439e+19 1.278533e+21 1.743777e+17 1.450001e+11 3.511536e+17
## [61] 1.281842e+20 8.614685e+18 9.398432e+23 9.570051e+16 2.568001e+22
## [66] 1.420321e+19 8.659340e+16 4.679204e+22 1.897511e+23 5.819554e+15
## [71] 3.575657e+10 6.464940e+13 2.146436e+14 5.849720e+13 4.333579e+13
## [76] 4.814172e+11 3.982478e+07 9.669522e+12 5.819554e+15 6.464940e+13
plot(exp(telco$Minutos))

Transformacion logaritmica

log(telco$Minutos)
##  [1] 3.496508 3.456317 3.686376 3.671225 3.632309 3.777348 3.830813 3.627004
##  [9] 3.737670 3.761200 3.802208 3.627004 3.295837 3.404525 3.277145 3.342862
## [17] 3.391147 3.481240 3.206803 3.210844 3.471966 3.284664 3.446808 3.437208
## [25] 3.284664 3.529297 3.303217 3.346389 3.903991 3.353407 3.618993 3.523415
## [33] 3.637586 3.730501 3.645450 3.883624 3.502550 3.713572 3.730501 3.543854
## [41] 3.860730 3.555348 3.605498 3.775057 3.561046 3.632309 3.629660 3.725693
## [49] 3.918005 3.514526 3.951244 3.919991 3.589059 3.683867 4.130355 3.819908
## [57] 3.883624 3.681351 3.246491 3.698830 3.835142 3.775057 4.010963 3.666122
## [65] 3.943522 3.786460 3.663562 3.955082 3.981549 3.591818 3.190476 3.459466
## [73] 3.496508 3.456317 3.446808 3.292126 2.862201 3.397858 3.591818 3.459466
log(telco$Minutos, base=2)
##  [1] 5.044394 4.986411 5.318317 5.296457 5.240314 5.449561 5.526695 5.232661
##  [9] 5.392317 5.426265 5.485427 5.232661 4.754888 4.911692 4.727920 4.822730
## [17] 4.892391 5.022368 4.626439 4.632268 5.008989 4.738768 4.972693 4.958843
## [25] 4.738768 5.091700 4.765535 4.827819 5.632268 4.837943 5.221104 5.083213
## [33] 5.247928 5.381975 5.259272 5.602884 5.053111 5.357552 5.381975 5.112700
## [41] 5.569856 5.129283 5.201634 5.446256 5.137504 5.240314 5.236493 5.375039
## [49] 5.652486 5.070389 5.700440 5.655352 5.177918 5.314697 5.958843 5.510962
## [57] 5.602884 5.311067 4.683696 5.336283 5.532940 5.446256 5.786596 5.289097
## [65] 5.689299 5.462707 5.285402 5.705978 5.744161 5.181898 4.602884 4.990955
## [73] 5.044394 4.986411 4.972693 4.749534 4.129283 4.902074 5.181898 4.990955
hist(log(telco$Minutos, base=2))

Comparacion de transformaciones

# Obtener solo transformaciones
Minutos_exp <- exp(telco$Minutos)
Minutos_sqrt <- sqrt(telco$Minutos)
Minutos_ln <- log(telco$Minutos)
Minutos_log2 <- log(telco$Minutos, base=2)
Minutos_log5 <- log(telco$Minutos, base=5)

Ver graficamente

par(mfrow=c(3,2))
hist(telco$Minutos)
hist(Minutos_exp)
hist(Minutos_sqrt)
hist(Minutos_ln)
hist(Minutos_log2)
hist(Minutos_log5)

par(mfrow=c(1,1))
par(mfrow=c(3,2))
plot(density(telco$Minutos), main = "Distribucion de Minutos originales")
plot(density(Minutos_exp), main = "Disatribucion de Minutos transformadas - exp")
plot(density(Minutos_sqrt), main = "Disatribucion de Minutos transformadas - sqrt")
plot(density(Minutos_ln), main = "Disatribucion de Minutos transformadas - log")
plot(density(Minutos_log2), main = "Disatribucion de Minutos transformadas - log2")
plot(density(Minutos_log5), main = "Disatribucion de Minutos transformadas - log5")

par(mfrow=c(1,1))
library(PerformanceAnalytics)
chart.Correlation(cor(telco[,4:8]), histogram = TRUE)
## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

Transformacion cuadrada

hist(telco$Llamadas, 12)

Para sacar la raiz cuadrada, simplemente se puede utilizar la funcion sqrt

sqrt(telco$Llamadas)
##  [1] 2.645751 2.000000 2.645751 2.236068 1.732051 2.000000 2.828427 2.000000
##  [9] 2.449490 2.000000 2.236068 1.732051 2.000000 1.414214 2.236068 2.236068
## [17] 2.449490 2.236068 2.000000 2.449490 2.645751 1.000000 3.000000 2.236068
## [25] 2.449490 2.449490 2.449490 2.645751 1.000000 2.645751 2.000000 2.236068
## [33] 1.732051 2.000000 1.000000 1.732051 1.732051 1.414214 2.645751 2.236068
## [41] 2.828427 1.414214 2.828427 1.000000 1.732051 2.828427 2.000000 2.828427
## [49] 2.645751 2.828427 3.000000 2.236068 2.828427 2.000000 2.236068 2.000000
## [57] 2.645751 2.236068 1.732051 2.000000 2.828427 2.000000 2.828427 3.605551
## [65] 2.449490 2.645751 3.000000 2.828427 1.732051 1.414214 1.000000 1.000000
## [73] 1.732051 2.236068 1.414214 1.414214 1.732051 1.732051 1.732051 1.414214
hist(sqrt(telco$Llamadas))

Tranformacion exponencial

exp(telco$Llamadas)
##  [1] 1.096633e+03 5.459815e+01 1.096633e+03 1.484132e+02 2.008554e+01
##  [6] 5.459815e+01 2.980958e+03 5.459815e+01 4.034288e+02 5.459815e+01
## [11] 1.484132e+02 2.008554e+01 5.459815e+01 7.389056e+00 1.484132e+02
## [16] 1.484132e+02 4.034288e+02 1.484132e+02 5.459815e+01 4.034288e+02
## [21] 1.096633e+03 2.718282e+00 8.103084e+03 1.484132e+02 4.034288e+02
## [26] 4.034288e+02 4.034288e+02 1.096633e+03 2.718282e+00 1.096633e+03
## [31] 5.459815e+01 1.484132e+02 2.008554e+01 5.459815e+01 2.718282e+00
## [36] 2.008554e+01 2.008554e+01 7.389056e+00 1.096633e+03 1.484132e+02
## [41] 2.980958e+03 7.389056e+00 2.980958e+03 2.718282e+00 2.008554e+01
## [46] 2.980958e+03 5.459815e+01 2.980958e+03 1.096633e+03 2.980958e+03
## [51] 8.103084e+03 1.484132e+02 2.980958e+03 5.459815e+01 1.484132e+02
## [56] 5.459815e+01 1.096633e+03 1.484132e+02 2.008554e+01 5.459815e+01
## [61] 2.980958e+03 5.459815e+01 2.980958e+03 4.424134e+05 4.034288e+02
## [66] 1.096633e+03 8.103084e+03 2.980958e+03 2.008554e+01 7.389056e+00
## [71] 2.718282e+00 2.718282e+00 2.008554e+01 1.484132e+02 7.389056e+00
## [76] 7.389056e+00 2.008554e+01 2.008554e+01 2.008554e+01 7.389056e+00
plot(exp(telco$Llamadas))

Transformacion logaritmica

log(telco$Llamadas)
##  [1] 1.9459101 1.3862944 1.9459101 1.6094379 1.0986123 1.3862944 2.0794415
##  [8] 1.3862944 1.7917595 1.3862944 1.6094379 1.0986123 1.3862944 0.6931472
## [15] 1.6094379 1.6094379 1.7917595 1.6094379 1.3862944 1.7917595 1.9459101
## [22] 0.0000000 2.1972246 1.6094379 1.7917595 1.7917595 1.7917595 1.9459101
## [29] 0.0000000 1.9459101 1.3862944 1.6094379 1.0986123 1.3862944 0.0000000
## [36] 1.0986123 1.0986123 0.6931472 1.9459101 1.6094379 2.0794415 0.6931472
## [43] 2.0794415 0.0000000 1.0986123 2.0794415 1.3862944 2.0794415 1.9459101
## [50] 2.0794415 2.1972246 1.6094379 2.0794415 1.3862944 1.6094379 1.3862944
## [57] 1.9459101 1.6094379 1.0986123 1.3862944 2.0794415 1.3862944 2.0794415
## [64] 2.5649494 1.7917595 1.9459101 2.1972246 2.0794415 1.0986123 0.6931472
## [71] 0.0000000 0.0000000 1.0986123 1.6094379 0.6931472 0.6931472 1.0986123
## [78] 1.0986123 1.0986123 0.6931472
log(telco$Llamadas, base=2)
##  [1] 2.807355 2.000000 2.807355 2.321928 1.584963 2.000000 3.000000 2.000000
##  [9] 2.584963 2.000000 2.321928 1.584963 2.000000 1.000000 2.321928 2.321928
## [17] 2.584963 2.321928 2.000000 2.584963 2.807355 0.000000 3.169925 2.321928
## [25] 2.584963 2.584963 2.584963 2.807355 0.000000 2.807355 2.000000 2.321928
## [33] 1.584963 2.000000 0.000000 1.584963 1.584963 1.000000 2.807355 2.321928
## [41] 3.000000 1.000000 3.000000 0.000000 1.584963 3.000000 2.000000 3.000000
## [49] 2.807355 3.000000 3.169925 2.321928 3.000000 2.000000 2.321928 2.000000
## [57] 2.807355 2.321928 1.584963 2.000000 3.000000 2.000000 3.000000 3.700440
## [65] 2.584963 2.807355 3.169925 3.000000 1.584963 1.000000 0.000000 0.000000
## [73] 1.584963 2.321928 1.000000 1.000000 1.584963 1.584963 1.584963 1.000000
hist(log(telco$Llamadas, base=2))

Comparacion de transformaciones

# Obtener solo transformaciones
 
Llamadas_sqrt <- sqrt(telco$Llamadas)
Llamadas_exp <- exp(telco$Llamadas)
Llamadas_ln <- log(telco$Llamadas)
Llamadas_log2 <- log(telco$Llamadas, base=2)
Llamadas_log5 <- log(telco$Llamadas, base=5)

Ver graficamente

par(mfrow=c(3,2))
hist(telco$Llamadas)
hist(Llamadas_sqrt)
hist(Llamadas_exp)
hist(Llamadas_ln)
hist(Llamadas_log2)
hist(Llamadas_log5)

par(mfrow=c(1,1))
par(mfrow=c(3,2))
plot(density(telco$Llamadas), main = "Distribucion de Llamadas originales")
plot(density(Llamadas_sqrt), main = "Disatribucion de Llamadas transformadas - sqrt")
plot(density(Llamadas_exp), main = "Disatribucion de Llamadas transformadas - exp")
plot(density(Llamadas_ln), main = "Disatribucion de Llamadas transformadas - log")
plot(density(Llamadas_log2), main = "Disatribucion de Llamadas transformadas - log2")
plot(density(Llamadas_log5), main = "Disatribucion de Llamadas transformadas - log5")

par(mfrow=c(1,1))
library(PerformanceAnalytics)
chart.Correlation(cor(telco[,4:8]), histogram = TRUE)
## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

Transformacion cuadrada

hist(telco$Tiempo, 12)

Para sacar la raiz cuadrada, simplemente se puede utilizar la funcion sqrt

sqrt(telco$Tiempo)
##  [1] 4.1109610 1.2247449 2.0000000 3.8078866 1.6431677 3.3911650 0.7071068
##  [8] 1.1401754 2.3021729 1.0954451 1.3038405 4.5276926 0.8944272 0.6324555
## [15] 1.6733201 2.4083189 2.0493902 0.8944272 3.0822070 1.6124515 2.1213203
## [22] 1.1401754 1.6124515 2.3452079 1.6431677 3.3911650 0.7071068 1.1401754
## [29] 2.3021729 1.0954451 1.3038405 4.5276926 1.8165902 0.5477226 1.3038405
## [36] 4.0620192 1.9748418 5.1575188 1.5491933 0.5477226 1.6431677 4.7644517
## [43] 2.1213203 2.1447611 2.8635642 2.2803509 2.0000000 3.5355339 4.8682646
## [50] 1.6431677 6.0000000 0.7071068 1.2649111 1.3038405 0.8944272 1.4832397
## [57] 2.1908902 1.4832397 2.0000000 4.1109610 1.2247449 1.6733201 1.8708287
## [64] 2.0000000 3.8078866 1.7606817 2.1679483 1.9748418 2.5690465 3.4205263
## [71] 1.6124515 2.3021729 1.0954451 1.3038405 4.5276926 1.8165902 0.5477226
## [78] 1.3038405 1.4832397 2.0000000
hist(sqrt(telco$Tiempo))

Tranformacion exponencial

exp(telco$Tiempo)
##  [1] 2.185631e+07 4.481689e+00 5.459815e+01 1.982759e+06 1.487973e+01
##  [6] 9.871577e+04 1.648721e+00 3.669297e+00 2.003368e+02 3.320117e+00
## [11] 5.473947e+00 7.999022e+08 2.225541e+00 1.491825e+00 1.644465e+01
## [16] 3.302996e+02 6.668633e+01 2.225541e+00 1.335973e+04 1.346374e+01
## [21] 9.001713e+01 3.669297e+00 1.346374e+01 2.446919e+02 1.487973e+01
## [26] 9.871577e+04 1.648721e+00 3.669297e+00 2.003368e+02 3.320117e+00
## [31] 5.473947e+00 7.999022e+08 2.711264e+01 1.349859e+00 5.473947e+00
## [36] 1.465072e+07 4.940245e+01 3.566426e+11 1.102318e+01 1.349859e+00
## [41] 1.487973e+01 7.219128e+09 9.001713e+01 9.948432e+01 3.640950e+03
## [46] 1.812722e+02 5.459815e+01 2.683373e+05 1.962362e+10 1.487973e+01
## [51] 4.311232e+15 1.648721e+00 4.953032e+00 5.473947e+00 2.225541e+00
## [56] 9.025013e+00 1.215104e+02 9.025013e+00 5.459815e+01 2.185631e+07
## [61] 4.481689e+00 1.644465e+01 3.311545e+01 5.459815e+01 1.982759e+06
## [66] 2.219795e+01 1.099472e+02 4.940245e+01 7.350952e+02 1.205717e+05
## [71] 1.346374e+01 2.003368e+02 3.320117e+00 5.473947e+00 7.999022e+08
## [76] 2.711264e+01 1.349859e+00 5.473947e+00 9.025013e+00 5.459815e+01
plot(exp(telco$Tiempo))

Transformacion logaritmica

log(telco$Tiempo)
##  [1]  2.8273136  0.4054651  1.3862944  2.6741486  0.9932518  2.4423470
##  [7] -0.6931472  0.2623643  1.6677068  0.1823216  0.5306283  3.0204249
## [13] -0.2231436 -0.9162907  1.0296194  1.7578579  1.4350845 -0.2231436
## [19]  2.2512918  0.9555114  1.5040774  0.2623643  0.9555114  1.7047481
## [25]  0.9932518  2.4423470 -0.6931472  0.2623643  1.6677068  0.1823216
## [31]  0.5306283  3.0204249  1.1939225 -1.2039728  0.5306283  2.8033604
## [37]  1.3609766  3.2809112  0.8754687 -1.2039728  0.9932518  3.1223649
## [43]  1.5040774  1.5260563  2.1041342  1.6486586  1.3862944  2.5257286
## [49]  3.1654750  0.9932518  3.5835189 -0.6931472  0.4700036  0.5306283
## [55] -0.2231436  0.7884574  1.5686159  0.7884574  1.3862944  2.8273136
## [61]  0.4054651  1.0296194  1.2527630  1.3862944  2.6741486  1.1314021
## [67]  1.5475625  1.3609766  1.8870696  2.4595888  0.9555114  1.6677068
## [73]  0.1823216  0.5306283  3.0204249  1.1939225 -1.2039728  0.5306283
## [79]  0.7884574  1.3862944
log(telco$Tiempo, base=2)
##  [1]  4.0789513  0.5849625  2.0000000  3.8579810  1.4329594  3.5235620
##  [7] -1.0000000  0.3785116  2.4059924  0.2630344  0.7655347  4.3575520
## [13] -0.3219281 -1.3219281  1.4854268  2.5360529  2.0703893 -0.3219281
## [19]  3.2479275  1.3785116  2.1699250  0.3785116  1.3785116  2.4594316
## [25]  1.4329594  3.5235620 -1.0000000  0.3785116  2.4059924  0.2630344
## [31]  0.7655347  4.3575520  1.7224660 -1.7369656  0.7655347  4.0443941
## [37]  1.9634741  4.7333543  1.2630344 -1.7369656  1.4329594  4.5046204
## [43]  2.1699250  2.2016339  3.0356239  2.3785116  2.0000000  3.6438562
## [49]  4.5668152  1.4329594  5.1699250 -1.0000000  0.6780719  0.7655347
## [55] -0.3219281  1.1375035  2.2630344  1.1375035  2.0000000  4.0789513
## [61]  0.5849625  1.4854268  1.8073549  2.0000000  3.8579810  1.6322682
## [67]  2.2326608  1.9634741  2.7224660  3.5484366  1.3785116  2.4059924
## [73]  0.2630344  0.7655347  4.3575520  1.7224660 -1.7369656  0.7655347
## [79]  1.1375035  2.0000000
hist(log(telco$Tiempo, base=2))

Comparacion de transformaciones

# Obtener solo transformaciones
 
Tiempo_sqrt <- sqrt(telco$Tiempo)
Tiempo_exp <- exp(telco$Tiempo)
Tiempo_ln <- log(telco$Tiempo)

Tiempo_log5 <- log(telco$Tiempo, base=5)

Ver graficamente

par(mfrow=c(3,2))
hist(telco$Tiempo)
hist(Tiempo_sqrt)
hist(Tiempo_exp)
hist(Tiempo_ln)
hist(Tiempo_log5)
par(mfrow=c(1,1))

par(mfrow=c(3,2))
plot(density(telco$Tiempo), main = "Distribucion de Tiempo originales")
plot(density(Tiempo_sqrt), main = "Disatribucion de Tiempo transformadas - sqrt")
plot(density(Tiempo_exp), main = "Disatribucion de Tiempo transformadas - exp")
plot(density(Tiempo_ln), main = "Disatribucion de Tiempo transformadas - log")

plot(density(Tiempo_log5), main = "Disatribucion de  transformadas - log5")
par(mfrow=c(1,1))

library(PerformanceAnalytics)
chart.Correlation(cor(telco[,4:8]), histogram = TRUE)
## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

Transformacion cuadrada

hist(telco$Reclamos, 12)

Para sacar la raiz cuadrada, simplemente se puede utilizar la funcion sqrt

sqrt(telco$Reclamos)
##  [1] 2.236068 1.414214 2.236068 1.732051 1.414214 1.732051 2.449490 1.414214
##  [9] 1.732051 1.000000 1.732051 1.732051 1.414214 1.000000 2.000000 1.732051
## [17] 1.732051 2.000000 2.000000 1.000000 1.732051 1.000000 2.645751 1.732051
## [25] 1.732051 1.414214 2.000000 2.236068 1.000000 2.236068 1.414214 1.732051
## [33] 1.732051 2.000000 1.000000 1.414214 1.414214 1.000000 2.000000 2.000000
## [41] 1.732051 1.000000 1.732051 1.000000 1.414214 2.645751 1.732051 2.236068
## [49] 1.732051 2.645751 2.828427 2.236068 2.828427 2.000000 2.000000 1.732051
## [57] 2.645751 2.236068 1.414214 1.732051 2.828427 2.000000 2.828427 3.316625
## [65] 2.236068 2.000000 3.000000 2.828427 1.732051 1.414214 1.000000 1.000000
## [73] 1.732051 2.000000 1.414214 1.000000 1.414214 1.732051 1.414214 1.414214
hist(sqrt(telco$Reclamos))

Tranformacion exponencial

exp(telco$Reclamos)
##  [1]   148.413159     7.389056   148.413159    20.085537     7.389056
##  [6]    20.085537   403.428793     7.389056    20.085537     2.718282
## [11]    20.085537    20.085537     7.389056     2.718282    54.598150
## [16]    20.085537    20.085537    54.598150    54.598150     2.718282
## [21]    20.085537     2.718282  1096.633158    20.085537    20.085537
## [26]     7.389056    54.598150   148.413159     2.718282   148.413159
## [31]     7.389056    20.085537    20.085537    54.598150     2.718282
## [36]     7.389056     7.389056     2.718282    54.598150    54.598150
## [41]    20.085537     2.718282    20.085537     2.718282     7.389056
## [46]  1096.633158    20.085537   148.413159    20.085537  1096.633158
## [51]  2980.957987   148.413159  2980.957987    54.598150    54.598150
## [56]    20.085537  1096.633158   148.413159     7.389056    20.085537
## [61]  2980.957987    54.598150  2980.957987 59874.141715   148.413159
## [66]    54.598150  8103.083928  2980.957987    20.085537     7.389056
## [71]     2.718282     2.718282    20.085537    54.598150     7.389056
## [76]     2.718282     7.389056    20.085537     7.389056     7.389056
plot(exp(telco$Reclamos))

Transformacion logaritmica

log(telco$Reclamos)
##  [1] 1.6094379 0.6931472 1.6094379 1.0986123 0.6931472 1.0986123 1.7917595
##  [8] 0.6931472 1.0986123 0.0000000 1.0986123 1.0986123 0.6931472 0.0000000
## [15] 1.3862944 1.0986123 1.0986123 1.3862944 1.3862944 0.0000000 1.0986123
## [22] 0.0000000 1.9459101 1.0986123 1.0986123 0.6931472 1.3862944 1.6094379
## [29] 0.0000000 1.6094379 0.6931472 1.0986123 1.0986123 1.3862944 0.0000000
## [36] 0.6931472 0.6931472 0.0000000 1.3862944 1.3862944 1.0986123 0.0000000
## [43] 1.0986123 0.0000000 0.6931472 1.9459101 1.0986123 1.6094379 1.0986123
## [50] 1.9459101 2.0794415 1.6094379 2.0794415 1.3862944 1.3862944 1.0986123
## [57] 1.9459101 1.6094379 0.6931472 1.0986123 2.0794415 1.3862944 2.0794415
## [64] 2.3978953 1.6094379 1.3862944 2.1972246 2.0794415 1.0986123 0.6931472
## [71] 0.0000000 0.0000000 1.0986123 1.3862944 0.6931472 0.0000000 0.6931472
## [78] 1.0986123 0.6931472 0.6931472
log(telco$Reclamos, base=2)
##  [1] 2.321928 1.000000 2.321928 1.584963 1.000000 1.584963 2.584963 1.000000
##  [9] 1.584963 0.000000 1.584963 1.584963 1.000000 0.000000 2.000000 1.584963
## [17] 1.584963 2.000000 2.000000 0.000000 1.584963 0.000000 2.807355 1.584963
## [25] 1.584963 1.000000 2.000000 2.321928 0.000000 2.321928 1.000000 1.584963
## [33] 1.584963 2.000000 0.000000 1.000000 1.000000 0.000000 2.000000 2.000000
## [41] 1.584963 0.000000 1.584963 0.000000 1.000000 2.807355 1.584963 2.321928
## [49] 1.584963 2.807355 3.000000 2.321928 3.000000 2.000000 2.000000 1.584963
## [57] 2.807355 2.321928 1.000000 1.584963 3.000000 2.000000 3.000000 3.459432
## [65] 2.321928 2.000000 3.169925 3.000000 1.584963 1.000000 0.000000 0.000000
## [73] 1.584963 2.000000 1.000000 0.000000 1.000000 1.584963 1.000000 1.000000
hist(log(telco$Reclamos, base=2))

Comparacion de transformaciones

# Obtener solo transformaciones
 
Reclamos_sqrt <- sqrt(telco$Reclamos)
Reclamos_exp <- exp(telco$Reclamos)
Reclamos_ln <- log(telco$Reclamos)
Reclamos_log2 <- log(telco$Reclamos, base=2)
Reclamos_log5 <- log(telco$Reclamos, base=5)

Ver graficamente

par(mfrow=c(3,2))
hist(telco$Reclamos)
hist(Reclamos_sqrt)
hist(Reclamos_exp)
hist(Reclamos_ln)
hist(Reclamos_log2)
hist(Reclamos_log5)

par(mfrow=c(1,1))
par(mfrow=c(3,2))
plot(density(telco$Reclamos), main = "Distribucion de Reclamos originales")
plot(density(Reclamos_sqrt), main = "Disatribucion de Reclamos transformadas - sqrt")
plot(density(Reclamos_exp), main = "Disatribucion de Reclamos transformadas - exp")
plot(density(Reclamos_ln), main = "Disatribucion de Reclamos transformadas - log")
plot(density(Reclamos_log2), main = "Disatribucion de Reclamos transformadas - log2")
plot(density(Reclamos_log5), main = "Disatribucion de Reclamos transformadas - log5")

par(mfrow=c(1,1))
library(PerformanceAnalytics)
chart.Correlation(cor(telco[,4:8]), histogram = TRUE)
## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter

## Warning in par(usr): argument 1 does not name a graphical parameter