UNIVERSIDAD CENTRAL DEL ECUADOR
Petróleos
Tema: Estadistica inferencial de variables cualitativas
grupo 2
2025-2026
library(readxl)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(readr)
##Cargar datos
setwd("C:/Users/ronal/OneDrive/Desktop")
datos <- read.csv("database (1).csv", header = TRUE, sep = ",", dec = ".")
# Variable: Liquid Explosion
liq_exp <- datos$Liquid.Explosion # Ajusta si usa otro nombre EXACTO
# Frecuencia absoluta
freq_LE <- table(liq_exp)
# Convertir a data frame
Tabla_LE <- as.data.frame(freq_LE)
colnames(Tabla_LE) <- c("x", "ni")
# Frecuencia relativa
Tabla_LE$hi <- round(Tabla_LE$ni / sum(Tabla_LE$ni), 4)
# Fila TOTAL
fila_total_LE <- data.frame(
x = "TOTAL",
ni = sum(Tabla_LE$ni),
hi = 1.00
)
# Tabla final con YES, NO y TOTAL
TablaFinal_LE <- rbind(Tabla_LE, fila_total_LE)
TablaFinal_LE
## x ni hi
## 1 NO 2780 0.9946
## 2 YES 15 0.0054
## 3 TOTAL 2795 1.0000
##Gráfica No.1
Tabla_LE_graf <- subset(TablaFinal_LE, x != "TOTAL")
options(repr.plot.width = 10, repr.plot.height = 7)
par(mar = c(8, 5, 5, 2))
bp <- barplot(
Tabla_LE_graf$ni,
names.arg = rep("", nrow(Tabla_LE_graf)),
col = "#4ECDC4",
main = "Grafica No.1: Frecuencia Absoluta - Liquid Explosion",
ylab = "Cantidad",
width = 1.5,
space = 1,
cex.axis = 1.2,
ylim = c(0, max(Tabla_LE_graf$ni) * 1.3)
)
text(
x = bp,
y = -max(Tabla_LE_graf$ni) * 0.10,
labels = Tabla_LE_graf$x,
cex = 1.2,
xpd = TRUE
)
##Gráfica No.2
Tabla_LE_graf <- subset(TablaFinal_LE, x != "TOTAL")
options(repr.plot.width = 10, repr.plot.height = 7)
par(mar = c(8, 5, 5, 2))
bp <- barplot(
Tabla_LE_graf$hi,
names.arg = rep("", nrow(Tabla_LE_graf)),
col = "#4ECDC4",
main = "Grafica No.2: Frecuencia Relativa - Liquid Explosion",
ylab = "Frecuencia Relativa",
width = 1.5,
space = 1,
cex.axis = 1.2,
ylim = c(0, max(Tabla_LE_graf$hi) * 1.3)
)
text(
x = bp,
y = -max(Tabla_LE_graf$hi) * 0.08,
labels = Tabla_LE_graf$x,
cex = 1.2,
xpd = TRUE
)
##Gráfica No.3
Tabla_LE_graf <- subset(TablaFinal_LE, x != "TOTAL")
options(repr.plot.width = 10, repr.plot.height = 7)
par(mar = c(8, 5, 5, 2))
bp <- barplot(
Tabla_LE_graf$hi * 100,
names.arg = rep("", nrow(Tabla_LE_graf)),
col = "#4ECDC4",
main = "Grafica No.3: Porcentaje - Liquid Explosion",
ylab = "Porcentaje (%)",
width = 1.5,
space = 1,
cex.axis = 1.2,
ylim = c(0, max(Tabla_LE_graf$hi * 100) * 1.3)
)
text(
x = bp,
y = -max(Tabla_LE_graf$hi * 100) * 0.08,
labels = Tabla_LE_graf$x,
cex = 1.2,
xpd = TRUE
)
##Grafica No.4-Diagrama Circular
Tabla_LE_graf <- subset(TablaFinal_LE, x != "TOTAL")
options(repr.plot.width = 10, repr.plot.height = 7)
par(mar = c(4, 4, 4, 18))
colores <- colorRampPalette(c("#1f77b4", "#d4f1f9"))(nrow(Tabla_LE_graf))
pie(
Tabla_LE_graf$hi,
labels = NA,
col = colores,
main = "Grafica No.4: Distribucion - Liquid Explosion",
cex = 1.2,
radius = 1.0
)
legend(
x = 1.3,
y = 0.6,
legend = paste0(
Tabla_LE_graf$x, " - ",
round(Tabla_LE_graf$hi * 100, 1), "% (", Tabla_LE_graf$ni, " casos)"
),
fill = colores,
cex = 1.1,
bty = "n",
xpd = TRUE
)