options(repos = c(CRAN = "https://cran.mx.r-project.org"))
install.packages("ggplot2")
## Installing package into 'C:/Users/Arun/AppData/Local/R/win-library/4.5'
## (as 'lib' is unspecified)
## Warning: unable to access index for repository https://cran.mx.r-project.org/src/contrib:
## no fue posible abrir la URL 'https://cran.mx.r-project.org/src/contrib/PACKAGES'
## Warning: package 'ggplot2' is not available for this version of R
##
## A version of this package for your version of R might be available elsewhere,
## see the ideas at
## https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
## Warning: unable to access index for repository https://cran.mx.r-project.org/bin/windows/contrib/4.5:
## no fue posible abrir la URL 'https://cran.mx.r-project.org/bin/windows/contrib/4.5/PACKAGES'
install.packages("dplyr")
## Installing package into 'C:/Users/Arun/AppData/Local/R/win-library/4.5'
## (as 'lib' is unspecified)
## Warning: unable to access index for repository https://cran.mx.r-project.org/src/contrib:
## no fue posible abrir la URL 'https://cran.mx.r-project.org/src/contrib/PACKAGES'
## Warning: package 'dplyr' is not available for this version of R
##
## A version of this package for your version of R might be available elsewhere,
## see the ideas at
## https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
## Warning: unable to access index for repository https://cran.mx.r-project.org/bin/windows/contrib/4.5:
## no fue posible abrir la URL 'https://cran.mx.r-project.org/bin/windows/contrib/4.5/PACKAGES'
library(ggplot2)
library(dplyr)
##
## Adjuntando el paquete: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
###Ejercicios pagina 92 ###
"3.7"
## [1] "3.7"
# Función de la pro babildad
f_horas_aspiradora = function(x) {
ifelse(x >= 0 & x < 1, x,
ifelse(x >= 1 & x < 2, 2 - x, 0))
}
# Punto A
prob_a = integrate(f_horas_aspiradora, 0, 1.2)$value
# Punto B
prob_b = integrate(f_horas_aspiradora, 0.5, 1.0)$value
#Respuestas de los dos incisos
cat("a) Probabilidad de menos de 120 horas:", prob_a, "\n")
## a) Probabilidad de menos de 120 horas: 0.68
cat("b) Probabilidad entre 50 y 100 horas:", prob_b, "\n")
## b) Probabilidad entre 50 y 100 horas: 0.375
# Crear un data frame con puntos para graficar
x_valores <- seq(0, 2, length.out = 1000)
df <- data.frame(x = x_valores ,y = f_horas_aspiradora(x_valores))
# Definir regiones sombreadas
# Región a: x < 1.2
df_a <- df %>% filter(x <= 1.2)
# Región b: 0.5 < x < 1.0
df_b <- df %>% filter(x >= 0.5 & x <= 1.0)
# Graficar
ggplot(df, aes(x = x, y = y)) +
geom_line(size = 1.2) +
geom_area(mapping = aes(x = x, y = y), data = df_a, fill = "skyblue", alpha = 0.8) +
geom_area(mapping = aes(x = x, y = y), data = df_b, fill = "red", alpha = 0.2) +
theme_minimal()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

"3.12"
## [1] "3.12"
#La función acumulativa de probabilidad es
f_bono = function(x) {
if(x < 1){
return(0)
}else if(x >= 1 & x < 3){
return(1/4)
}else if(x >= 3 & x < 5){
return(1/2)
}else if(x >= 5 & x < 7){
return(3/4)
}else if(x >= 7){
return(1)
}
}
#Respuesta A
p_a=f_bono(5)-f_bono(4)
#Respuesta B
p_b=1-f_bono(3)
#Respuesta C
p_c=f_bono(6)-f_bono(1.4)
#Respuesta D
#Ni idea que significa
#P(T ≤ 5 | T ≥ 2);