Importamos los datos

animacion <- read.csv("shows.csv", sep = ";")

0.15 Recodificación de variables

colnames(animacion)
## [1] "Ranking" "Name"    "Year"    "Minutes" "genre"   "Rating"  "Votes"
names(animacion) <- c("Puesto","Nombre","Año","Duracion","Género","Puntaje","Votos")
names(animacion)
## [1] "Puesto"   "Nombre"   "Año"      "Duracion" "Género"   "Puntaje"  "Votos"
 # Eliminamos valores NA o nulos

animacion <- na.omit(animacion)
animacion
##    Puesto                                  Nombre         Año Duracion
## 1       1                               Big Mouth    (2017– )   30 min
## 2       2                            The Bad Guys       -2022  100 min
## 3       3                            Chainsaw Man    (2022– )         
## 4       4                          Rick and Morty    (2013– )   23 min
## 6       6                               Zootopia+    (2022– )         
## 7       7            Star Wars: Tales of the Jedi    (2022– )   15 min
## 8       8                     One Piece Film: Red       -2022  115 min
## 9       9                              Family Guy    (1999– )   22 min
## 10     10                          Wendell & Wild       -2022  105 min
## 11     11                            The Simpsons    (1989– )   22 min
## 12     12                       The Dragon Prince    (2018– )   26 min
## 13     13                         Attack on Titan (2013–2023)   24 min
## 14     14                               Pinocchio (II) (2022)  117 min
## 15     15                               One Piece    (1999– )   24 min
## 16     16         Bleach: Thousand-Year Blood War    (2022– )   24 min
## 17     17                   Lyle, Lyle, Crocodile       -2022  106 min
## 18     18 Miraculous: Tales of Ladybug & Cat Noir    (2015– )   20 min
## 20     20                                  Sing 2       -2021  110 min
## 21     21                  Cyberpunk: Edgerunners    (2022– )   24 min
## 22     22                        My Hero Academia    (2016– )   24 min
## 23     23                              Super Pets       -2022  105 min
## 24     24                         BoJack Horseman (2014–2020)   25 min
## 25     25                                  Arcane    (2021– )   41 min
## 26     26                           Bob's Burgers    (2011– )   22 min
## 27     27                             Zootropolis       -2016  108 min
## 28     28                               Enchanted       -2007  107 min
## 29     29                              South Park    (1997– )   22 min
## 30     30          The Nightmare Before Christmas       -1993   76 min
## 31     31               Star Wars: The Clone Wars (2008–2020)   23 min
## 32     32          Demon Slayer: Kimetsu no Yaiba    (2019– )   24 min
## 33     33                    Love, Death & Robots    (2019– )   15 min
## 35     35                                 Encanto       -2021  102 min
## 36     36              Avatar: The Last Airbender (2005–2008)   23 min
## 37     37               The Soccer Football Movie       -2022   73 min
## 38     38             Batman: The Animated Series (1992–1995)   23 min
## 39     39                                  Archer    (2009– )   22 min
## 40     40                          Mob Psycho 100    (2016– )   24 min
## 41     41                Minions: The Rise of Gru       -2022   87 min
## 42     42                                  Bleach (2004–2012)   24 min
## 43     43                                    Coco  (I) (2017)  105 min
## 44     44                                    Sing       -2016  108 min
## 45     45                           American Dad!    (2005– )   22 min
## 46     46                                Futurama (1999–2023)   22 min
## 47     47                                   Bluey    (2018– )    7 min
## 48     48                           The Lion King       -1994   88 min
## 49     49                              Invincible    (2021– )   50 min
## 50     50                              SPY×FAMILY    (2022– )   24 min
##                          Género Puntaje   Votos
## 1    Animation, Comedy, Romance     7.9   79301
## 2  Animation, Adventure, Comedy     6.8   37335
## 3  Animation, Action, Adventure     8.8   10613
## 4  Animation, Adventure, Comedy     9.1  515315
## 6   Animation, Short, Adventure     6.8    1232
## 7      Animation, Short, Action     8.4   15691
## 8  Animation, Action, Adventure     6.9    6269
## 9             Animation, Comedy     8.2  338447
## 10 Animation, Adventure, Comedy     6.5    5759
## 11            Animation, Comedy     8.7  406290
## 12 Animation, Action, Adventure     8.3   23460
## 13 Animation, Action, Adventure     9.0  369274
## 14     Animation, Drama, Family     8.0     539
## 15 Animation, Action, Adventure     8.9  124898
## 16 Animation, Action, Adventure     9.4    8182
## 17 Animation, Adventure, Comedy     6.3    2548
## 18 Animation, Action, Adventure     7.6   11645
## 20 Animation, Adventure, Comedy     7.4   67960
## 21 Animation, Action, Adventure     8.4   41881
## 22 Animation, Action, Adventure     8.4   61931
## 23 Animation, Action, Adventure     7.3   60494
## 24     Animation, Comedy, Drama     8.8  156050
## 25 Animation, Action, Adventure     9.0  203013
## 26            Animation, Comedy     8.2   81343
## 27 Animation, Adventure, Comedy     8.0  497187
## 28 Animation, Adventure, Comedy     7.1  200274
## 29            Animation, Comedy     8.7  368653
## 30   Animation, Family, Fantasy     7.9  339067
## 31 Animation, Action, Adventure     8.4   96880
## 32 Animation, Action, Adventure     8.7  101339
## 33     Animation, Short, Action     8.4  168071
## 35    Animation, Comedy, Family     7.2  218233
## 36 Animation, Action, Adventure     9.3  313079
## 37    Animation, Comedy, Family     3.2     355
## 38 Animation, Action, Adventure     9.0  103990
## 39    Animation, Action, Comedy     8.6  155029
## 40    Animation, Action, Comedy     8.6   31786
## 41 Animation, Adventure, Comedy     6.6   60842
## 42 Animation, Action, Adventure     8.2   55915
## 43 Animation, Adventure, Comedy     8.4  503181
## 44    Animation, Comedy, Family     7.1  170727
## 45            Animation, Comedy     7.4  128206
## 46 Animation, Adventure, Comedy     8.5  237826
## 47            Animation, Family     9.7   10061
## 48  Animation, Adventure, Drama     8.5 1052286
## 49 Animation, Action, Adventure     8.7  135460
## 50    Animation, Action, Comedy     8.6   22796

