library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.4.2
## Warning: package 'dplyr' was built under R version 4.4.2
## Warning: package 'forcats' was built under R version 4.4.2
## Warning: package 'lubridate' was built under R version 4.4.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(MASS)
## 
## Adjuntando el paquete: 'MASS'
## The following object is masked from 'package:dplyr':
## 
##     select
library(UsingR)
## Warning: package 'UsingR' was built under R version 4.4.2
## Cargando paquete requerido: HistData
## Warning: package 'HistData' was built under R version 4.4.2
## Cargando paquete requerido: Hmisc
## Warning: package 'Hmisc' was built under R version 4.4.2
## 
## Adjuntando el paquete: 'Hmisc'
## The following objects are masked from 'package:dplyr':
## 
##     src, summarize
## The following objects are masked from 'package:base':
## 
##     format.pval, units
brillo <- data.frame(brightness)
library(readxl)

Se trata de un conjunto de datos de 966 registros

dim(brillo)
## [1] 966   1
  1. Gráfico de frecuencia y densidad
ggplot(data = brillo)+
  aes(x=brillo$brightness, y= ..density..)+
  geom_histogram()+
  geom_density()+
  labs(title = "Brightness vs Frecuency of Stars", x="Brightness", y="Frecuency"
       )
## Warning: The dot-dot notation (`..density..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(density)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: Use of `brillo$brightness` is discouraged.
## ℹ Use `brightness` instead.
## Use of `brillo$brightness` is discouraged.
## ℹ Use `brightness` instead.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

ggplot(brillo, aes(x=brillo$brightness))+
  geom_histogram(aes(y=..density..), fill="blue")+
  geom_density(alpha=.2, fill="red")
## Warning: Use of `brillo$brightness` is discouraged.
## ℹ Use `brightness` instead.
## Use of `brillo$brightness` is discouraged.
## ℹ Use `brightness` instead.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

  1. Diarama de cajas (Boxplot)
boxplot(brillo$brightness, col = palette(rainbow(8)))

  1. Hay valores atípicos, unos muy pequeños y otros muy grandes, como se indica en las pruebas siguientes. Q1 - 1.5RI, valor mínimo esperado Q3 + 1.5RI, valor máximo esperado 7.7:9.7 RI≈ 2 Intervalo Aceptable: (5.7:11) Fuera de esos valores los consideramos externos al rango intercuartílico(*atípicos)
library(outliers)

Menor valor outlier es 2.07, según la prueba de outlier:

grubbs.test(brillo$brightness)
## 
##  Grubbs test for one outlier
## 
## data:  brillo$brightness
## G = 4.90464, U = 0.97505, p-value = 0.0003884
## alternative hypothesis: lowest value 2.07 is an outlier

Mayor valor outlier es 12.43 según la prueba de outlier:

grubbs.test(brillo$brightness, opposite = TRUE)
## 
##  Grubbs test for one outlier
## 
## data:  brillo$brightness
## G = 3.10011, U = 0.99003, p-value = 0.9126
## alternative hypothesis: highest value 12.43 is an outlier
library(EnvStats)
## Warning: package 'EnvStats' was built under R version 4.4.2
## 
## Adjuntando el paquete: 'EnvStats'
## The following object is masked from 'package:Hmisc':
## 
##     stripChart
## The following object is masked from 'package:MASS':
## 
##     boxcox
## The following objects are masked from 'package:stats':
## 
##     predict, predict.lm

Prueba de rosner para outliers:

rosnerTest(brillo$brightness, k=2)
## 
## Results of Outlier Test
## -------------------------
## 
## Test Method:                     Rosner's Test for Outliers
## 
## Hypothesized Distribution:       Normal
## 
## Data:                            brillo$brightness
## 
## Sample Size:                     966
## 
## Test Statistics:                 R.1 = 4.904643
##                                  R.2 = 4.805341
## 
## Test Statistic Parameter:        k = 2
## 
## Alternative Hypothesis:          Up to 2 observations are not
##                                  from the same Distribution.
## 
## Type I Error:                    5%
## 
## Number of Outliers Detected:     2
## 
##   i   Mean.i     SD.i Value Obs.Num    R.i+1 lambda.i+1 Outlier
## 1 0 8.417743 1.294231  2.07     676 4.904643   4.031437    TRUE
## 2 1 8.424321 1.278644  2.28     744 4.805341   4.031181    TRUE
library(EnvStats)

Prueba de rosner para outliers:

rosnerTest(brillo$brightness, k=2)
## 
## Results of Outlier Test
## -------------------------
## 
## Test Method:                     Rosner's Test for Outliers
## 
## Hypothesized Distribution:       Normal
## 
## Data:                            brillo$brightness
## 
## Sample Size:                     966
## 
## Test Statistics:                 R.1 = 4.904643
##                                  R.2 = 4.805341
## 
## Test Statistic Parameter:        k = 2
## 
## Alternative Hypothesis:          Up to 2 observations are not
##                                  from the same Distribution.
## 
## Type I Error:                    5%
## 
## Number of Outliers Detected:     2
## 
##   i   Mean.i     SD.i Value Obs.Num    R.i+1 lambda.i+1 Outlier
## 1 0 8.417743 1.294231  2.07     676 4.904643   4.031437    TRUE
## 2 1 8.424321 1.278644  2.28     744 4.805341   4.031181    TRUE

Respuesta: TRUE. Por lo cual se confirma el resultado de las pruebas anteriores.

  1. Valores No atípicos.
library(rstatix)
## 
## Adjuntando el paquete: 'rstatix'
## The following object is masked from 'package:MASS':
## 
##     select
## The following object is masked from 'package:stats':
## 
##     filter

Tabla de valores outliers y valores extremos

VA <- identify_outliers(brillo)

Extremos: Las posisciones 25 y 28, es decir los valores: 2.07 y 2.28 El resto son outliers que se muestran en la tabla.

