Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

R Console Page 1

> library(tidyverse)
── 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.4.4 ✔ 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 e
rrors
> library(readr)
> library(ggplot2)
> library(readxl)
> TresEstados<-read_excel("C:/Users/admon/Documents/Taller 2 Probabilidad y estadistica dep2.xlsx
")
-/ /
- > Tres
Estados<-na.omit(TresEstados)
> TresEstados$Region <-factor(TresEstados$Region)
> TresEstados$Doing_Homework_Hours <- as.numeric(TresEstados$Doing_Things_With_Family_Hours)
> summary(TresEstados$Region)
GA MT OR
263 179 327
> summary(TresEstados$Doing_Homework_Hours)
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.000 3.000 5.000 9.007 10.000 150.000
> TresEstados$Doing_Things_With_Family_Hours<- as.numeric(TresEstados$Doing_Things_With_Family_Ho
urs)
> summary(TresEstados$Doing_Things_With_Family_Hours)
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.000 3.000 5.000 9.007 10.000 150.000
> x.OR <- TresEstados$Doing_Things_With_Family_Hours)
Error: inesperado ')' en "x.OR <- TresEstados$Doing_Things_With_Family_Hours)"
> x.OR <- TresEstados$Doing_Things_With_Family_Hours[TresEstados$Region=="OR"]
> x.MT <- TresEstados$Doing_Things_With_Family_Hours[TresEstados$Region=="MT"]
> x.GA <- TresEstados$Doing_Things_With_Family_Hours[TresEstados$Region=="GA"]
> par(mfrow=c(1,3))
> x.MT <-sort(x.MT)
> x.GA <-sort(x.GA)
> x.OR <-sort(x.OR)
> acum_x.MT <- (1:length(x.MT))/length(x.MT)
> acum_x.GA <- (1:length(x.GA))/length(x.GA)
> acum_x.OR <- (1:length(x.OR))/length(x.OR)
> plot(x.MT,acum_x.MT,type="s",ylim=c(0,1))
> plot(x.GA,acum_x.GA,type="s",ylim=c(0,1))
> plot(x.OR,acum_x.OR,type="s",ylim=c(0,1))
> intervalos<-c("[0,10)","[10,20)","[20,30)","[30,40)","[40,50)")
> datos<-c(TresEstados)
> hist_result<-hist(datos,breaks=intervalos,plot=FALSE)
Error in hist.default(datos, breaks = intervalos, plot = FALSE) :
'x' must be numeric
> hist_MT <- hist(x.MT, plot = FALSE)
> hist_GA <- hist(x.GA, plot = FALSE)
> hist_OR <- hist(x.OR, plot = FALSE)
>
> frec_acum_MT <- cumsum(hist_MT$counts) / sum(hist_MT$counts)
> frec_acum_GA <- cumsum(hist_GA$counts) / sum(hist_GA$counts)
> frec_acum_OR <- cumsum(hist_OR$counts) / sum(hist_OR$counts)
> print("Frecuencias acumuladas para Montana:")
[1] "Frecuencias acumuladas para Montana:"
> print(frec_acum_MT)
[1] 0.5195531 0.7988827 0.8659218 0.9050279 0.9385475 0.9553073
[7] 0.9608939 0.9608939 0.9720670 1.0000000
> print("Frecuencias acumuladas para Georgia:")
[1] "Frecuencias acumuladas para Georgia:"
> print(frec_acum_GA)
[1] 0.7452471 0.8859316 0.9429658 0.9543726 0.9961977 0.9961977
[7] 0.9961977 0.9961977 1.0000000
R Console Page 2

> print("Frecuencias acumuladas para Oregon:")


[1] "Frecuencias acumuladas para Oregon:"
> print(frec_acum_OR)
[1] 0.9327217 0.9877676 0.9969419 0.9969419 0.9969419 0.9969419
[7] 0.9969419 1.0000000
> lines(x.GA, frec_acum_GA, type = "s", col = "red", lty = 2) # Cambia a 'x.GA' según tus datos
Error in xy.coords(x, y) : 'x' and 'y' lengths differ
> legend("bottomright", legend = c("Ojiva", "Frecuencias Acumuladas"), col = c("black", "red"), l
ty = c(1, 2))
> length(x.GA)
[1] 263
> length(frec_acum_GA)
[1] 9
> orden <- order(x.GA)

