IMPORTACIÓN DATOS

ionwater <- read.table("ion_waters.csv",head=T,dec=".",sep=",")
View(ionwater)
str(ionwater)
## 'data.frame':    19 obs. of  3 variables:
##  $ type     : chr  "GW" "S" "S" "GW" ...
##  $ n.nitrate: num  0.2 0.98 0.59 0.19 0.46 0.2 0.31 0.27 0.33 0.2 ...
##  $ sulphate : num  2.57 10.82 4.99 2.43 7.04 ...
summary(ionwater)
##      type             n.nitrate         sulphate     
##  Length:19          Min.   :0.1900   Min.   : 0.810  
##  Class :character   1st Qu.:0.2000   1st Qu.: 2.020  
##  Mode  :character   Median :0.2700   Median : 2.810  
##                     Mean   :0.3232   Mean   : 3.329  
##                     3rd Qu.:0.3200   3rd Qu.: 3.715  
##                     Max.   :0.9800   Max.   :10.820
head(ionwater)
##   type n.nitrate sulphate
## 1   GW      0.20     2.57
## 2    S      0.98    10.82
## 3    S      0.59     4.99
## 4   GW      0.19     2.43
## 5    S      0.46     7.04
## 6   GW      0.20     3.12
tail(ionwater)
##    type n.nitrate sulphate
## 14    S      0.30     2.90
## 15   GW      0.26     1.41
## 16   GW      0.27     2.93
## 17   GW      0.20     1.92
## 18    S      0.29     2.12
## 19   GW      0.20     1.43

EXPLORACIÓN DATOS

str(ionwater)
## 'data.frame':    19 obs. of  3 variables:
##  $ type     : chr  "GW" "S" "S" "GW" ...
##  $ n.nitrate: num  0.2 0.98 0.59 0.19 0.46 0.2 0.31 0.27 0.33 0.2 ...
##  $ sulphate : num  2.57 10.82 4.99 2.43 7.04 ...
names(ionwater)
## [1] "type"      "n.nitrate" "sulphate"
dim(ionwater)
## [1] 19  3

SUBCONJUNTOS DE DATOS Datos agua S

ionwater <- read.table("ion_waters.csv",head=T,dec=".",sep=",")
View(ionwater)
ionwater2 <- ionwater[,1:3]
View(ionwater2)
S <- subset(ionwater, type == "S")
S
##    type n.nitrate sulphate
## 2     S      0.98    10.82
## 3     S      0.59     4.99
## 5     S      0.46     7.04
## 7     S      0.31     3.75
## 9     S      0.33     1.83
## 13    S      0.40     2.81
## 14    S      0.30     2.90
## 18    S      0.29     2.12

Datos augua GW

ionwater <- read.table("ion_waters.csv",head=T,dec=".",sep=",")
View(ionwater)
ionwater3 <- ionwater[,1:3]
View(ionwater3)
GW <- subset(ionwater, type == "GW")
GW
##    type n.nitrate sulphate
## 1    GW      0.20     2.57
## 4    GW      0.19     2.43
## 6    GW      0.20     3.12
## 8    GW      0.27     2.68
## 10   GW      0.20     0.81
## 11   GW      0.23     3.68
## 12   GW      0.26     4.01
## 15   GW      0.26     1.41
## 16   GW      0.27     2.93
## 17   GW      0.20     1.92
## 19   GW      0.20     1.43

COMPARAR MEDIAS

NITRATO

var.test(S$n.nitrate, GW$n.nitrate)
## 
##  F test to compare two variances
## 
## data:  S$n.nitrate and GW$n.nitrate
## F = 50.552, num df = 7, denom df = 10, p-value = 1.041e-06
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##   12.79866 240.68604
## sample estimates:
## ratio of variances 
##           50.55244

Hipotesis nula: NO hay variaciones significativas en la varianza (0) Hipotesis alternativa: SI hay variaciones significativas en la varianza (1)

RESULTADO: Ya que dio “not equal to 1” NO hay una difrencia significativa en el promedio.

Prueba T: Significancia de Promedio Nitrato

t.test(S$n.nitrate, GW$n.nitrate, mu = 0, paired = FALSE, var.equal=FALSE)
## 
##  Welch Two Sample t-test
## 
## data:  S$n.nitrate and GW$n.nitrate
## t = 2.7796, df = 7.2018, p-value = 0.02655
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.03575589 0.42833502
## sample estimates:
## mean of x mean of y 
## 0.4575000 0.2254545

Hipotesis nula: NO hay variaciones significativas en el promedio (0) Hipotesis alternativa: SI hay variaciones significativas en el promedio (1)

Resultado: Ya que dio “not equal to 0” SI hay una difrencia significativa en el promedio.

SULFATO

var.test(S$sulphate, GW$sulphate)
## 
##  F test to compare two variances
## 
## data:  S$sulphate and GW$sulphate
## F = 9.547, num df = 7, denom df = 10, p-value = 0.001975
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##   2.417057 45.454144
## sample estimates:
## ratio of variances 
##           9.546951

Hipotesis nula: NO hay variaciones significativas en la varianza (0) Hipotesis alternativa: SI hay variaciones significativas en la varianza (1)

RESULTADO: Ya que dio “not equal to 1” NO hay una difrencia significativa en el promedio.

Prueba T: Significancia de Promedio Sulfato

t.test(S$sulphate, GW$sulphate, mu = 0, paired = FALSE, var.equal=FALSE)
## 
##  Welch Two Sample t-test
## 
## data:  S$sulphate and GW$sulphate
## t = 1.8544, df = 8.0743, p-value = 0.1005
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.5021694  4.6598967
## sample estimates:
## mean of x mean of y 
##  4.532500  2.453636

Hipotesis nula: NO hay variaciones significativas en el promedio (0) Hipotesis alternativa: SI hay variaciones significativas en el promedio (1)

Resultado: Ya que dio “not equal to 0” SI hay una difrencia significativa en el promedio.

GRAFICAR VARIABLES

library(ggplot2)
plot(GW$n.nitrate,GW$sulphate,pch=19,col="green",cex=1)

plot(S$n.nitrate,S$sulphate,pch=19,col="blue",cex=1)

Debido a la anormalidad de los datos, para aguas GW no existe correlación.

Si hay correlación para el agua S.

MODELO DE REGRESIÓN LINEAL

ggplot(data = ionwater) +
geom_point(aes(x = n.nitrate, y = sulphate), col='blue')

RL.GW=lm(GW$n.nitrate ~ GW$sulphate)
RL.GW
## 
## Call:
## lm(formula = GW$n.nitrate ~ GW$sulphate)
## 
## Coefficients:
## (Intercept)  GW$sulphate  
##     0.19612      0.01195
RL.S=lm(S$n.nitrate ~ S$sulphate)
RL.S
## 
## Call:
## lm(formula = S$n.nitrate ~ S$sulphate)
## 
## Coefficients:
## (Intercept)   S$sulphate  
##     0.14060      0.06992
plot(RL.GW,which=1)

plot(RL.S,which=1)