VA
##    brightness is.outlier is.extreme
## 1       12.31       TRUE      FALSE
## 2       11.71       TRUE      FALSE
## 3        5.53       TRUE      FALSE
## 4       11.28       TRUE      FALSE
## 5        4.78       TRUE      FALSE
## 6        5.13       TRUE      FALSE
## 7        4.37       TRUE      FALSE
## 8        5.04       TRUE      FALSE
## 9       12.43       TRUE      FALSE
## 10      12.04       TRUE      FALSE
## 11       4.55       TRUE      FALSE
## 12      11.55       TRUE      FALSE
## 13      12.14       TRUE      FALSE
## 14      11.63       TRUE      FALSE
## 15       4.99       TRUE      FALSE
## 16      11.67       TRUE      FALSE
## 17       4.61       TRUE      FALSE
## 18      11.99       TRUE      FALSE
## 19      12.04       TRUE      FALSE
## 20       5.55       TRUE      FALSE
## 21      12.17       TRUE      FALSE
## 22      11.55       TRUE      FALSE
## 23      11.79       TRUE      FALSE
## 24      12.19       TRUE      FALSE
## 25       2.07       TRUE       TRUE
## 26      11.65       TRUE      FALSE
## 27      11.73       TRUE      FALSE
## 28       2.28       TRUE       TRUE
## 29       5.42       TRUE      FALSE
## 30       3.88       TRUE      FALSE
## 31       5.54       TRUE      FALSE
## 32       5.29       TRUE      FALSE
## 33       5.01       TRUE      FALSE
## 34      11.55       TRUE      FALSE
## 35       4.89       TRUE      FALSE
## 36      11.80       TRUE      FALSE
## 37       5.41       TRUE      FALSE
## 38       5.24       TRUE      FALSE
brillo
##     brightness
## 1         9.10
## 2         9.27
## 3         6.61
## 4         8.06
## 5         8.55
## 6        12.31
## 7         9.64
## 8         9.05
## 9         8.59
## 10        8.59
## 11        7.34
## 12        8.43
## 13        8.80
## 14        7.25
## 15        8.60
## 16        8.15
## 17       11.71
## 18       11.03
## 19        6.53
## 20        8.51
## 21        7.55
## 22        8.69
## 23        7.57
## 24        9.05
## 25        6.28
## 26        9.13
## 27        9.32
## 28        8.83
## 29        9.14
## 30        8.26
## 31        7.63
## 32        9.09
## 33        8.10
## 34        6.43
## 35        9.07
## 36        7.68
## 37       10.44
## 38        8.65
## 39        7.46
## 40        8.70
## 41       10.61
## 42        8.20
## 43        6.18
## 44        7.91
## 45        9.59
## 46        8.57
## 47       10.78
## 48        7.31
## 49        9.53
## 50        6.49
## 51        8.94
## 52        8.56
## 53       10.96
## 54       10.57
## 55        7.40
## 56        8.12
## 57        8.27
## 58        7.05
## 59        9.09
## 60        8.34
## 61        8.86
## 62        8.27
## 63        6.36
## 64        8.08
## 65       11.00
## 66        8.55
## 67        7.83
## 68        8.79
## 69        8.33
## 70       10.42
## 71        8.26
## 72        8.97
## 73        6.90
## 74        9.93
## 75        7.42
## 76        9.03
## 77        8.41
## 78        8.06
## 79        8.69
## 80        8.40
## 81        8.57
## 82        9.50
## 83        8.85
## 84        9.61
## 85       10.62
## 86        8.05
## 87        7.80
## 88        5.71
## 89        7.87
## 90        7.64
## 91        7.66
## 92        8.68
## 93        8.12
## 94       10.10
## 95        8.67
## 96       10.46
## 97        9.87
## 98        9.48
## 99        7.04
## 100       8.44
## 101       9.88
## 102       7.05
## 103       8.29
## 104       9.34
## 105       7.73
## 106       6.22
## 107       5.53
## 108       8.53
## 109       7.23
## 110       8.61
## 111      11.28
## 112      10.76
## 113       8.93
## 114       7.95
## 115       7.46
## 116       8.60
## 117       8.55
## 118       9.20
## 119       6.82
## 120       8.29
## 121       6.83
## 122       4.78
## 123       7.21
## 124       5.58
## 125       8.70
## 126       8.06
## 127      10.86
## 128       6.50
## 129       9.32
## 130       9.14
## 131       8.13
## 132      10.62
## 133       6.62
## 134       9.96
## 135       8.64
## 136       6.60
## 137       6.25
## 138       7.83
## 139      10.03
## 140       9.04
## 141       8.47
## 142       7.33
## 143       8.66
## 144      10.35
## 145       5.13
## 146       8.96
## 147       8.49
## 148      11.26
## 149       8.15
## 150       7.04
## 151      10.02
## 152       8.90
## 153       7.78
## 154       4.37
## 155       9.93
## 156       8.60
## 157       8.51
## 158       7.09
## 159       6.93
## 160       8.68
## 161       8.98
## 162       9.84
## 163       8.98
## 164       7.98
## 165      10.16
## 166       8.86
## 167       8.58
## 168       9.56
## 169       9.24
## 170       9.63
## 171       5.80
## 172       9.05
## 173       8.45
## 174       8.86
## 175       7.84
## 176       8.86
## 177       8.93
## 178       7.97
## 179       6.90
## 180       8.47
## 181       6.77
## 182       8.55
## 183       5.04
## 184       8.48
## 185       8.53
## 186       6.33
## 187       8.99
## 188       8.64
## 189       9.55
## 190       8.74
## 191      12.43
## 192       8.16
## 193       9.46
## 194       5.70
## 195       7.62
## 196       8.95
## 197       8.97
## 198       8.94
## 199       7.24
## 200      10.32
## 201       8.24
## 202       8.62
## 203       9.18
## 204       8.53
## 205       8.54
## 206       8.56
## 207       9.41
## 208       5.87
## 209       7.20
## 210       9.05
## 211       9.52
## 212      10.24
## 213       7.70
## 214       8.17
## 215       7.29
## 216       9.26
## 217       7.94
## 218       8.42
## 219       8.56
## 220       7.52
## 221       7.74
## 222       8.85
## 223       9.01
## 224       7.17
## 225       9.04
## 226      10.30
## 227       9.86
## 228       7.64
## 229       8.27
## 230       8.44
## 231       9.58
## 232       8.43
## 233       8.49
## 234       9.64
## 235       9.17
## 236       8.09
## 237       9.00
## 238       6.25
## 239       8.56
## 240      10.81
## 241       8.76
## 242       7.76
## 243       7.82
## 244       7.90
## 245       8.52
## 246       9.73
## 247       9.19
## 248       8.10
## 249       8.75
## 250       8.14
## 251       8.65
## 252      10.30
## 253       6.46
## 254       6.73
## 255       7.96
## 256       9.53
## 257       8.87
## 258       6.59
## 259       8.65
## 260       9.64
## 261       9.15
## 262       9.04
## 263      12.04
## 264       8.42
## 265       8.09
## 266       9.06
## 267       8.09
## 268       8.18
## 269       8.77
## 270       7.36
## 271       9.16
## 272       8.82
## 273      11.14
## 274       6.24
## 275       9.44
## 276       7.49
## 277       6.96
## 278       7.94
## 279       8.69
## 280       8.15
## 281       8.45
## 282       7.92
## 283       7.45
## 284       9.01
## 285       8.55
## 286       9.23
## 287       9.16
## 288       7.90
## 289       8.68
## 290       7.78
## 291       8.21
## 292       8.11
## 293       8.29
## 294       7.89
## 295       9.67
## 296       8.24
## 297       6.80
## 298       8.18
## 299       8.44
## 300       4.55
## 301       7.45
## 302       6.31
## 303       8.15
## 304       8.27
## 305       7.66
## 306       8.59
## 307      11.55
## 308       7.09
## 309       8.54
## 310       9.58
## 311       8.44
## 312       8.59
## 313       8.01
## 314       8.29
## 315       9.62
## 316       7.26
## 317       7.91
## 318       9.45
## 319       8.19
## 320      12.14
## 321       8.93
## 322       7.65
## 323       8.53
## 324       7.38
## 325       8.56
## 326       8.76
## 327       9.56
## 328       7.09
## 329       9.83
## 330       5.90
## 331      10.80
## 332       8.41
## 333       9.05
## 334       8.79
## 335       8.88
## 336       7.59
## 337       9.60
## 338      10.66
## 339       8.55
## 340       8.11
## 341       9.44
## 342       9.60
## 343       5.78
## 344      10.66
## 345       6.38
## 346       8.80
## 347       7.79
## 348       8.60
## 349       7.77
## 350      10.37
## 351       9.80
## 352      10.42
## 353      11.63
## 354       9.22
## 355       4.99
## 356       8.43
## 357       7.33
## 358       8.93
## 359       9.09
## 360       9.26
## 361       8.73
## 362       9.18
## 363       8.12
## 364       9.26
## 365       8.94
## 366       6.11
## 367       9.13
## 368       7.90
## 369       9.34
## 370       7.13
## 371      10.82
## 372       7.46
## 373       8.72
## 374       7.02
## 375       9.08
## 376       8.37
## 377       5.59
## 378       7.37
## 379       5.68
## 380       8.56
## 381       8.72
## 382       9.06
## 383       8.82
## 384       8.18
## 385       9.39
## 386       9.10
## 387       8.46
## 388       9.15
## 389       8.28
## 390      11.67
## 391       8.18
## 392       7.93
## 393       9.21
## 394       6.09
## 395       8.31
## 396       7.83
## 397       8.72
## 398       6.61
## 399       6.25
## 400       7.82
## 401       8.66
## 402       8.15
## 403       8.97
## 404       8.15
## 405       7.47
## 406       8.63
## 407       8.13
## 408       8.23
## 409       8.41
## 410       6.47
## 411       9.83
## 412       8.64
## 413       7.73
## 414       8.64
## 415       8.94
## 416       8.84
## 417       6.32
## 418       5.80
## 419       8.97
## 420       7.53
## 421       7.41
## 422       7.80
## 423       8.14
## 424       6.71
## 425       8.73
## 426       9.37
## 427       8.69
## 428       9.95
## 429       7.10
## 430       8.09
## 431       6.88
## 432       9.48
## 433       9.04
## 434       9.30
## 435       8.49
## 436       8.30
## 437       7.95
## 438       7.08
## 439       6.93
## 440       8.38
## 441       4.61
## 442       8.56
## 443       8.78
## 444       7.42
## 445       8.26
## 446       7.71
## 447       6.91
## 448       9.16
## 449       8.99
## 450       8.63
## 451       9.90
## 452       7.59
## 453       7.39
## 454      11.99
## 455       7.78
## 456       7.47
## 457       6.97
## 458       8.82
## 459       9.13
## 460       7.86
## 461       7.13
## 462       9.45
## 463      12.04
## 464       8.78
## 465       7.23
## 466       9.73
## 467       7.36
## 468       7.36
## 469       8.47
## 470       9.37
## 471       6.99
## 472       8.20
## 473       8.36
## 474       8.22
## 475       5.55
## 476       9.91
## 477       9.67
## 478       8.60
## 479      10.07
## 480      10.15
## 481       7.75
## 482       9.21
## 483       9.66
## 484       8.47
## 485       9.37
## 486       9.44
## 487       9.99
## 488      10.38
## 489       7.51
## 490       8.91
## 491       7.45
## 492       9.57
## 493       8.99
## 494       8.58
## 495       6.90
## 496       7.55
## 497       7.93
## 498       9.71
## 499       9.57
## 500       8.55
## 501       6.62
## 502       7.89
## 503       7.51
## 504       7.36
## 505       8.66
## 506       8.51
## 507       6.65
## 508       9.67
## 509       7.80
## 510       8.21
## 511       7.90
## 512       8.94
## 513       9.82
## 514       8.69
## 515       8.57
## 516       8.89
## 517       5.98
## 518       7.92
## 519       7.60
## 520       8.22
## 521       5.70
## 522      12.17
## 523       8.75
## 524       6.93
## 525       7.97
## 526       8.06
## 527      10.13
## 528       7.31
## 529       8.35
## 530       5.57
## 531       9.85
## 532       9.16
## 533       9.03
## 534      10.07
## 535       9.76
## 536       9.35
## 537      10.95
## 538       8.87
## 539       6.68
## 540       9.69
## 541       8.05
## 542      10.30
## 543       6.07
## 544       8.51
## 545       7.71
## 546       8.56
## 547       8.26
## 548      11.55
## 549       8.62
## 550      10.92
## 551      10.51
## 552       9.83
## 553       9.84
## 554       9.74
## 555       8.21
## 556       8.72
## 557       8.03
## 558       9.00
## 559       6.19
## 560      11.79
## 561       8.22
## 562       7.93
## 563      10.18
## 564       8.98
## 565       9.13
## 566       6.91
## 567       8.79
## 568       8.23
## 569      12.19
## 570      10.24
## 571       8.83
## 572       7.62
## 573       8.96
## 574      10.41
## 575       8.97
## 576       9.61
## 577       8.29
## 578       8.30
## 579       8.26
## 580       7.44
## 581       9.52
## 582       8.20
## 583       8.68
## 584       8.65
## 585      10.52
## 586       8.41
## 587       9.18
## 588       8.42
## 589       8.86
## 590       7.92
## 591      10.97
## 592       8.85
## 593       9.31
## 594      10.28
## 595       7.56
## 596       7.88
## 597       7.99
## 598       8.23
## 599       8.52
## 600       9.14
## 601       6.20
## 602       7.64
## 603       8.95
## 604       7.48
## 605       7.06
## 606       7.33
## 607       8.98
## 608       8.24
## 609       8.53
## 610       8.40
## 611       7.48
## 612       8.46
## 613       9.29
## 614       8.57
## 615       8.70
## 616       8.50
## 617       8.37
## 618       6.87
## 619       7.50
## 620       7.39
## 621       8.19
## 622       7.56
## 623       8.37
## 624       7.39
## 625       6.73
## 626       8.66
## 627       8.25
## 628       8.47
## 629       8.01
## 630       6.83
## 631       9.06
## 632       8.79
## 633       7.44
## 634       6.43
## 635       5.93
## 636       8.85
## 637       9.86
## 638       8.55
## 639       7.66
## 640       7.82
## 641       9.08
## 642      10.10
## 643       8.21
## 644       8.85
## 645       7.79
## 646       7.58
## 647       7.85
## 648       7.18
## 649       7.54
## 650       9.72
## 651       7.12
## 652       9.77
## 653       8.84
## 654       5.67
## 655       8.15
## 656       9.61
## 657       8.19
## 658       7.27
## 659       8.51
## 660       8.36
## 661      10.00
## 662       8.74
## 663       6.18
## 664      10.26
## 665      10.16
## 666       8.31
## 667       8.58
## 668       7.04
## 669       8.81
## 670       5.99
## 671       8.22
## 672       9.86
## 673       8.00
## 674       9.40
## 675       9.10
## 676       2.07
## 677       8.11
## 678       8.89
## 679       9.43
## 680       7.59
## 681       8.72
## 682       9.86
## 683       9.23
## 684       9.50
## 685      10.73
## 686       7.59
## 687       7.41
## 688       9.26
## 689       7.78
## 690       7.76
## 691       8.94
## 692       8.95
## 693       6.41
## 694       6.11
## 695       7.76
## 696       7.38
## 697       6.21
## 698       7.05
## 699       7.44
## 700       8.50
## 701       7.84
## 702      11.01
## 703       7.88
## 704       9.10
## 705       8.65
## 706       8.41
## 707       7.81
## 708       7.43
## 709       8.76
## 710       7.58
## 711       9.55
## 712       6.82
## 713      10.24
## 714       6.24
## 715       7.31
## 716      10.52
## 717       9.27
## 718       7.13
## 719       9.14
## 720       8.48
## 721       8.57
## 722       7.21
## 723       9.05
## 724       7.72
## 725       8.03
## 726       6.47
## 727       5.57
## 728       6.32
## 729       7.78
## 730      11.65
## 731       8.58
## 732      10.37
## 733       9.23
## 734       9.20
## 735       6.93
## 736      11.73
## 737       9.32
## 738       7.11
## 739       9.79
## 740       8.21
## 741       8.42
## 742       7.05
## 743       9.26
## 744       2.28
## 745       8.77
## 746       9.25
## 747       9.30
## 748      10.63
## 749       9.90
## 750       9.89
## 751       9.33
## 752       7.78
## 753       7.02
## 754      11.26
## 755       8.89
## 756       9.60
## 757       7.07
## 758       6.01
## 759       5.42
## 760       9.11
## 761       8.24
## 762       8.97
## 763       3.88
## 764       8.59
## 765       7.17
## 766       7.94
## 767       7.27
## 768       9.59
## 769       7.94
## 770       8.52
## 771       7.59
## 772       9.17
## 773       8.08
## 774       9.80
## 775       8.92
## 776       9.91
## 777       9.42
## 778       8.84
## 779      10.15
## 780       8.37
## 781       9.33
## 782       9.35
## 783       7.40
## 784       8.35
## 785       9.53
## 786       9.59
## 787      10.05
## 788       8.57
## 789       8.48
## 790       8.43
## 791       8.45
## 792       8.84
## 793      11.18
## 794       8.64
## 795       8.42
## 796       6.34
## 797       7.93
## 798       8.36
## 799       8.32
## 800       7.77
## 801       6.84
## 802       8.78
## 803       7.19
## 804       8.50
## 805       8.82
## 806       9.04
## 807       7.93
## 808       7.66
## 809      10.07
## 810       9.03
## 811       5.54
## 812       5.29
## 813       8.13
## 814       7.51
## 815       9.08
## 816       7.10
## 817       7.88
## 818       9.40
## 819       9.06
## 820       8.38
## 821      10.65
## 822       7.77
## 823       8.50
## 824       8.61
## 825      10.05
## 826       8.71
## 827       9.37
## 828       6.97
## 829       8.56
## 830       9.34
## 831       9.47
## 832       8.11
## 833       8.91
## 834       7.83
## 835       8.95
## 836       7.20
## 837       9.37
## 838       5.84
## 839       5.01
## 840       9.81
## 841       9.27
## 842       9.50
## 843       9.32
## 844       8.92
## 845       8.38
## 846       7.74
## 847       8.60
## 848       9.49
## 849       8.35
## 850       7.11
## 851       9.87
## 852       8.98
## 853       7.75
## 854       8.24
## 855       6.74
## 856       6.83
## 857       7.70
## 858       6.70
## 859       8.67
## 860       9.94
## 861       8.73
## 862       9.63
## 863       6.66
## 864       8.29
## 865       8.47
## 866       8.16
## 867       8.97
## 868       7.51
## 869       8.97
## 870       8.55
## 871       5.84
## 872       7.85
## 873       8.68
## 874       8.05
## 875       8.27
## 876       7.68
## 877       9.40
## 878       7.77
## 879       6.89
## 880       7.55
## 881       8.27
## 882       8.16
## 883       8.07
## 884       7.91
## 885       7.71
## 886      10.16
## 887       8.41
## 888       8.88
## 889       9.64
## 890       7.93
## 891       7.78
## 892       8.90
## 893       8.55
## 894       9.15
## 895      10.86
## 896      11.55
## 897       9.08
## 898       7.44
## 899      10.35
## 900       6.68
## 901       8.85
## 902       8.90
## 903       8.24
## 904       6.74
## 905      10.75
## 906       8.44
## 907       7.69
## 908       4.89
## 909      11.80
## 910       8.88
## 911       7.70
## 912       8.60
## 913       8.44
## 914       9.50
## 915       9.03
## 916       7.15
## 917       7.95
## 918       8.23
## 919       9.81
## 920       8.48
## 921       9.33
## 922       8.97
## 923       8.08
## 924       7.47
## 925       8.34
## 926       7.75
## 927       8.34
## 928       5.41
## 929       7.56
## 930       6.93
## 931      10.03
## 932       8.69
## 933       9.04
## 934       8.32
## 935       7.85
## 936       7.21
## 937       8.98
## 938       7.09
## 939       8.85
## 940       9.21
## 941       8.61
## 942       7.91
## 943       7.47
## 944       8.65
## 945       8.53
## 946       9.92
## 947       8.09
## 948       5.24
## 949       7.06
## 950       8.45
## 951       8.73
## 952       7.45
## 953       9.02
## 954       7.51
## 955       7.32
## 956       8.17
## 957       9.45
## 958       9.72
## 959       9.34
## 960       8.75
## 961       9.32
## 962       7.91
## 963       7.49
## 964       6.53
## 965       6.18
## 966       8.69

