ggplot(Huatabampo, aes(x = SNM, y = NF)) + 
  geom_point()

cor.test(SNM, NF, method=c("pearson", "kendall", "spearman"))
## 
##  Pearson's product-moment correlation
## 
## data:  SNM and NF
## t = 15.526, df = 291, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.6052017 0.7312929
## sample estimates:
##     cor 
## 0.67311
nf<-Huatabampo %>%
  filter(NF <=2.9 ) 

ggplot(nf, aes(x = nf$SNM, y = nf$NF)) + 
  geom_point()

cor.test(nf$SNM, nf$NF, method=c("pearson", "kendall", "spearman"))
## 
##  Pearson's product-moment correlation
## 
## data:  nf$SNM and nf$NF
## t = 11.338, df = 164, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.5678834 0.7404278
## sample estimates:
##       cor 
## 0.6628664
#SNM sobre nivel del mar
#NF nivel freatico
#CE
#PPM partes por milon de sal
#PH acidez o alcalinidad
#TEMP temperatura
PPM <- Huatabampo$PPM
PH <- Huatabampo$PH
NF <- Huatabampo$NF
SNM <- Huatabampo$SNM
temperatura<-Huatabampo$TEMP

datos <- data.frame(PPM, PH, NF, SNM,temperatura)

pairs(datos)

cor(datos)
##                    PPM          PH         NF         SNM temperatura
## PPM          1.0000000 -0.54435240 -0.5352205 -0.32158319  0.20043300
## PH          -0.5443524  1.00000000  0.1593932  0.05119597 -0.02029087
## NF          -0.5352205  0.15939323  1.0000000  0.67310998 -0.26663371
## SNM         -0.3215832  0.05119597  0.6731100  1.00000000 -0.19907971
## temperatura  0.2004330 -0.02029087 -0.2666337 -0.19907971  1.00000000
  datos_1<-data.frame(NF,SNM)
  pairs(datos_1)

  cor(datos_1)
##          NF     SNM
## NF  1.00000 0.67311
## SNM 0.67311 1.00000
datos_2<-datos_1 %>%
  filter(NF <=2.9 ) 

pairs(datos_2)

 cor(datos_2)
##            NF       SNM
## NF  1.0000000 0.6628664
## SNM 0.6628664 1.0000000
 regresion <- lm(datos_2$SNM ~ datos_2$NF, data = datos_2)
summary(regresion)
## 
## Call:
## lm(formula = datos_2$SNM ~ datos_2$NF, data = datos_2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.6579 -1.2683 -0.1109  0.8843  4.4633 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -0.2492     0.5331  -0.467    0.641    
## datos_2$NF    2.8220     0.2489  11.338   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.683 on 164 degrees of freedom
## Multiple R-squared:  0.4394, Adjusted R-squared:  0.436 
## F-statistic: 128.5 on 1 and 164 DF,  p-value: < 2.2e-16
plot(datos_2$NF, datos_2$SNM, xlab='nivel freautico', ylab='nivel sobre el mar')
abline(regresion)

Quiero saber cual va ser el nivel del mar cuando el nivel freatico este entre 3 y 4 y la coniabilidad de este resultado

a<-datos_2$NF
nuevos.nivele <- data.frame(a =seq(3,4))

predict(regresion, nuevos.nivele)
## Warning: 'newdata' had 2 rows but variables found have 166 rows
##        1        2        3        4        5        6        7        8 
## 7.313648 7.116111 3.419353 5.789793 5.422939 5.394720 4.350597 7.708721 
##        9       10       11       12       13       14       15       16 
## 5.535817 7.595843 5.761574 5.507598 5.253622 3.870865 6.071988 7.228989 
##       17       18       19       20       21       22       23       24 
## 7.116111 7.031453 5.676915 5.253622 5.874452 4.491695 5.310061 2.488108 
##       25       26       27       28       29       30       31       32 
## 1.923717 4.068402 5.310061 5.592256 5.451159 5.733354 6.354184 7.087892 
##       33       34       35       36       37       38       39       40 
## 5.620476 6.156647 6.636379 5.959110 6.241306 4.604573 3.757987 1.443985 
##       41       42       43       44       45       46       47       48 
## 3.560450 4.802110 5.761574 5.253622 6.354184 7.482965 7.087892 5.959110 
##       49       50       51       52       53       54       55       56 
## 7.059672 5.592256 5.027866 7.087892 4.548134 4.943207 6.692818 6.523501 
##       57       58       59       60       61       62       63       64 
## 6.805696 4.548134 5.168963 5.761574 7.482965 6.438842 6.523501 5.761574 
##       65       66       67       68       69       70       71       72 
## 6.721038 2.826742 7.087892 3.532231 5.874452 5.761574 6.241306 7.087892 
##       73       74       75       76       77       78       79       80 
## 5.112524 2.234132 4.096621 2.854962 4.181280 4.181280 2.290571 4.237719 
##       81       82       83       84       85       86       87       88 
## 1.754400 1.274668 2.770303 4.237719 4.830329 4.463475 6.325964 5.027866 
##       89       90       91       92       93       94       95       96 
## 7.652282 5.592256 6.523501 7.087892 4.040182 3.842646 5.507598 4.802110 
##       97       98       99      100      101      102      103      104 
## 4.773890 7.003233 6.071988 5.761574 6.636379 5.959110 4.830329 7.257209 
##      105      106      107      108      109      110      111      112 
## 7.228989 6.805696 6.946794 2.742084 2.854962 6.805696 6.579940 7.257209 
##      113      114      115      116      117      118      119      120 
## 4.604573 7.059672 6.269525 6.805696 5.281842 7.087892 6.241306 7.370087 
##      121      122      123      124      125      126      127      128 
## 7.341867 7.454746 6.382403 4.548134 4.886768 7.652282 4.350597 6.664599 
##      129      130      131      132      133      134      135      136 
## 6.523501 5.535817 2.967840 5.705135 6.410623 6.805696 6.946794 5.959110 
##      137      138      139      140      141      142      143      144 
## 6.975013 4.661012 6.890355 5.676915 7.228989 4.548134 7.426526 2.036596 
##      145      146      147      148      149      150      151      152 
## 4.209499 6.043769 5.056085 3.391133 3.701548 7.652282 7.116111 7.228989 
##      153      154      155      156      157      158      159      160 
## 5.705135 4.378817 4.830329 7.087892 7.228989 6.805696 6.579940 6.213086 
##      161      162      163      164      165      166 
## 5.930891 7.934478 6.523501 5.676915 7.370087 6.100208
confint(regresion)
##                 2.5 %    97.5 %
## (Intercept) -1.301825 0.8034522
## datos_2$NF   2.330484 3.3134223