ion_waters <- read.table("ion_waters.csv",head=T,dec=".",sep=",")
View(ion_waters)
str(ion_waters)
## '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 ...

Exploración de datos

summary(ion_waters$n.nitrate)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.1900  0.2000  0.2700  0.3232  0.3200  0.9800
summary(ion_waters$sulphate)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.810   2.020   2.810   3.329   3.715  10.820

Sub-Grupos

 water <- read.table("ion_waters.csv",head=T,dec=".",sep = ",")
water
##    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
## 7     S      0.31     3.75
## 8    GW      0.27     2.68
## 9     S      0.33     1.83
## 10   GW      0.20     0.81
## 11   GW      0.23     3.68
## 12   GW      0.26     4.01
## 13    S      0.40     2.81
## 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
 WATERGW <- water[,1:3] 
 View(WATERGW)
 GW <- subset(water , 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
WATERS <- water[,1:3] 
 View(WATERS)
 S <- subset(water , 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

Diferencias promedio

Aguas subterranea (GW)

mean(GW$n.nitrate)
## [1] 0.2254545
mean(GW$sulphate)
## [1] 2.453636

Aguas subterranea (s)

mean(S$n.nitrate)
## [1] 0.4575
mean(S$sulphate)
## [1] 4.5325

promedio nitrato

S.nitrate<-(S$n.nitrate)
gw.nitrate<-(GW$n.nitrate)
S.nitrate
## [1] 0.98 0.59 0.46 0.31 0.33 0.40 0.30 0.29
gw.nitrate
##  [1] 0.20 0.19 0.20 0.27 0.20 0.23 0.26 0.26 0.27 0.20 0.20

PRUEBA F: Significancia de VARIANZA NITRATO

var.test(S$n.nitrate, gw.nitrate)
## 
##  F test to compare two variances
## 
## data:  S$n.nitrate and gw.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: 0 NO ES SIGNIFICATIVO

PRUEBA T: Significancia de PROMEDIO NITRATO

t.test(S$n.nitrate, gw.nitrate, mu = 0, paired = FALSE, var.equal = FALSE)
## 
##  Welch Two Sample t-test
## 
## data:  S$n.nitrate and gw.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: 1 SI ES SIGNIFICATIVO

promedio sulfato

S.sulphate<-(S$sulphate)
gw.sulphate<-(GW$sulphate)
S.sulphate
## [1] 10.82  4.99  7.04  3.75  1.83  2.81  2.90  2.12
gw.sulphate
##  [1] 2.57 2.43 3.12 2.68 0.81 3.68 4.01 1.41 2.93 1.92 1.43

PRUEBA F:Significancia de VARIANZA 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: 0 NO ES SIGNIFICATIVO

PRUEBA T: Significancia de PROMEDIO NITRATO

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: 1 SI ES SIGNIFICATIVO

si hay diferencias significativas entre ambos promedio de nitrato y sulfato

Gráfca variables para evidenciar la correlación

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

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

No hay correlación

Estimación modelo de regresión lineal

S.nitrate<-(S$n.nitrate)
gw.nitrate<-(GW$n.nitrate)
S.nitrate
## [1] 0.98 0.59 0.46 0.31 0.33 0.40 0.30 0.29
gw.nitrate
##  [1] 0.20 0.19 0.20 0.27 0.20 0.23 0.26 0.26 0.27 0.20 0.20

regresión lineal GW (subterránea)

MODEL1=lm(GW$n.nitrate ~ GW$sulphate)
MODEL1
## 
## Call:
## lm(formula = GW$n.nitrate ~ GW$sulphate)
## 
## Coefficients:
## (Intercept)  GW$sulphate  
##     0.19612      0.01195
summary(MODEL1)
## 
## Call:
## lm(formula = GW$n.nitrate ~ GW$sulphate)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.03517 -0.02296 -0.01012  0.02740  0.04702 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.19612    0.02726   7.193 5.12e-05 ***
## GW$sulphate  0.01195    0.01037   1.153    0.279    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.03245 on 9 degrees of freedom
## Multiple R-squared:  0.1286, Adjusted R-squared:  0.0318 
## F-statistic: 1.328 on 1 and 9 DF,  p-value: 0.2788
plot(MODEL1,which=1)

regresión lineal S (superficial)

MODEL2=lm(S$n.nitrate ~ S$sulphate)
MODEL2
## 
## Call:
## lm(formula = S$n.nitrate ~ S$sulphate)
## 
## Coefficients:
## (Intercept)   S$sulphate  
##     0.14060      0.06992
summary(MODEL2)
## 
## Call:
## lm(formula = S$n.nitrate ~ S$sulphate)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.17281 -0.05572  0.03131  0.06792  0.10051 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept)  0.14060    0.06901   2.037  0.08775 . 
## S$sulphate   0.06992    0.01288   5.429  0.00162 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1041 on 6 degrees of freedom
## Multiple R-squared:  0.8309, Adjusted R-squared:  0.8027 
## F-statistic: 29.48 on 1 and 6 DF,  p-value: 0.001618
plot(MODEL2,which=1)