Identificados los outliers

#brightness.without <- brillo[-C(6,17,107,111,122,145,154,183,191,263,300,307,320,353,355,390,441,454,463,475,522,548,560,569,676,730,736,744,759,763,811,812,839,896,908,909,928,948),]
#brillo%<%identify_outliers(brillo$brightness)
  1. UScereal
UScereal
##                                       mfr  calories    protein       fat
## 100% Bran                               N 212.12121 12.1212121 3.0303030
## All-Bran                                K 212.12121 12.1212121 3.0303030
## All-Bran with Extra Fiber               K 100.00000  8.0000000 0.0000000
## Apple Cinnamon Cheerios                 G 146.66667  2.6666667 2.6666667
## Apple Jacks                             K 110.00000  2.0000000 0.0000000
## Basic 4                                 G 173.33333  4.0000000 2.6666667
## Bran Chex                               R 134.32836  2.9850746 1.4925373
## Bran Flakes                             P 134.32836  4.4776119 0.0000000
## Cap'n'Crunch                            Q 160.00000  1.3333333 2.6666667
## Cheerios                                G  88.00000  4.8000000 1.6000000
## Cinnamon Toast Crunch                   G 160.00000  1.3333333 4.0000000
## Clusters                                G 220.00000  6.0000000 4.0000000
## Cocoa Puffs                             G 110.00000  1.0000000 1.0000000
## Corn Chex                               R 110.00000  2.0000000 0.0000000
## Corn Flakes                             K 100.00000  2.0000000 0.0000000
## Corn Pops                               K 110.00000  1.0000000 0.0000000
## Count Chocula                           G 110.00000  1.0000000 1.0000000
## Cracklin' Oat Bran                      K 220.00000  6.0000000 6.0000000
## Crispix                                 K 110.00000  2.0000000 0.0000000
## Crispy Wheat & Raisins                  G 133.33333  2.6666667 1.3333333
## Double Chex                             R 133.33333  2.6666667 0.0000000
## Froot Loops                             K 110.00000  2.0000000 1.0000000
## Frosted Flakes                          K 146.66667  1.3333333 0.0000000
## Frosted Mini-Wheats                     K 125.00000  3.7500000 0.0000000
## Fruit & Fibre: Dates Walnuts and Oats   P 179.10448  4.4776119 2.9850746
## Fruitful Bran                           K 179.10448  4.4776119 0.0000000
## Fruity Pebbles                          P 146.66667  1.3333333 1.3333333
## Golden Crisp                            P 113.63636  2.2727273 0.0000000
## Golden Grahams                          G 146.66667  1.3333333 1.3333333
## Grape Nuts Flakes                       P 113.63636  3.4090909 1.1363636
## Grape-Nuts                              P 440.00000 12.0000000 0.0000000
## Great Grains Pecan                      P 363.63636  9.0909091 9.0909091
## Honey Graham Ohs                        Q 120.00000  1.0000000 2.0000000
## Honey Nut Cheerios                      G 146.66667  4.0000000 1.3333333
## Honey-comb                              P  82.70677  0.7518797 0.0000000
## Just Right Fruit & Nut                  K 186.66667  4.0000000 1.3333333
## Kix                                     G  73.33333  1.3333333 0.6666667
## Life                                    Q 149.25373  5.9701493 2.9850746
## Lucky Charms                            G 110.00000  2.0000000 1.0000000
## Mueslix Crispy Blend                    K 238.80597  4.4776119 2.9850746
## Multi-Grain Cheerios                    G 100.00000  2.0000000 1.0000000
## Nut&Honey Crunch                        K 179.10448  2.9850746 1.4925373
## Nutri-Grain Almond-Raisin               K 208.95522  4.4776119 2.9850746
## Oatmeal Raisin Crisp                    G 260.00000  6.0000000 4.0000000
## Post Nat. Raisin Bran                   P 179.10448  4.4776119 1.4925373
## Product 19                              K 100.00000  3.0000000 0.0000000
## Puffed Rice                             Q  50.00000  1.0000000 0.0000000
## Quaker Oat Squares                      Q 200.00000  8.0000000 2.0000000
## Raisin Bran                             K 160.00000  4.0000000 1.3333333
## Raisin Nut Bran                         G 200.00000  6.0000000 4.0000000
## Raisin Squares                          K 180.00000  4.0000000 0.0000000
## Rice Chex                               R  97.34513  0.8849558 0.0000000
## Rice Krispies                           K 110.00000  2.0000000 0.0000000
## Shredded Wheat 'n'Bran                  N 134.32836  4.4776119 0.0000000
## Shredded Wheat spoon size               N 134.32836  4.4776119 0.0000000
## Smacks                                  K 146.66667  2.6666667 1.3333333
## Special K                               K 110.00000  6.0000000 0.0000000
## Total Corn Flakes                       G 110.00000  2.0000000 1.0000000
## Total Raisin Bran                       G 140.00000  3.0000000 1.0000000
## Total Whole Grain                       G 100.00000  3.0000000 1.0000000
## Triples                                 G 146.66667  2.6666667 1.3333333
## Trix                                    G 110.00000  1.0000000 1.0000000
## Wheat Chex                              R 149.25373  4.4776119 1.4925373
## Wheaties                                G 100.00000  3.0000000 1.0000000
## Wheaties Honey Gold                     G 146.66667  2.6666667 1.3333333
##                                          sodium     fibre    carbo    sugars
## 100% Bran                             393.93939 30.303030 15.15152 18.181818
## All-Bran                              787.87879 27.272727 21.21212 15.151515
## All-Bran with Extra Fiber             280.00000 28.000000 16.00000  0.000000
## Apple Cinnamon Cheerios               240.00000  2.000000 14.00000 13.333333
## Apple Jacks                           125.00000  1.000000 11.00000 14.000000
## Basic 4                               280.00000  2.666667 24.00000 10.666667
## Bran Chex                             298.50746  5.970149 22.38806  8.955224
## Bran Flakes                           313.43284  7.462687 19.40299  7.462687
## Cap'n'Crunch                          293.33333  0.000000 16.00000 16.000000
## Cheerios                              232.00000  1.600000 13.60000  0.800000
## Cinnamon Toast Crunch                 280.00000  0.000000 17.33333 12.000000
## Clusters                              280.00000  4.000000 26.00000 14.000000
## Cocoa Puffs                           180.00000  0.000000 12.00000 13.000000
## Corn Chex                             280.00000  0.000000 22.00000  3.000000
## Corn Flakes                           290.00000  1.000000 21.00000  2.000000
## Corn Pops                              90.00000  1.000000 13.00000 12.000000
## Count Chocula                         180.00000  0.000000 12.00000 13.000000
## Cracklin' Oat Bran                    280.00000  8.000000 20.00000 14.000000
## Crispix                               220.00000  1.000000 21.00000  3.000000
## Crispy Wheat & Raisins                186.66667  2.666667 14.66667 13.333333
## Double Chex                           253.33333  1.333333 24.00000  6.666667
## Froot Loops                           125.00000  1.000000 11.00000 13.000000
## Frosted Flakes                        266.66667  1.333333 18.66667 14.666667
## Frosted Mini-Wheats                     0.00000  3.750000 17.50000  8.750000
## Fruit & Fibre: Dates Walnuts and Oats 238.80597  7.462687 17.91045 14.925373
## Fruitful Bran                         358.20896  7.462687 20.89552 17.910448
## Fruity Pebbles                        180.00000  0.000000 17.33333 16.000000
## Golden Crisp                           51.13636  0.000000 12.50000 17.045455
## Golden Grahams                        373.33333  0.000000 20.00000 12.000000
## Grape Nuts Flakes                     159.09091  3.409091 17.04545  5.681818
## Grape-Nuts                            680.00000 12.000000 68.00000 12.000000
## Great Grains Pecan                    227.27273  9.090909 39.39394 12.121212
## Honey Graham Ohs                      220.00000  1.000000 12.00000 11.000000
## Honey Nut Cheerios                    333.33333  2.000000 15.33333 13.333333
## Honey-comb                            135.33835  0.000000 10.52632  8.270677
## Just Right Fruit & Nut                226.66667  2.666667 26.66667 12.000000
## Kix                                   173.33333  0.000000 14.00000  2.000000
## Life                                  223.88060  2.985075 17.91045  8.955224
## Lucky Charms                          180.00000  0.000000 12.00000 12.000000
## Mueslix Crispy Blend                  223.88060  4.477612 25.37313 19.402985
## Multi-Grain Cheerios                  220.00000  2.000000 15.00000  6.000000
## Nut&Honey Crunch                      283.58209  0.000000 22.38806 13.432836
## Nutri-Grain Almond-Raisin             328.35821  4.477612 31.34328 10.447761
## Oatmeal Raisin Crisp                  340.00000  3.000000 27.00000 20.000000
## Post Nat. Raisin Bran                 298.50746  8.955224 16.41791 20.895522
## Product 19                            320.00000  1.000000 20.00000  3.000000
## Puffed Rice                             0.00000  0.000000 13.00000  0.000000
## Quaker Oat Squares                    270.00000  4.000000 28.00000 12.000000
## Raisin Bran                           280.00000  6.666667 18.66667 16.000000
## Raisin Nut Bran                       280.00000  5.000000 21.00000 16.000000
## Raisin Squares                          0.00000  4.000000 30.00000 12.000000
## Rice Chex                             212.38938  0.000000 20.35398  1.769912
## Rice Krispies                         290.00000  0.000000 22.00000  3.000000
## Shredded Wheat 'n'Bran                  0.00000  5.970149 28.35821  0.000000
## Shredded Wheat spoon size               0.00000  4.477612 29.85075  0.000000
## Smacks                                 93.33333  1.333333 12.00000 20.000000
## Special K                             230.00000  1.000000 16.00000  3.000000
## Total Corn Flakes                     200.00000  0.000000 21.00000  3.000000
## Total Raisin Bran                     190.00000  4.000000 15.00000 14.000000
## Total Whole Grain                     200.00000  3.000000 16.00000  3.000000
## Triples                               333.33333  0.000000 28.00000  4.000000
## Trix                                  140.00000  0.000000 13.00000 12.000000
## Wheat Chex                            343.28358  4.477612 25.37313  4.477612
## Wheaties                              200.00000  3.000000 17.00000  3.000000
## Wheaties Honey Gold                   266.66667  1.333333 21.33333 10.666667
##                                       shelf potassium vitamins
## 100% Bran                                 3 848.48485 enriched
## All-Bran                                  3 969.69697 enriched
## All-Bran with Extra Fiber                 3 660.00000 enriched
## Apple Cinnamon Cheerios                   1  93.33333 enriched
## Apple Jacks                               2  30.00000 enriched
## Basic 4                                   3 133.33333 enriched
## Bran Chex                                 1 186.56716 enriched
## Bran Flakes                               3 283.58209 enriched
## Cap'n'Crunch                              2  46.66667 enriched
## Cheerios                                  1  84.00000 enriched
## Cinnamon Toast Crunch                     2  60.00000 enriched
## Clusters                                  3 210.00000 enriched
## Cocoa Puffs                               2  55.00000 enriched
## Corn Chex                                 1  25.00000 enriched
## Corn Flakes                               1  35.00000 enriched
## Corn Pops                                 2  20.00000 enriched
## Count Chocula                             2  65.00000 enriched
## Cracklin' Oat Bran                        3 320.00000 enriched
## Crispix                                   3  30.00000 enriched
## Crispy Wheat & Raisins                    3 160.00000 enriched
## Double Chex                               3 106.66667 enriched
## Froot Loops                               2  30.00000 enriched
## Frosted Flakes                            1  33.33333 enriched
## Frosted Mini-Wheats                       2 125.00000 enriched
## Fruit & Fibre: Dates Walnuts and Oats     3 298.50746 enriched
## Fruitful Bran                             3 283.58209 enriched
## Fruity Pebbles                            2  33.33333 enriched
## Golden Crisp                              1  45.45455 enriched
## Golden Grahams                            2  60.00000 enriched
## Grape Nuts Flakes                         3  96.59091 enriched
## Grape-Nuts                                3 360.00000 enriched
## Great Grains Pecan                        3 303.03030 enriched
## Honey Graham Ohs                          2  45.00000 enriched
## Honey Nut Cheerios                        1 120.00000 enriched
## Honey-comb                                1  26.31579 enriched
## Just Right Fruit & Nut                    3 126.66667     100%
## Kix                                       2  26.66667 enriched
## Life                                      2 141.79104 enriched
## Lucky Charms                              2  55.00000 enriched
## Mueslix Crispy Blend                      3 238.80597 enriched
## Multi-Grain Cheerios                      1  90.00000 enriched
## Nut&Honey Crunch                          2  59.70149 enriched
## Nutri-Grain Almond-Raisin                 3 194.02985 enriched
## Oatmeal Raisin Crisp                      3 240.00000 enriched
## Post Nat. Raisin Bran                     3 388.05970 enriched
## Product 19                                3  45.00000     100%
## Puffed Rice                               3  15.00000     none
## Quaker Oat Squares                        3 220.00000 enriched
## Raisin Bran                               2 320.00000 enriched
## Raisin Nut Bran                           3 280.00000 enriched
## Raisin Squares                            3 220.00000 enriched
## Rice Chex                                 1  26.54867 enriched
## Rice Krispies                             1  35.00000 enriched
## Shredded Wheat 'n'Bran                    1 208.95522     none
## Shredded Wheat spoon size                 1 179.10448     none
## Smacks                                    2  53.33333 enriched
## Special K                                 1  55.00000 enriched
## Total Corn Flakes                         3  35.00000     100%
## Total Raisin Bran                         3 230.00000     100%
## Total Whole Grain                         3 110.00000     100%
## Triples                                   3  80.00000 enriched
## Trix                                      2  25.00000 enriched
## Wheat Chex                                1 171.64179 enriched
## Wheaties                                  1 110.00000 enriched
## Wheaties Honey Gold                       1  80.00000 enriched
dim(UScereal)
## [1] 65 11
view(UScereal)
class(UScereal)
## [1] "data.frame"

