Actividad #2.1
Punto A:
x= c(1,3,5,7,9)
x
## [1] 1 3 5 7 9
Punto B:
y=c(2,4,6,7,11,12)
y
## [1] 2 4 6 7 11 12
Punto C:
x + 1
## [1] 2 4 6 8 10
Punto D:
y*2
## [1] 4 8 12 14 22 24
Punto E:
length(x)
## [1] 5
length(y)
## [1] 6
Punto F:
x+y
## Warning in x + y: longitud de objeto mayor no es múltiplo de la longitud de uno
## menor
## [1] 3 7 11 14 20 13
Punto G:
sum(x>5)
## [1] 2
sum(x[x>5])
## [1] 16
Punto H:
sum(x>5 | x< 3)
## [1] 3
Punto I:
y[2]
## [1] 4
Punto J:
y[-2]
## [1] 2 6 7 11 12
Punto K:
y[x]
## [1] 2 6 11 NA NA
Punto L: ¿Que significa NA?)
"NA: se usa para representar cualquier valor 'no disponible' u 'olvidado'"
## [1] "NA: se usa para representar cualquier valor 'no disponible' u 'olvidado'"
Punto M:
y[y>=8]
## [1] 11 12
Actividad #2.2:
Punto A:
millas= c(65241,65665,65998,66014,66547,66857,67025,67447,66958,67002)
Punto B:
mks= millas*1609
mks
## [1] 104972769 105654985 106190782 106216526 107074123 107572913 107843225
## [8] 108522223 107735422 107806218
Punto C:
diff(mks)
## [1] 682216 535797 25744 857597 498790 270312 678998 -786801 70796
Punto D:
summary(mks)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 104972769 106197218 107323518 106958919 107788519 108522223
Actividad #2.3
facturas = c(47,32,40,36,49,31,49,30,49,35,48,32)
mes = c("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre")
Punto A:
sum(facturas)
## [1] 478
Punto B:
mean(facturas)
## [1] 39.83333
Punto C:
min(facturas)
## [1] 30
max(facturas)
## [1] 49
Punto D:
matriz_col = cbind(facturas,mes)
matriz_col
## facturas mes
## [1,] "47" "Enero"
## [2,] "32" "Febrero"
## [3,] "40" "Marzo"
## [4,] "36" "Abril"
## [5,] "49" "Mayo"
## [6,] "31" "Junio"
## [7,] "49" "Julio"
## [8,] "30" "Agosto"
## [9,] "49" "Septiembre"
## [10,] "35" "Octubre"
## [11,] "48" "Noviembre"
## [12,] "32" "Diciembre"
Punto E:
sum(facturas>40)
## [1] 5
Punto F:
sum_meses = sum(facturas[facturas>40])
sum_total = sum(facturas)
por_total = ((sum_meses*100)/sum_total)
por_total
## [1] 50.62762
Actividad #2.4
datos =c(61,88,73,49,41,72,99,07,12,13,87,91,05,17,97)
names(datos)=c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
Punto A: Diagrama Porcentual
hist(datos, main = "Diagrama porcentual", labels = paste(datos,"%"))
Punto B:
head(datos)
## 1 2 3 4 5 6
## 61 88 73 49 41 72
summary(datos)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 5.00 15.00 61.00 54.13 87.50 99.00
fivenum(datos)
## 13 10 1 11 7
## 5.0 15.0 61.0 87.5 99.0
Punto C: ¿Qué diferencias hay entre summary(x) y fivenum(x)?
summary(x) proporciona un resumen estadístico que incluye la media, mediana y cuartiles de los datos en x, mientras que fivenum(x) devuelve los cinco números resumen: mínimo, primer cuartil, mediana, tercer cuartil y máximo.
Actividad #2.5:
Punto A:
arreglo = rnorm(100)
arreglo
## [1] 0.3562598375 1.0825418479 -2.1842800585 0.0004155364 -0.4419192155
## [6] -0.0487913838 -0.0755506269 -0.2960233693 -0.3721723270 0.2973399808
## [11] 0.0826902539 -1.2201406573 -1.5996469315 0.7379206580 0.2919799576
## [16] -0.7670699937 -1.1384533117 -0.5648896306 -0.4940979740 -0.9087832649
## [21] 0.3037989695 0.9571934387 -0.1399331294 -0.9616547988 -0.1626375928
## [26] -0.2662363250 0.6791438630 0.9141150413 -0.7534776870 -0.1900397358
## [31] 0.7898580245 -0.7401770446 0.0887469444 -0.6157340478 -0.1029900679
## [36] -1.7019980615 -0.5112489055 1.0619114135 -0.1777995894 -1.1702461520
## [41] 0.4776772788 0.9518698954 1.8577495176 -0.0200147165 0.7043426886
## [46] -0.0052859583 2.2812352096 1.8227789131 0.5273856179 -0.4241336159
## [51] 1.7923731909 0.9894872153 -0.1583474608 0.8993353616 -0.6038174160
## [56] -0.4677745349 -1.6631539307 -0.0679651146 -0.5291283834 1.2649808903
## [61] 0.7616876534 1.4940555906 -1.1542142588 -0.8730977652 -0.2447548891
## [66] 0.5523647073 -0.0337390509 -2.0027986100 0.0417466404 -0.1945800614
## [71] 0.5910097658 0.9146324035 0.5958827123 0.9140393423 -0.7156147204
## [76] 0.4513930725 -1.7316701642 -0.1942351604 -1.5369037176 1.2198565717
## [81] 0.8229573634 -1.0201370815 0.0249311813 -1.3472277848 1.3579106850
## [86] -1.2076391450 0.0488034254 0.6038556838 0.1995554503 1.4806405907
## [91] 0.6025364844 -0.3929887462 -0.6637406543 0.7155357165 -2.6445095852
## [96] -0.7991936863 -0.8586180203 0.2273109989 -1.9106032096 -0.4697065246
Punto B:
hist(arreglo, main = "Diagrama distribucion normal")
Se nota que los valores generados por la función rnorm varían cada vez que se ejecuta, lo que resulta en gráficos y resúmenes de datos distintos en cada ocasión.
Punto C:
summary(arreglo)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -2.64451 -0.67671 -0.07176 -0.06708 0.62268 2.28124
Actividad #2.6:
arreglo_2 = rbinom(30,5,0.9)
arreglo_2
## [1] 5 4 5 4 5 5 5 5 4 2 5 4 4 5 5 5 4 5 5 5 5 5 5 5 5 5 5 3 5 3
Punto A:
barplot(prop.table(table(arreglo_2)),col=c("red","yellow"),
main="Datos Binomiales",
ylab ="Frecuencias Relativas")
Punto B:
head(arreglo_2)
## [1] 5 4 5 4 5 5
summary(arreglo_2)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.000 4.000 5.000 4.567 5.000 5.000
Actividad #2.7
Num_fallos =c(0,1,0,NA,0,0,0,0,0,1,1,1,0,0,3,0,0,0,0,0,2,0,1)
Punto A:
barplot(Num_fallos)
El uso de un diagrama de barras resultaría más adecuado para representar estos datos en comparación con un diagrama de cajas, ya que el último no proporcionaría una información precisa en este caso particular.
Punto B:
Num_errores = mean(Num_fallos,na.rm = TRUE)
Num_errores
## [1] 0.4545455
Actividad #2.8:
Punto A:
Estudiantes = c(1,2,3,4,5,6,7,8,9,10)
Estudiantes
## [1] 1 2 3 4 5 6 7 8 9 10
P1 = c(3,3,3,4,3,4,3,4,4,3)
P1
## [1] 3 3 3 4 3 4 3 4 4 3
P2 = c(5,5,2,2,5,2,2,5,5,2)
P2
## [1] 5 5 2 2 5 2 2 5 5 2
P3 = c(1,3,1,3,3,3,1,3,1,1)
P3
## [1] 1 3 1 3 3 3 1 3 1 1
Punto B:
tabla = c(P1,P2,P3)
matriz = matrix(tabla,3,10,byrow = TRUE)
rownames(matriz)= c("P1","P2","P3")
colnames(matriz)=paste("Est",1:10)
matriz
## Est 1 Est 2 Est 3 Est 4 Est 5 Est 6 Est 7 Est 8 Est 9 Est 10
## P1 3 3 3 4 3 4 3 4 4 3
## P2 5 5 2 2 5 2 2 5 5 2
## P3 1 3 1 3 3 3 1 3 1 1
Punto C:
matriz[2,]
## Est 1 Est 2 Est 3 Est 4 Est 5 Est 6 Est 7 Est 8 Est 9 Est 10
## 5 5 2 2 5 2 2 5 5 2
matriz[3,]
## Est 1 Est 2 Est 3 Est 4 Est 5 Est 6 Est 7 Est 8 Est 9 Est 10
## 1 3 1 3 3 3 1 3 1 1
Punto D:
Datos_2 = c(P2,P3)
Datos_3 = matrix(Datos_2,2,10,byrow = TRUE)
Datos_2
## [1] 5 5 2 2 5 2 2 5 5 2 1 3 1 3 3 3 1 3 1 1
Datos_3
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 5 5 2 2 5 2 2 5 5 2
## [2,] 1 3 1 3 3 3 1 3 1 1
barplot(Datos_3,beside=F,xlab = "Estudiantes")
Punto E:
barplot(matriz,beside = T,xlab = "Estudiantes")
Actividad #2.9
VEC_1= rnorm(50)
VEC_1
## [1] -0.22391449 1.91207593 -1.06957662 -1.95655060 1.07581633 -0.13694453
## [7] 0.57095800 0.37267649 -0.67777991 1.48007955 -0.33469626 -0.46877195
## [13] -0.49491969 -0.62400472 -0.06856540 -0.76834832 1.09533779 -1.47022556
## [19] 0.14656500 1.73770467 0.71234024 0.68913595 1.13525643 1.32099030
## [25] -0.88817887 1.12698555 0.94874885 0.30497255 1.26432741 2.04761929
## [31] 0.08335104 1.82092514 2.15930842 0.23992160 0.78650613 0.23835718
## [37] 0.26083633 0.75266718 1.59038076 1.30371351 -0.25503948 0.15127521
## [43] 1.18423142 -1.42003482 -1.47258205 0.72337477 0.76386928 0.58937561
## [49] 1.11293408 -0.08061956
VEC_2 = rnorm(50)
VEC_2
## [1] -1.283151133 0.245297726 -0.102262331 -1.144738799 2.188313174
## [6] 1.094976595 0.445026601 -2.447839107 -0.011886929 0.716264617
## [11] 0.573132483 0.093047636 -0.720693622 0.263396576 0.541811076
## [16] 1.020513876 -0.098024373 -0.065638534 -1.992823611 0.862654555
## [21] 0.446419114 1.452540991 0.827575537 -1.048110585 0.450125044
## [26] 0.875397859 -1.707415842 0.005253909 1.700318811 -1.965415229
## [31] 0.182952753 0.593931783 0.690970082 0.031426983 -0.830466141
## [36] 2.569335539 0.258172169 -1.312748784 0.434114588 1.194922736
## [41] 0.590081528 0.146126326 -0.741953827 -0.275364957 1.022881474
## [46] -1.503998289 -0.383719816 0.240184386 -0.160348216 0.768151687
Punto A:
shapiro.test(VEC_1)
##
## Shapiro-Wilk normality test
##
## data: VEC_1
## W = 0.97961, p-value = 0.5356
shapiro.test(VEC_2)
##
## Shapiro-Wilk normality test
##
## data: VEC_2
## W = 0.97131, p-value = 0.2615
Punto B:
TEST = t.test(VEC_1,VEC_2)
TEST
##
## Welch Two Sample t-test
##
## data: VEC_1 and VEC_2
## t = 1.4276, df = 97.729, p-value = 0.1566
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.1136326 0.6961585
## sample estimates:
## mean of x mean of y
## 0.38583730 0.09457436
Basándonos en los resultados obtenidos de la prueba t de Welch para los vectores VEC_1 y VEC_2, la asunción de normalidad de los datos se cumple. Esto valida la comparación de medias entre los dos grupos. Sin embargo, el valor del p-valor, que es mayor que el umbral comúnmente aceptado de 0.05, sugiere que no hay suficiente evidencia para rechazar la hipótesis nula de que las medias son iguales.
Actividad #2.10
VEC_3 = rnorm(50)
VEC_3
## [1] 0.6431248807 -1.3876214243 -0.2954828142 -1.5356502124 -0.0698946744
## [6] -0.0009994676 1.3306049254 -0.4038101915 0.4679839886 0.2799933405
## [11] -0.8220349423 -0.6722784741 0.7172895725 -0.4683591395 -0.2960454158
## [16] -0.1054254533 1.7093384224 1.0543330788 -0.9672264413 -0.6060093710
## [21] -0.5331467352 0.5338619593 -1.0457234880 -0.9852764550 -0.4670482870
## [26] -0.3167211213 1.2226418844 -0.2887359021 0.7601944224 -0.3739252717
## [31] 0.7032642020 -2.1287622409 -0.4071851630 0.4707558922 -0.3066830584
## [36] 0.5468653213 2.1169955229 0.4410898578 -0.4224375277 -0.3684598189
## [41] 2.1796887085 -1.7742195524 -0.0774495207 0.9662200190 -0.2009099930
## [46] 1.4111798526 -0.1247657984 0.7742503751 0.3149124650 0.6175529789
VEC_4 = rbinom(50,10,0.9)
VEC_4
## [1] 8 10 8 8 8 8 10 9 8 8 8 8 10 9 8 10 10 9 9 9 10 8 8 10 10
## [26] 7 6 8 9 8 7 8 9 9 10 9 9 9 9 10 9 10 10 7 9 8 8 9 8 9
Punto A:
shapiro.test(VEC_3)
##
## Shapiro-Wilk normality test
##
## data: VEC_3
## W = 0.98252, p-value = 0.6619
shapiro.test(VEC_4)
##
## Shapiro-Wilk normality test
##
## data: VEC_4
## W = 0.87924, p-value = 0.0001061
Punto B:
TEST_2 = t.test(VEC_3,VEC_4)
TEST_2
##
## Welch Two Sample t-test
##
## data: VEC_3 and VEC_4
## t = -45.517, df = 97.777, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -9.041539 -8.286067
## sample estimates:
## mean of x mean of y
## 0.03619707 8.70000000
Basándonos en los resultados de la prueba t de Welch para VEC_3 y VEC_4, se observa que uno de los vectores sigue una distribución normal mientras que el otro parece seguir una distribución nominal. El valor del p-valor, que es significativamente menor que el umbral comúnmente aceptado de 0.05, sugiere que hay una diferencia significativa entre los dos grupos.