UNIVERSIDAD CENTRAL DEL ECUADOR
Petróleos
Tema: Estadistica inferencial de variables cualitativas
grupo 2
2025-2026
##Cargar libreria
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 Ignition
liq_ign <- datos$Liquid.Ignition # Ajustar si nombre cambia
# Frecuencia absoluta
freq_LI <- table(liq_ign)
# Convertir a data frame
Tabla_LI <- as.data.frame(freq_LI)
colnames(Tabla_LI) <- c("x", "ni")
# Frecuencia relativa
Tabla_LI$hi <- round(Tabla_LI$ni / sum(Tabla_LI$ni), 4)
# Fila TOTAL
fila_total_LI <- data.frame(
x = "TOTAL",
ni = sum(Tabla_LI$ni),
hi = 1.00
)
# Tabla final con YES, NO y TOTAL
TablaFinal_LI <- rbind(Tabla_LI, fila_total_LI)
TablaFinal_LI
## x ni hi
## 1 NO 2700 0.966
## 2 YES 95 0.034
## 3 TOTAL 2795 1.000
##Gráfica No.1
Tabla_LI_graf <- subset(TablaFinal_LI, x != "TOTAL")
options(repr.plot.width = 10, repr.plot.height = 7)
par(mar = c(8, 5, 5, 2))
bp <- barplot(
Tabla_LI_graf$ni,
names.arg = rep("", nrow(Tabla_LI_graf)),
col = "#4ECDC4",
main = "Grafica No.1: Frecuencia Absoluta - Liquid Ignition",
ylab = "Cantidad",
width = 1.5,
space = 1,
cex.axis = 1.2,
ylim = c(0, max(Tabla_LI_graf$ni) * 1.3)
)
text(
x = bp,
y = -max(Tabla_LI_graf$ni) * 0.10,
labels = Tabla_LI_graf$x,
cex = 1.2,
xpd = TRUE
)
##Gráfica No.2
Tabla_LI_graf <- subset(TablaFinal_LI, x != "TOTAL")
options(repr.plot.width = 10, repr.plot.height = 7)
par(mar = c(8, 5, 5, 2))
bp <- barplot(
Tabla_LI_graf$hi,
names.arg = rep("", nrow(Tabla_LI_graf)),
col = "#4ECDC4",
main = "Grafica No.2: Frecuencia Relativa - Liquid Ignition",
ylab = "Frecuencia Relativa",
width = 1.5,
space = 1,
cex.axis = 1.2,
ylim = c(0, max(Tabla_LI_graf$hi) * 1.3)
)
text(
x = bp,
y = -max(Tabla_LI_graf$hi) * 0.08,
labels = Tabla_LI_graf$x,
cex = 1.2,
xpd = TRUE
)
##Gráfica No.3
Tabla_LI_graf <- subset(TablaFinal_LI, x != "TOTAL")
options(repr.plot.width = 10, repr.plot.height = 7)
par(mar = c(8, 5, 5, 2))
bp <- barplot(
Tabla_LI_graf$hi * 100,
names.arg = rep("", nrow(Tabla_LI_graf)),
col = "#4ECDC4",
main = "Grafica No.3: Porcentaje - Liquid Ignition",
ylab = "Porcentaje (%)",
width = 1.5,
space = 1,
cex.axis = 1.2,
ylim = c(0, max(Tabla_LI_graf$hi * 100) * 1.3)
)
text(
x = bp,
y = -max(Tabla_LI_graf$hi * 100) * 0.08,
labels = Tabla_LI_graf$x,
cex = 1.2,
xpd = TRUE
)
##Gráfica No.4- Diagrama Circular
Tabla_LI_graf <- subset(TablaFinal_LI, 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_LI_graf))
pie(
Tabla_LI_graf$hi,
labels = NA,
col = colores,
main = "Grafica No.4: Distribucion - Liquid Ignition",
cex = 1.2,
radius = 1.0
)
legend(
x = 1.3,
y = 0.6,
legend = paste0(
Tabla_LI_graf$x, " - ",
round(Tabla_LI_graf$hi * 100, 1), "% (", Tabla_LI_graf$ni, " casos)"
),
fill = colores,
cex = 1.1,
bty = "n",
xpd = TRUE
)