UScereal es un conjunto de datos en formato dataframe de 65 registros X 11 variables.

library(readxl)
UScerealMOD <- read_excel("C:/Users/admin/Desktop/UScerealMOD.xlsx")
View(UScerealMOD)
UScerealMOD1 <- UScerealMOD[,-c(1)]
UScerealMOD1 <- scale(UScerealMOD1)
cor(UScerealMOD1)
##                   mfr    calories     protein        fat      sodium
## mfr        1.00000000  0.07368375 -0.06138204  0.1394717  0.06506238
## calories   0.07368375  1.00000000  0.70601046  0.5901757  0.52865521
## protein   -0.06138204  0.70601046  1.00000000  0.4112661  0.57272218
## fat        0.13947168  0.59017565  0.41126609  1.0000000  0.25956061
## sodium     0.06506238  0.52865521  0.57272218  0.2595606  1.00000000
## fibre     -0.18892655  0.38821786  0.80963967  0.2260715  0.49548309
## carbo      0.02102933  0.78872268  0.54709029  0.1828522  0.42356172
## sugars     0.06457892  0.49529421  0.18484845  0.4156740  0.21124365
## shelf      0.02171155  0.42634004  0.39633111  0.3256975  0.23412749
## potassium -0.16331472  0.47659552  0.84175404  0.3232754  0.55664265
## vitamins  -0.14642588 -0.19020808 -0.06820574 -0.2206739 -0.36388041
##                 fibre       carbo      sugars      shelf   potassium
## mfr       -0.18892655  0.02102933  0.06457892 0.02171155 -0.16331472
## calories   0.38821786  0.78872268  0.49529421 0.42634004  0.47659552
## protein    0.80963967  0.54709029  0.18484845 0.39633111  0.84175404
## fat        0.22607148  0.18285220  0.41567397 0.32569752  0.32327538
## sodium     0.49548309  0.42356172  0.21124365 0.23412749  0.55664265
## fibre      1.00000000  0.20307489  0.14891577 0.35784289  0.96386621
## carbo      0.20307489  1.00000000 -0.04082599 0.26045989  0.24204848
## sugars     0.14891577 -0.04082599  1.00000000 0.29005112  0.27183347
## shelf      0.35784289  0.26045989  0.29005112 1.00000000  0.42625294
## potassium  0.96386621  0.24204848  0.27183347 0.42625294  1.00000000
## vitamins  -0.05770782  0.08134011 -0.41600466 0.04355160 -0.07083895
##              vitamins
## mfr       -0.14642588
## calories  -0.19020808
## protein   -0.06820574
## fat       -0.22067394
## sodium    -0.36388041
## fibre     -0.05770782
## carbo      0.08134011
## sugars    -0.41600466
## shelf      0.04355160
## potassium -0.07083895
## vitamins   1.00000000
correlac <- cor(UScerealMOD1)
library(ggplot2)
library(corrplot)
## corrplot 0.92 loaded
corrplot(correlac, method = "shade", shade.col = NA, tl.col = "black", tl.srt = 45)