0.16 Primera forma: Manual

X: Votos Y: Puntaje

recodificacion de variables: En nuestra base de datos original en la columna votos nos salia los valores con coma, para poder trabjar con esa columna, tendriamos usar el siguiente codigo:

 bd <- gsub(","," ", animacion$Votos, fixed = T)
Votos = as.numeric(bd)

pero decidimos cambiar los valores de forma manual en el archivo csv de nuestra base de datos

# Relacion lineal entre las variables

plot(animacion)

#coeficiente de correlacion

cor(animacion$Votos, animacion$Puntaje)
## [1] 0.2676261
prom_x <- mean(animacion$Votos)
prom_x
## [1] 161717.3
prom_y <- mean(animacion$Puntaje)
prom_y
## [1] 8.040426
# sum((xi-prom_X)(yi-prom_Y))

numerador <- sum((animacion$Votos-prom_x)*(animacion$Puntaje-prom_y))
numerador
## [1] 2685379
# sum(xi_prom_x)^2

denominador <- sum((animacion$Votos-prom_x)^2)
denominador
## [1] 1.818912e+12
# b1

b1 <- numerador/denominador
b1
## [1] 1.476366e-06
#b0 = prom_y - b1*prom_x

b0 <- prom_y - b1*prom_x
b0
## [1] 7.801672
# Modelo ajustado
# Modelo: Puntaje = bo + b1*X 
# Modelo: Puntaje = 7.801672 + 1.476366e-06*X

