#agrupamientos -clusters- multivariados
setwd("~/Dropbox/Clases_UPJ/Ecosistemas/2017_1/Alumnos/Salida") # selección directorio de trabajo
campo=read.table("cluster.txt", header=T) # lectura de la base de datos
campo2=transform(campo, temp.amb=scale(temp.amb), luz=scale(luz), ph=scale(ph), humedad.suelo=scale(humedad.suelo), humedad.amb=scale(humedad.amb)) # estandarizar variables
d <- dist(campo2, method = "euclidean") # matriz de distancias
## Warning in dist(campo2, method = "euclidean"): NAs introduced by coercion
fit <- hclust(d, method="ward.D") # genera cluster jerarquico
plot(fit) # dibuja el cluster

#componentes de varianza
campo3=read.table("compilada2.txt", header=T) # lectura de la base de datos
campo4=transform(campo3, temp.amb=scale(temp.amb), luz=scale(luz), ph=scale(ph), humedad.suelo=scale(humedad.suelo), humedad.amb=scale(humedad.amb)) # estandarizar variables
attach(campo4)
library(lme4)
## Loading required package: Matrix

fit4=lmer(temp.amb ~ 1 + (1 | lugar/sitio))
fit7=lmer(luz ~ 1 + (1 | lugar/sitio))
fit8=lmer(ph ~ 1 + (1 | lugar/sitio))
fit9=lmer(humedad.suelo ~ 1 + (1 | lugar/sitio))
fit10=lmer(humedad.amb ~ 1 + (1 | lugar/sitio))
summary(fit4)
## Linear mixed model fit by REML ['lmerMod']
## Formula: temp.amb ~ 1 + (1 | lugar/sitio)
## 
## REML criterion at convergence: 292.9
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.2344 -0.6120  0.0062  0.5538  2.6526 
## 
## Random effects:
##  Groups      Name        Variance Std.Dev.
##  sitio:lugar (Intercept) 0.0000   0.0000  
##  lugar       (Intercept) 0.4821   0.6943  
##  Residual                0.7606   0.8721  
## Number of obs: 112, groups:  sitio:lugar, 9; lugar, 2
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept) -0.06051    0.49794  -0.122
summary(fit7)
## Linear mixed model fit by REML ['lmerMod']
## Formula: luz ~ 1 + (1 | lugar/sitio)
## 
## REML criterion at convergence: 296.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.9530 -0.6239 -0.1792  0.5578  3.1629 
## 
## Random effects:
##  Groups      Name        Variance  Std.Dev. 
##  sitio:lugar (Intercept) 3.180e-01 5.639e-01
##  lugar       (Intercept) 2.317e-16 1.522e-08
##  Residual                7.069e-01 8.408e-01
## Number of obs: 112, groups:  sitio:lugar, 9; lugar, 2
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  0.02195    0.20415   0.108
summary(fit8)
## Linear mixed model fit by REML ['lmerMod']
## Formula: ph ~ 1 + (1 | lugar/sitio)
## 
## REML criterion at convergence: 306.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.2457 -0.5442  0.0230  0.6291  1.8649 
## 
## Random effects:
##  Groups      Name        Variance  Std.Dev. 
##  sitio:lugar (Intercept) 2.298e-01 4.793e-01
##  lugar       (Intercept) 1.154e-14 1.074e-07
##  Residual                7.925e-01 8.902e-01
## Number of obs: 112, groups:  sitio:lugar, 9; lugar, 2
## 
## Fixed effects:
##              Estimate Std. Error t value
## (Intercept) -0.004149   0.180660  -0.023
summary(fit9)
## Linear mixed model fit by REML ['lmerMod']
## Formula: humedad.suelo ~ 1 + (1 | lugar/sitio)
## 
## REML criterion at convergence: 247.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.6273 -0.7710  0.1190  0.7197  2.7117 
## 
## Random effects:
##  Groups      Name        Variance Std.Dev.
##  sitio:lugar (Intercept) 0.3851   0.6206  
##  lugar       (Intercept) 0.4562   0.6755  
##  Residual                0.4281   0.6543  
## Number of obs: 112, groups:  sitio:lugar, 9; lugar, 2
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  0.04549    0.52464   0.087
summary(fit10)
## Linear mixed model fit by REML ['lmerMod']
## Formula: humedad.amb ~ 1 + (1 | lugar/sitio)
## 
## REML criterion at convergence: 315.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -6.8080 -0.4469  0.0283  0.5167  2.4925 
## 
## Random effects:
##  Groups      Name        Variance Std.Dev.
##  sitio:lugar (Intercept) 0.02915  0.1707  
##  lugar       (Intercept) 0.09979  0.3159  
##  Residual                0.92506  0.9618  
## Number of obs: 112, groups:  sitio:lugar, 9; lugar, 2
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  0.02285    0.24808   0.092
#diferencias entre lugares
detach(campo4)
attach(campo3)
fit11=t.test(temp.amb~lugar)
fit11
## 
##  Welch Two Sample t-test
## 
## data:  temp.amb by lugar
## t = -6.0102, df = 104.27, p-value = 2.757e-08
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -2.811859 -1.416713
## sample estimates:
##  mean in group Chingaza mean in group Encenillo 
##                16.60000                18.71429
fit14=t.test(luz~lugar)
fit14
## 
##  Welch Two Sample t-test
## 
## data:  luz by lugar
## t = 0.95601, df = 92.938, p-value = 0.3415
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -2.104253  6.011147
## sample estimates:
##  mean in group Chingaza mean in group Encenillo 
##               10.846939                8.893492
fit15=t.test(ph~lugar)
fit15
## 
##  Welch Two Sample t-test
## 
## data:  ph by lugar
## t = -1.0126, df = 105.67, p-value = 0.3135
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.26426603  0.08558123
## sample estimates:
##  mean in group Chingaza mean in group Encenillo 
##                6.383673                6.473016
fit16=t.test(humedad.suelo~lugar)
fit16
## 
##  Welch Two Sample t-test
## 
## data:  humedad.suelo by lugar
## t = 6.2518, df = 82.625, p-value = 1.695e-08
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  18.61982 35.99696
## sample estimates:
##  mean in group Chingaza mean in group Encenillo 
##                69.81633                42.50794
fit17=t.test(humedad.amb~lugar)
fit17
## 
##  Welch Two Sample t-test
## 
## data:  humedad.amb by lugar
## t = 2.5046, df = 73.967, p-value = 0.01446
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.9891629 8.6870275
## sample estimates:
##  mean in group Chingaza mean in group Encenillo 
##                73.97143                69.13333