col <- colorRampPalette(c("#BB4444", "#EE9988", "#FFFFFF", "#77AADD", "#4477AA"))

Matriz de correlaciones

corrplot(correlac, method = "shade", sade.col=NA, tl.col = "black", tl.srt = 45, col=col(200), addCoef.col = "black",addcolorlabel="no", order="AOE", type = "upper", diag = F, addshade = "all" )
## Warning in text.default(pos.xlabel[, 1], pos.xlabel[, 2], newcolnames, srt =
## tl.srt, : "sade.col" es un parámetro gráfico inválido
## Warning in text.default(pos.xlabel[, 1], pos.xlabel[, 2], newcolnames, srt =
## tl.srt, : "addcolorlabel" es un parámetro gráfico inválido
## Warning in text.default(pos.ylabel[, 1], pos.ylabel[, 2], newrownames, col =
## tl.col, : "sade.col" es un parámetro gráfico inválido
## Warning in text.default(pos.ylabel[, 1], pos.ylabel[, 2], newrownames, col =
## tl.col, : "addcolorlabel" es un parámetro gráfico inválido
## Warning in title(title, ...): "sade.col" es un parámetro gráfico inválido
## Warning in title(title, ...): "addcolorlabel" es un parámetro gráfico inválido

Conjunto de datos de cereales para desayunos. Contiene valores numéricos relacionados con la marca de cereal, su calidad y nutrición. Se analian esas relaciones. Relaciones: En gráfico las correlaciones directas se representan en color azul. Las inversas en rojo. 0.02 i. Manufactura y Shelf: la relación entre estas variables tiende a ser directa pero es baja ii. fat y vitamins: es inversamente proporcional. 0.22 iii. fat y Shelf: es directa; 0.33 iv. carbohydrates & sugars: inversa pero baja; 0.04 v. fibre & manufacturer: es inversa y baja; 0.19 vi. sodium & sugars;relación directa al 21%