puntaje_pred <- b0+b1*animacion$Votos
puntaje_pred
##  [1] 7.918749 7.856792 7.817340 8.562465 7.803491 7.824837 7.810927 8.301343
##  [9] 7.810174 8.401504 7.836307 8.346855 7.802467 7.986067 7.813751 7.805433
## [17] 7.818864 7.902005 7.863503 7.893104 7.890983 8.032059 8.101393 7.921764
## [25] 8.535701 8.097349 8.345938 8.302259 7.944702 7.951285 8.049806 8.123863
## [33] 8.263891 7.802196 7.955199 8.030551 7.848599 7.891497 7.884223 8.544551
## [41] 8.053727 7.990951 8.152790 7.816525 9.355231 8.001660 7.835327
# JUntar los predichos con la data original
cbind(animacion, puntaje_pred)
##    Puesto                                  Nombre         Año Duracion
## 1       1                               Big Mouth    (2017– )   30 min
## 2       2                            The Bad Guys       -2022  100 min
## 3       3                            Chainsaw Man    (2022– )         
## 4       4                          Rick and Morty    (2013– )   23 min
## 6       6                               Zootopia+    (2022– )         
## 7       7            Star Wars: Tales of the Jedi    (2022– )   15 min
## 8       8                     One Piece Film: Red       -2022  115 min
## 9       9                              Family Guy    (1999– )   22 min
## 10     10                          Wendell & Wild       -2022  105 min
## 11     11                            The Simpsons    (1989– )   22 min
## 12     12                       The Dragon Prince    (2018– )   26 min
## 13     13                         Attack on Titan (2013–2023)   24 min
## 14     14                               Pinocchio (II) (2022)  117 min
## 15     15                               One Piece    (1999– )   24 min
## 16     16         Bleach: Thousand-Year Blood War    (2022– )   24 min
## 17     17                   Lyle, Lyle, Crocodile       -2022  106 min
## 18     18 Miraculous: Tales of Ladybug & Cat Noir    (2015– )   20 min
## 20     20                                  Sing 2       -2021  110 min
## 21     21                  Cyberpunk: Edgerunners    (2022– )   24 min
## 22     22                        My Hero Academia    (2016– )   24 min
## 23     23                              Super Pets       -2022  105 min
## 24     24                         BoJack Horseman (2014–2020)   25 min
## 25     25                                  Arcane    (2021– )   41 min
## 26     26                           Bob's Burgers    (2011– )   22 min
## 27     27                             Zootropolis       -2016  108 min
## 28     28                               Enchanted       -2007  107 min
## 29     29                              South Park    (1997– )   22 min
## 30     30          The Nightmare Before Christmas       -1993   76 min
## 31     31               Star Wars: The Clone Wars (2008–2020)   23 min
## 32     32          Demon Slayer: Kimetsu no Yaiba    (2019– )   24 min
## 33     33                    Love, Death & Robots    (2019– )   15 min
## 35     35                                 Encanto       -2021  102 min
## 36     36              Avatar: The Last Airbender (2005–2008)   23 min
## 37     37               The Soccer Football Movie       -2022   73 min
## 38     38             Batman: The Animated Series (1992–1995)   23 min
## 39     39                                  Archer    (2009– )   22 min
## 40     40                          Mob Psycho 100    (2016– )   24 min
## 41     41                Minions: The Rise of Gru       -2022   87 min
## 42     42                                  Bleach (2004–2012)   24 min
## 43     43                                    Coco  (I) (2017)  105 min
## 44     44                                    Sing       -2016  108 min
## 45     45                           American Dad!    (2005– )   22 min
## 46     46                                Futurama (1999–2023)   22 min
## 47     47                                   Bluey    (2018– )    7 min
## 48     48                           The Lion King       -1994   88 min
## 49     49                              Invincible    (2021– )   50 min
## 50     50                              SPY×FAMILY    (2022– )   24 min
##                          Género Puntaje   Votos puntaje_pred
## 1    Animation, Comedy, Romance     7.9   79301     7.918749
## 2  Animation, Adventure, Comedy     6.8   37335     7.856792
## 3  Animation, Action, Adventure     8.8   10613     7.817340
## 4  Animation, Adventure, Comedy     9.1  515315     8.562465
## 6   Animation, Short, Adventure     6.8    1232     7.803491
## 7      Animation, Short, Action     8.4   15691     7.824837
## 8  Animation, Action, Adventure     6.9    6269     7.810927
## 9             Animation, Comedy     8.2  338447     8.301343
## 10 Animation, Adventure, Comedy     6.5    5759     7.810174
## 11            Animation, Comedy     8.7  406290     8.401504
## 12 Animation, Action, Adventure     8.3   23460     7.836307
## 13 Animation, Action, Adventure     9.0  369274     8.346855
## 14     Animation, Drama, Family     8.0     539     7.802467
## 15 Animation, Action, Adventure     8.9  124898     7.986067
## 16 Animation, Action, Adventure     9.4    8182     7.813751
## 17 Animation, Adventure, Comedy     6.3    2548     7.805433
## 18 Animation, Action, Adventure     7.6   11645     7.818864
## 20 Animation, Adventure, Comedy     7.4   67960     7.902005
## 21 Animation, Action, Adventure     8.4   41881     7.863503
## 22 Animation, Action, Adventure     8.4   61931     7.893104
## 23 Animation, Action, Adventure     7.3   60494     7.890983
## 24     Animation, Comedy, Drama     8.8  156050     8.032059
## 25 Animation, Action, Adventure     9.0  203013     8.101393
## 26            Animation, Comedy     8.2   81343     7.921764
## 27 Animation, Adventure, Comedy     8.0  497187     8.535701
## 28 Animation, Adventure, Comedy     7.1  200274     8.097349
## 29            Animation, Comedy     8.7  368653     8.345938
## 30   Animation, Family, Fantasy     7.9  339067     8.302259
## 31 Animation, Action, Adventure     8.4   96880     7.944702
## 32 Animation, Action, Adventure     8.7  101339     7.951285
## 33     Animation, Short, Action     8.4  168071     8.049806
## 35    Animation, Comedy, Family     7.2  218233     8.123863
## 36 Animation, Action, Adventure     9.3  313079     8.263891
## 37    Animation, Comedy, Family     3.2     355     7.802196
## 38 Animation, Action, Adventure     9.0  103990     7.955199
## 39    Animation, Action, Comedy     8.6  155029     8.030551
## 40    Animation, Action, Comedy     8.6   31786     7.848599
## 41 Animation, Adventure, Comedy     6.6   60842     7.891497
## 42 Animation, Action, Adventure     8.2   55915     7.884223
## 43 Animation, Adventure, Comedy     8.4  503181     8.544551
## 44    Animation, Comedy, Family     7.1  170727     8.053727
## 45            Animation, Comedy     7.4  128206     7.990951
## 46 Animation, Adventure, Comedy     8.5  237826     8.152790
## 47            Animation, Family     9.7   10061     7.816525
## 48  Animation, Adventure, Drama     8.5 1052286     9.355231
## 49 Animation, Action, Adventure     8.7  135460     8.001660
## 50    Animation, Action, Comedy     8.6   22796     7.835327
# Residuales
residuales <- animacion$Puntaje-puntaje_pred
residuales
##  [1] -0.01874894 -1.05679177  0.98265967  0.53753495 -1.00349054  0.57516269
##  [7] -0.91092700 -0.10134320 -1.31017405  0.29849572  0.46369280  0.65314487
## [13]  0.19753258  0.91393322  1.58624872 -1.50543344 -0.21886394 -0.50200547
## [19]  0.53649667  0.50689554 -0.59098293  0.76794147  0.89860691  0.27823633
## [25] -0.53570150 -0.99734932  0.35406169 -0.40225855  0.45529803  0.74871492
## [31]  0.35019408 -0.92386338  1.03610924 -4.60219577  1.04480107  0.56944884
## [37]  0.75140058 -1.29149670  0.31577735 -0.14455083 -0.95372715 -0.59095060
## [43]  0.34721019  1.88347463 -0.85523063  0.69833984  0.76467311
cbind(animacion, puntaje_pred, residuales)
##    Puesto                                  Nombre         Año Duracion
## 1       1                               Big Mouth    (2017– )   30 min
## 2       2                            The Bad Guys       -2022  100 min
## 3       3                            Chainsaw Man    (2022– )         
## 4       4                          Rick and Morty    (2013– )   23 min
## 6       6                               Zootopia+    (2022– )         
## 7       7            Star Wars: Tales of the Jedi    (2022– )   15 min
## 8       8                     One Piece Film: Red       -2022  115 min
## 9       9                              Family Guy    (1999– )   22 min
## 10     10                          Wendell & Wild       -2022  105 min
## 11     11                            The Simpsons    (1989– )   22 min
## 12     12                       The Dragon Prince    (2018– )   26 min
## 13     13                         Attack on Titan (2013–2023)   24 min
## 14     14                               Pinocchio (II) (2022)  117 min
## 15     15                               One Piece    (1999– )   24 min
## 16     16         Bleach: Thousand-Year Blood War    (2022– )   24 min
## 17     17                   Lyle, Lyle, Crocodile       -2022  106 min
## 18     18 Miraculous: Tales of Ladybug & Cat Noir    (2015– )   20 min
## 20     20                                  Sing 2       -2021  110 min
## 21     21                  Cyberpunk: Edgerunners    (2022– )   24 min
## 22     22                        My Hero Academia    (2016– )   24 min
## 23     23                              Super Pets       -2022  105 min
## 24     24                         BoJack Horseman (2014–2020)   25 min
## 25     25                                  Arcane    (2021– )   41 min
## 26     26                           Bob's Burgers    (2011– )   22 min
## 27     27                             Zootropolis       -2016  108 min
## 28     28                               Enchanted       -2007  107 min
## 29     29                              South Park    (1997– )   22 min
## 30     30          The Nightmare Before Christmas       -1993   76 min
## 31     31               Star Wars: The Clone Wars (2008–2020)   23 min
## 32     32          Demon Slayer: Kimetsu no Yaiba    (2019– )   24 min
## 33     33                    Love, Death & Robots    (2019– )   15 min
## 35     35                                 Encanto       -2021  102 min
## 36     36              Avatar: The Last Airbender (2005–2008)   23 min
## 37     37               The Soccer Football Movie       -2022   73 min
## 38     38             Batman: The Animated Series (1992–1995)   23 min
## 39     39                                  Archer    (2009– )   22 min
## 40     40                          Mob Psycho 100    (2016– )   24 min
## 41     41                Minions: The Rise of Gru       -2022   87 min
## 42     42                                  Bleach (2004–2012)   24 min
## 43     43                                    Coco  (I) (2017)  105 min
## 44     44                                    Sing       -2016  108 min
## 45     45                           American Dad!    (2005– )   22 min
## 46     46                                Futurama (1999–2023)   22 min
## 47     47                                   Bluey    (2018– )    7 min
## 48     48                           The Lion King       -1994   88 min
## 49     49                              Invincible    (2021– )   50 min
## 50     50                              SPY×FAMILY    (2022– )   24 min
##                          Género Puntaje   Votos puntaje_pred  residuales
## 1    Animation, Comedy, Romance     7.9   79301     7.918749 -0.01874894
## 2  Animation, Adventure, Comedy     6.8   37335     7.856792 -1.05679177
## 3  Animation, Action, Adventure     8.8   10613     7.817340  0.98265967
## 4  Animation, Adventure, Comedy     9.1  515315     8.562465  0.53753495
## 6   Animation, Short, Adventure     6.8    1232     7.803491 -1.00349054
## 7      Animation, Short, Action     8.4   15691     7.824837  0.57516269
## 8  Animation, Action, Adventure     6.9    6269     7.810927 -0.91092700
## 9             Animation, Comedy     8.2  338447     8.301343 -0.10134320
## 10 Animation, Adventure, Comedy     6.5    5759     7.810174 -1.31017405
## 11            Animation, Comedy     8.7  406290     8.401504  0.29849572
## 12 Animation, Action, Adventure     8.3   23460     7.836307  0.46369280
## 13 Animation, Action, Adventure     9.0  369274     8.346855  0.65314487
## 14     Animation, Drama, Family     8.0     539     7.802467  0.19753258
## 15 Animation, Action, Adventure     8.9  124898     7.986067  0.91393322
## 16 Animation, Action, Adventure     9.4    8182     7.813751  1.58624872
## 17 Animation, Adventure, Comedy     6.3    2548     7.805433 -1.50543344
## 18 Animation, Action, Adventure     7.6   11645     7.818864 -0.21886394
## 20 Animation, Adventure, Comedy     7.4   67960     7.902005 -0.50200547
## 21 Animation, Action, Adventure     8.4   41881     7.863503  0.53649667
## 22 Animation, Action, Adventure     8.4   61931     7.893104  0.50689554
## 23 Animation, Action, Adventure     7.3   60494     7.890983 -0.59098293
## 24     Animation, Comedy, Drama     8.8  156050     8.032059  0.76794147
## 25 Animation, Action, Adventure     9.0  203013     8.101393  0.89860691
## 26            Animation, Comedy     8.2   81343     7.921764  0.27823633
## 27 Animation, Adventure, Comedy     8.0  497187     8.535701 -0.53570150
## 28 Animation, Adventure, Comedy     7.1  200274     8.097349 -0.99734932
## 29            Animation, Comedy     8.7  368653     8.345938  0.35406169
## 30   Animation, Family, Fantasy     7.9  339067     8.302259 -0.40225855
## 31 Animation, Action, Adventure     8.4   96880     7.944702  0.45529803
## 32 Animation, Action, Adventure     8.7  101339     7.951285  0.74871492
## 33     Animation, Short, Action     8.4  168071     8.049806  0.35019408
## 35    Animation, Comedy, Family     7.2  218233     8.123863 -0.92386338
## 36 Animation, Action, Adventure     9.3  313079     8.263891  1.03610924
## 37    Animation, Comedy, Family     3.2     355     7.802196 -4.60219577
## 38 Animation, Action, Adventure     9.0  103990     7.955199  1.04480107
## 39    Animation, Action, Comedy     8.6  155029     8.030551  0.56944884
## 40    Animation, Action, Comedy     8.6   31786     7.848599  0.75140058
## 41 Animation, Adventure, Comedy     6.6   60842     7.891497 -1.29149670
## 42 Animation, Action, Adventure     8.2   55915     7.884223  0.31577735
## 43 Animation, Adventure, Comedy     8.4  503181     8.544551 -0.14455083
## 44    Animation, Comedy, Family     7.1  170727     8.053727 -0.95372715
## 45            Animation, Comedy     7.4  128206     7.990951 -0.59095060
## 46 Animation, Adventure, Comedy     8.5  237826     8.152790  0.34721019
## 47            Animation, Family     9.7   10061     7.816525  1.88347463
## 48  Animation, Adventure, Drama     8.5 1052286     9.355231 -0.85523063
## 49 Animation, Action, Adventure     8.7  135460     8.001660  0.69833984
## 50    Animation, Action, Comedy     8.6   22796     7.835327  0.76467311
# Supuestos
plot(residuales, animacion$Puntaje)

# Normalidad
hist(residuales)

## Pueba de normalidad

# H0: La variable en estudio tiene (se aproxima) un comportamiento normal
# H1: La variable en estudio no tiene (no se aproxima) un comportamiento normal

shapiro.test(residuales)
## 
##  Shapiro-Wilk normality test
## 
## data:  residuales
## W = 0.86259, p-value = 5.63e-05