CARGA DE DATOS
#Carga de datos
setwd("~/UNI/ESTADISTICA")
datos <- read.csv("Depositos_Sulfuro.csv", sep = ";", dec = ".", header = TRUE)
CARGA DE LIBRERIAS
#Carga de librerias
library(dplyr)
library(knitr)
library(gt)
# Extraer y definir variables
area <- as.numeric(datos$ore_area) #Variable independiente
toneladas <-as.numeric(datos$oreton) #variable dependiente
#TABLA DE PARES DE VALORES
TPV <- data.frame( area,toneladas)
#LIMPIAR LOS VALORES NA,0 Y VALORES NEGATIVOS
TPV <- na.omit(TPV)
TPV <- TPV[TPV$area > 0 & TPV$toneladas > 0, ]
#ELIMINAR OUTLIERS
# OUTLIERS ÁREA
Q1_area <- quantile(TPV$area, 0.25)
Q3_area <- quantile(TPV$area, 0.75)
IQR_area <- Q3_area- Q1_area
lim_inf_area <- Q1_area - 1.5 * IQR_area
lim_sup_area <- Q3_area + 1.5 * IQR_area
# OUTLIERS TONELADAS
Q1_ton <- quantile(TPV$toneladas, 0.25)
Q3_ton <- quantile(TPV$toneladas, 0.75)
IQR_ton <- Q3_ton - Q1_ton
lim_inf_ton <- Q1_ton - 1.5 * IQR_ton
lim_sup_ton <- Q3_ton + 1.5 * IQR_ton
#TABLA SIN OUTLIERS
TPV_limpio <- TPV[
TPV$area >= lim_inf_area & TPV$area <= lim_sup_area &
TPV$toneladas >= lim_inf_ton & TPV$toneladas <= lim_sup_ton,
]
# Corresponder para una x una sola y
tabla_sup_1 <- aggregate(toneladas~ area,
data = TPV_limpio,
FUN = max)
tabla_media_1 <- aggregate(toneladas ~ area,
data = TPV_limpio,
FUN = mean)
tabla_inf_1 <- aggregate(toneladas ~ area,
data = TPV_limpio,
FUN = min)
#TABLA DE PARES DE VALORES PARA UN TRAMO
TPV_FILTRADO <- TPV_limpio[TPV_limpio$area < 20 & TPV_limpio$toneladas < 80, ]
#Corresponder para una x una sola y
tabla_sup <- aggregate(toneladas ~ area, data = TPV_FILTRADO, FUN = max)
tabla_media <- aggregate(toneladas ~ area, data = TPV_FILTRADO, FUN = mean)
tabla_inf <- aggregate(toneladas ~ area, data = TPV_FILTRADO, FUN = min)
#TABLA DE PARES DE VALORES PARA EL TRAMO DE ÁREAS MENORES A 20 CORRESPONDIENDO UNA UNICA Y A CADA X
tabla_inf
## area toneladas
## 1 1 1
## 2 2 1
## 3 3 2
## 4 4 3
## 5 5 4
## 6 7 23
## 7 8 7
## 8 9 24
## 9 10 15
## 10 11 15
## 11 13 30
## 12 14 10
## 13 15 11
## 14 17 45
#Obtener las variables de la tabla
x<-tabla_inf$area #Variable independiente
y<-tabla_inf$toneladas #Variable Dependiente
#Diagrama de dispersion para un tramo
plot(x,y,
pch = 16,
col = "blue",
main = "Grafica N°1 :Diagrama de disperción entre el área y el tonelaje
de los depositos de sulfuros masivos volcanicos",
xlab = "Área del deposito (km²)",
ylab = "Toneladas (Mt)")
Debido a la similitud de la nube de puntos conjeturamos a un modelo exponencial
Diagrama de dispersión
#Diagrama de dispersión
plot(x,
y,
pch = 16,
col = "blue",
main = "Grafica N°2 : Comparación de la realidad con el modelo exponencial
entre el área y el tonelaje de los depositos masivos de sulfuros
volcánicos",
xlab = "Área del deposito (km²)",
ylab = "Toneladas (Mt)")
# Parámetros potenciales
# Parámetros exponenciales
y1<- log(y)
#Cálculo de coefientes
regresion_exponencial<- lm(y1~x)
regresion_exponencial
##
## Call:
## lm(formula = y1 ~ x)
##
## Coefficients:
## (Intercept) x
## 0.3154 0.2046
summary(regresion_exponencial)
##
## Call:
## lm(formula = y1 ~ x)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.9864 -0.4490 0.0035 0.2956 1.3880
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.31540 0.37430 0.843 0.415910
## x 0.20459 0.03813 5.365 0.000169 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.7005 on 12 degrees of freedom
## Multiple R-squared: 0.7058, Adjusted R-squared: 0.6813
## F-statistic: 28.79 on 1 and 12 DF, p-value: 0.0001693
beta0<-regresion_exponencial$coefficients[1]
beta1<-regresion_exponencial$coefficients[2]
b<-beta1
b
## x
## 0.2045911
a<-exp(beta0)
a
## (Intercept)
## 1.370809
#Generar la curva
curve(a*exp(b*x), from = 0.0, to = 30, add = TRUE)
#Formamos la ecuación
plot(1, type = "n", axes = FALSE, xlab = "", ylab = "") # Crear un gráfico vacío
text(x = 1, y = 1,
labels = " Ecuación exponencial \n Y = ae^bx \n Y = 1.37e^(0.205x)",
cex = 2, # Tamaño del texto (ajustable)
col = "blue", # Color del texto
font =6) #tipo
TEST DE PEARSON
#TEST DE PEARSON
r<-cor(x,y1)
r*100
## [1] 84.01172
APRUEBA EL TEST PEARSON
RESTRICCIONES
Sí existen restricciones, ya que el modelo solo es valido dentro del rango (1≤x≤20)
¿Cuantas toneladas se esperaria si el área del deposito de 12 km ²?
#Cálculo de Pronosticos
T_Esp <- a*exp(b*12)
T_Esp
## (Intercept)
## 15.96652
plot(1, type = "n", axes = FALSE, xlab = "", ylab = "") # Crear un gráfico vacío
text(x = 1, y = 1,
labels = "¿Cual seria las toneladas si se tiene
un área del deposito de 12 km²?
\n R= 15.96 Mt ",
cex = 2, # Tamaño del texto (ajustable)
col = "blue", # Color del texto
font = 6)
Entre el área y el tonelaje existe una relacion exponencial donde el modelo f(x)=1.37e^(0.205x) siendo “x” área del deposito y “y” el tonelaje.
Sí existen restricciones, ya que el modelo solo es valido dentro del rango (1≤x≤20).
Ejemplo: Cuando el area es 12 km² se espera un tonelaje de 15.96 Mt