> > x.GA <- x.GA[orden]


> frec_acum_GA <- frec_acum_GA[orden]
> x.GA_interpolado <- approx(x.GA, xout = seq(min(x.GA), max(x.GA), length.out = length(acum_x.GA
)))$y
> df <- data.frame(x = x.GA, acum_x = acum_x.GA, frec_acum = frec_acum_GA)
> df <- df[order(df$x), ]
> x.GA <- sort(x.GA)
> length(x.GA)
[1] 263
> length(frec_acum_GA)
[1] 263
> x.GA <- sort(x.GA)
> frec_acum_GA <- sort(frec_acum_GA)
> plot(x.GA, acum_x.GA, type = "s", ylim = c(0, 1), main = "GA Ojiva", xlab = "Horas", ylab = "Fr
ecuencia acumulada")
> lines(x.GA, frec_acum_GA, type = "s", col = "red", lty = 2)
Error in xy.coords(x, y) : 'x' and 'y' lengths differ
> print(length(x.GA))
[1] 263
> print(length(acum_x.GA))
[1] 263
> print(length(frec_acum_GA))
[1] 9
> orden <- order(x.GA)
> x.GA <- x.GA[orden]
> acum_x.GA <- acum_x.GA[orden]
> frec_acum_GA <- frec_acum_GA[orden]
> datos_GA <- TresEstados$Doing_Things_With_Family_Hours[TresEstados$Region == "GA"]
> tabla_frec <- table(datos_GA)
> frec_acum_GA <- cumsum(tabla_frec) / sum(tabla_frec)
> print(length(x.GA))
[1] 263
> print(length(acum_x.GA))
[1] 263
> print(length(frec_acum_GA))
[1] 34
> x.GA <- TresEstados$Doing_Things_With_Family_Hours[TresEstados$Region == "GA"]
> x.GA <- sort(x.GA)
> ecdf_GA <- ecdf(x.GA)
> plot(ecdf_GA, main = "GA Ojiva", xlab = "Horas", ylab = "Frecuencia acumulada")
> lines(sort(x.GA), ecdf_GA(sort(x.GA)), col = "red", lty = 2)
> valores_evaluados <- c(5, 10, 15)
> frecuencias_acumuladas <- ecdf_GA(valores_evaluados)
> for (i in seq_along(valores_evaluados)) {cat("Frecuencia acumulada en", valores_evaluados[i], "
es:", frecuencias_acumuladas[i], "\n")}
Frecuencia acumulada en 5 es: 0.5247148
Frecuencia acumulada en 10 es: 0.7452471
Frecuencia acumulada en 15 es: 0.8365019
> valores_evaluados <- c(5, 10, 15, 20, 30, 40, 50)
> frecuencias_acumuladas <- ecdf_GA(valores_evaluados)
> for (i in seq_along(valores_evaluados)) {cat("Frecuencia acumulada en", valores_evaluados[i], "
es:", frecuencias_acumuladas[i], "\n")}
Frecuencia acumulada en 5 es: 0.5247148
Frecuencia acumulada en 10 es: 0.7452471
Frecuencia acumulada en 15 es: 0.8365019
R Console Page 5

[121] 0.42507645 0.42507645 0.42507645 0.42507645 0.42507645


[126] 0.42507645 0.42507645 0.42507645 0.42507645 0.42507645
[131] 0.42507645 0.42507645 0.42507645 0.42507645 0.42507645
[136] 0.42507645 0.42507645 0.42507645 0.42507645 0.52599388
[141] 0.52599388 0.52599388 0.52599388 0.52599388 0.52599388
[146] 0.52599388 0.52599388 0.52599388 0.52599388 0.52599388
[151] 0.52599388 0.52599388 0.52599388 0.52599388 0.52599388
[156] 0.52599388 0.52599388 0.52599388 0.52599388 0.52599388
[161] 0.52599388 0.52599388 0.52599388 0.52599388 0.52599388
[166] 0.52599388 0.52599388 0.52599388 0.52599388 0.52599388
[171] 0.52599388 0.52599388 0.58715596 0.58715596 0.58715596
[176] 0.58715596 0.58715596 0.58715596 0.58715596 0.58715596
[181] 0.58715596 0.58715596 0.58715596 0.58715596 0.58715596
[186] 0.58715596 0.58715596 0.58715596 0.58715596 0.58715596
[191] 0.58715596 0.58715596 0.63608563 0.63608563 0.63608563
[196] 0.63608563 0.63608563 0.63608563 0.63608563 0.63608563
[201] 0.63608563 0.63608563 0.63608563 0.63608563 0.63608563
[206] 0.63608563 0.63608563 0.63608563 0.67889908 0.67889908
[211] 0.67889908 0.67889908 0.67889908 0.67889908 0.67889908
[216] 0.67889908 0.67889908 0.67889908 0.67889908 0.67889908
[221] 0.67889908 0.67889908 0.69113150 0.69113150 0.69113150
[226] 0.69113150 0.80122324 0.80122324 0.80122324 0.80122324
[231] 0.80122324 0.80122324 0.80122324 0.80122324 0.80122324
[236] 0.80122324 0.80122324 0.80122324 0.80122324 0.80122324
[241] 0.80122324 0.80122324 0.80122324 0.80122324 0.80122324
[246] 0.80122324 0.80122324 0.80122324 0.80122324 0.80122324
[251] 0.80122324 0.80122324 0.80122324 0.80122324 0.80122324
[256] 0.80122324 0.80122324 0.80122324 0.80122324 0.80122324
[261] 0.80122324 0.80122324 0.82568807 0.82568807 0.82568807
[266] 0.82568807 0.82568807 0.82568807 0.82568807 0.82568807
[271] 0.83486239 0.83486239 0.83486239 0.85015291 0.85015291
[276] 0.85015291 0.85015291 0.85015291 0.88379205 0.88379205
[281] 0.88379205 0.88379205 0.88379205 0.88379205 0.88379205
[286] 0.88379205 0.88379205 0.88379205 0.88379205 0.89296636
[291] 0.89296636 0.89296636 0.90214067 0.90214067 0.90214067
[296] 0.90519878 0.90825688 0.93272171 0.93272171 0.93272171
[301] 0.93272171 0.93272171 0.93272171 0.93272171 0.93272171
[306] 0.93577982 0.94801223 0.94801223 0.94801223 0.94801223
[311] 0.95412844 0.95412844 0.95718654 0.96941896 0.96941896
[316] 0.96941896 0.96941896 0.97247706 0.97553517 0.98776758
[321] 0.98776758 0.98776758 0.98776758 0.99082569 0.99388379
[326] 0.99694190 1.00000000
> print("Frecuencias acumuladas para Montana:")
[1] "Frecuencias acumuladas para Montana:"
> print(ecdf_MT(x.MT))
[1] 0.02793296 0.02793296 0.02793296 0.02793296 0.02793296
[6] 0.03351955 0.12849162 0.12849162 0.12849162 0.12849162
[11] 0.12849162 0.12849162 0.12849162 0.12849162 0.12849162
[16] 0.12849162 0.12849162 0.12849162 0.12849162 0.12849162
[21] 0.12849162 0.12849162 0.12849162 0.13407821 0.21787709
[26] 0.21787709 0.21787709 0.21787709 0.21787709 0.21787709
[31] 0.21787709 0.21787709 0.21787709 0.21787709 0.21787709
[36] 0.21787709 0.21787709 0.21787709 0.21787709 0.30726257
[41] 0.30726257 0.30726257 0.30726257 0.30726257 0.30726257
[46] 0.30726257 0.30726257 0.30726257 0.30726257 0.30726257
[51] 0.30726257 0.30726257 0.30726257 0.30726257 0.30726257
[56] 0.39106145 0.39106145 0.39106145 0.39106145 0.39106145
[61] 0.39106145 0.39106145 0.39106145 0.39106145 0.39106145
[66] 0.39106145 0.39106145 0.39106145 0.39106145 0.39106145
[71] 0.51955307 0.51955307 0.51955307 0.51955307 0.51955307
[76] 0.51955307 0.51955307 0.51955307 0.51955307 0.51955307
[81] 0.51955307 0.51955307 0.51955307 0.51955307 0.51955307
[86] 0.51955307 0.51955307 0.51955307 0.51955307 0.51955307
[91] 0.51955307 0.51955307 0.51955307 0.56424581 0.56424581
[96] 0.56424581 0.56424581 0.56424581 0.56424581 0.56424581
[101] 0.56424581 0.59217877 0.59217877 0.59217877 0.59217877
[106] 0.59217877 0.63128492 0.63128492 0.63128492 0.63128492
[111] 0.63128492 0.63128492 0.63128492 0.64245810 0.64245810
[116] 0.79888268 0.79888268 0.79888268 0.79888268 0.79888268
[121] 0.79888268 0.79888268 0.79888268 0.79888268 0.79888268
R Console Page 6

[126] 0.79888268 0.79888268 0.79888268 0.79888268 0.79888268


[131] 0.79888268 0.79888268 0.79888268 0.79888268 0.79888268
[136] 0.79888268 0.79888268 0.79888268 0.79888268 0.79888268
[141] 0.79888268 0.79888268 0.79888268 0.80446927 0.82122905
[146] 0.82122905 0.82122905 0.86592179 0.86592179 0.86592179
[151] 0.86592179 0.86592179 0.86592179 0.86592179 0.86592179
[156] 0.87150838 0.90502793 0.90502793 0.90502793 0.90502793
[161] 0.90502793 0.90502793 0.91061453 0.92737430 0.92737430
[166] 0.92737430 0.93854749 0.93854749 0.94413408 0.95530726
[171] 0.95530726 0.96089385 0.96648045 0.97206704 1.00000000
[176] 1.00000000 1.00000000 1.00000000 1.00000000
> print("Frecuencias acumuladas para Georgia:")
[1] "Frecuencias acumuladas para Georgia:"
> print(ecdf_GA(x.GA))
[1] 0.06844106 0.06844106 0.06844106 0.06844106 0.06844106
[6] 0.06844106 0.06844106 0.06844106 0.06844106 0.06844106
[11] 0.06844106 0.06844106 0.06844106 0.06844106 0.06844106
[16] 0.06844106 0.06844106 0.06844106 0.07224335 0.14828897
[21] 0.14828897 0.14828897 0.14828897 0.14828897 0.14828897
[26] 0.14828897 0.14828897 0.14828897 0.14828897 0.14828897
[31] 0.14828897 0.14828897 0.14828897 0.14828897 0.14828897
[36] 0.14828897 0.14828897 0.14828897 0.14828897 0.24334601
[41] 0.24334601 0.24334601 0.24334601 0.24334601 0.24334601
[46] 0.24334601 0.24334601 0.24334601 0.24334601 0.24334601
[51] 0.24334601 0.24334601 0.24334601 0.24334601 0.24334601
[56] 0.24334601 0.24334601 0.24334601 0.24334601 0.24334601
[61] 0.24334601 0.24334601 0.24334601 0.24334601 0.32699620
[66] 0.32699620 0.32699620 0.32699620 0.32699620 0.32699620
[71] 0.32699620 0.32699620 0.32699620 0.32699620 0.32699620
[76] 0.32699620 0.32699620 0.32699620 0.32699620 0.32699620
[81] 0.32699620 0.32699620 0.32699620 0.32699620 0.32699620
[86] 0.32699620 0.36882129 0.36882129 0.36882129 0.36882129
[91] 0.36882129 0.36882129 0.36882129 0.36882129 0.36882129
[96] 0.36882129 0.36882129 0.52471483 0.52471483 0.52471483
[101] 0.52471483 0.52471483 0.52471483 0.52471483 0.52471483
[106] 0.52471483 0.52471483 0.52471483 0.52471483 0.52471483
[111] 0.52471483 0.52471483 0.52471483 0.52471483 0.52471483
[116] 0.52471483 0.52471483 0.52471483 0.52471483 0.52471483
[121] 0.52471483 0.52471483 0.52471483 0.52471483 0.52471483
[126] 0.52471483 0.52471483 0.52471483 0.52471483 0.52471483
[131] 0.52471483 0.52471483 0.52471483 0.52471483 0.52471483
[136] 0.52471483 0.52471483 0.52471483 0.58174905 0.58174905
[141] 0.58174905 0.58174905 0.58174905 0.58174905 0.58174905
[146] 0.58174905 0.58174905 0.58174905 0.58174905 0.58174905
[151] 0.58174905 0.58174905 0.58174905 0.62357414 0.62357414
[156] 0.62357414 0.62357414 0.62357414 0.62357414 0.62357414
[161] 0.62357414 0.62357414 0.62357414 0.62357414 0.63878327
[166] 0.63878327 0.63878327 0.63878327 0.65019011 0.65019011
[171] 0.65019011 0.74524715 0.74524715 0.74524715 0.74524715
[176] 0.74524715 0.74524715 0.74524715 0.74524715 0.74524715
[181] 0.74524715 0.74524715 0.74524715 0.74524715 0.74524715
[186] 0.74524715 0.74524715 0.74524715 0.74524715 0.74524715
[191] 0.74524715 0.74524715 0.74524715 0.74524715 0.74524715
[196] 0.74524715 0.75285171 0.75285171 0.77186312 0.77186312
[201] 0.77186312 0.77186312 0.77186312 0.78707224 0.78707224
[206] 0.78707224 0.78707224 0.83650190 0.83650190 0.83650190
[211] 0.83650190 0.83650190 0.83650190 0.83650190 0.83650190
[216] 0.83650190 0.83650190 0.83650190 0.83650190 0.83650190
[221] 0.84030418 0.85171103 0.85171103 0.85171103 0.88593156
[226] 0.88593156 0.88593156 0.88593156 0.88593156 0.88593156
[231] 0.88593156 0.88593156 0.88593156 0.88973384 0.89353612
[236] 0.91254753 0.91254753 0.91254753 0.91254753 0.91254753
[241] 0.92775665 0.92775665 0.92775665 0.92775665 0.93155894
[246] 0.93536122 0.94296578 0.94296578 0.94676806 0.95057034
[251] 0.95437262 0.95817490 0.96197719 0.96577947 0.99619772
[256] 0.99619772 0.99619772 0.99619772 0.99619772 0.99619772
[261] 0.99619772 0.99619772 1.00000000
> par(mfrow = c(1, 3))
> plot(ecdf_OR, main = "OR Ojiva", xlab = "Horas", ylab = "Frecuencia acumulada", col = "blue")
> lines(sort(x.OR), ecdf_OR(sort(x.OR)), col = "red", lty = 2)
R Console Page 7

> text(quantile(x.OR), ecdf_OR(quantile(x.OR)), labels = round(ecdf_OR(quantile(x.OR)), 4), pos =


4, col = "red")
> plot(ecdf_MT, main = "MT Ojiva", xlab = "Horas", ylab = "Frecuencia acumulada", col = "blue")
> lines(sort(x.MT), ecdf_MT(sort(x.MT)), col = "red", lty = 2)
> text(quantile(x.MT), ecdf_MT(quantile(x.MT)), labels = round(ecdf_MT(quantile(x.MT)), 4), pos =
4, col = "red")
> plot(ecdf_GA, main = "GA Ojiva", xlab = "Horas", ylab = "Frecuencia acumulada", col = "blue")
> lines(sort(x.GA), ecdf_GA(sort(x.GA)), col = "red", lty = 2)
> text(quantile(x.GA), ecdf_GA(quantile(x.GA)), labels = round(ecdf_GA(quantile(x.GA)), 4), pos =
4, col = "red")
>

You might also like