2.9. Uso del paquete pwr. Análisis de correlaciones Ejemplo: Se quiere analizar el tamaño de la muestra para un ensayo clínico relacionado con un tratamiento que queremos disponer el prpoximo año. Con un nivel de significancia de 5%, partiendo de que el efecto mínimo es de 40%. Necesitamos determinar el tamaño muestral con un poder del 90%

library(pwr)
muestra <- pwr.r.test(r=0.4,
           sig.level = 0.05,
           power = 0.90)

La relación se representa en el gráfico de poder estadístico

muestra
## 
##      approximate correlation power calculation (arctangh transformation) 
## 
##               n = 60.70866
##               r = 0.4
##       sig.level = 0.05
##           power = 0.9
##     alternative = two.sided
plot(muestra)

De acuerdo con el resultado de la prueba se requiere al menos 61 participantes en el ensayo clinico.

Luego de las pruebas iniciales se requiere mejorar el efecto y se proyecta a 70%. Calculamos el tamaños de la muestra para para los parámetros anteriores.

muestra1 <- pwr.r.test(r=0.7,
           sig.level = 0.05,
           power = 0.90)
muestra1
## 
##      approximate correlation power calculation (arctangh transformation) 
## 
##               n = 16.32292
##               r = 0.7
##       sig.level = 0.05
##           power = 0.9
##     alternative = two.sided

Ahora se requiere un tamaño de muetsra más pequeño, pasando de 61 participantes a 17.

2.10. Ejemplo de caso de uso en la tesis. Ver archivo adjunto de nombre: “AnalisisFactorialDepresionTOPICOS”