#agrupamientos -clusters- multivariados
setwd("~/Dropbox/Clases_UPJ/Ecosistemas/Alumnos/Datos 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), temp.rocio=scale(temp.rocio), vel.viento=scale(vel.viento), 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
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), temp.rocio=scale(temp.rocio), vel.viento=scale(vel.viento), 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))
fit5=lmer(temp.rocio ~ 1 + (1 | lugar/sitio))
fit6=lmer(vel.viento ~ 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: 468
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -6.0561 -0.5294 -0.0488  0.5086  3.2982 
## 
## Random effects:
##  Groups      Name        Variance Std.Dev.
##  sitio:lugar (Intercept) 0.13094  0.3619  
##  lugar       (Intercept) 0.04779  0.2186  
##  Residual                0.87537  0.9356  
## Number of obs: 168, groups:  sitio:lugar, 9; lugar, 2
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept) -0.04225    0.21247  -0.199
summary(fit5)
## Linear mixed model fit by REML ['lmerMod']
## Formula: temp.rocio ~ 1 + (1 | lugar/sitio)
## 
## REML criterion at convergence: 478.9
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -0.7700 -0.2582 -0.1120  0.0327 11.8851 
## 
## Random effects:
##  Groups      Name        Variance Std.Dev.
##  sitio:lugar (Intercept) 0.009084 0.09531 
##  lugar       (Intercept) 0.000000 0.00000 
##  Residual                0.991831 0.99591 
## Number of obs: 168, groups:  sitio:lugar, 9; lugar, 2
## 
## Fixed effects:
##              Estimate Std. Error t value
## (Intercept) -0.004674   0.083692  -0.056
summary(fit6)
## Linear mixed model fit by REML ['lmerMod']
## Formula: vel.viento ~ 1 + (1 | lugar/sitio)
## 
## REML criterion at convergence: 467.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.0959 -0.3952 -0.1230 -0.0258  9.2603 
## 
## Random effects:
##  Groups      Name        Variance Std.Dev.
##  sitio:lugar (Intercept) 0.07361  0.2713  
##  lugar       (Intercept) 0.14842  0.3853  
##  Residual                0.88236  0.9393  
## Number of obs: 168, groups:  sitio:lugar, 9; lugar, 2
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  0.08052    0.29840    0.27
summary(fit7)
## Linear mixed model fit by REML ['lmerMod']
## Formula: luz ~ 1 + (1 | lugar/sitio)
## 
## REML criterion at convergence: 383.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.7418 -0.5458 -0.1146  0.2257  4.7556 
## 
## Random effects:
##  Groups      Name        Variance Std.Dev.
##  sitio:lugar (Intercept) 0.6945   0.8334  
##  lugar       (Intercept) 0.1090   0.3302  
##  Residual                0.4819   0.6942  
## Number of obs: 168, groups:  sitio:lugar, 9; lugar, 2
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)   0.1481     0.3722   0.398
summary(fit8)
## Linear mixed model fit by REML ['lmerMod']
## Formula: ph ~ 1 + (1 | lugar/sitio)
## 
## REML criterion at convergence: 399.9
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.3487 -0.4535  0.1740  0.5508  2.3153 
## 
## Random effects:
##  Groups      Name        Variance Std.Dev.
##  sitio:lugar (Intercept) 0.09937  0.3152  
##  lugar       (Intercept) 0.56235  0.7499  
##  Residual                0.57183  0.7562  
## Number of obs: 168, groups:  sitio:lugar, 9; lugar, 2
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept) -0.04318    0.54533  -0.079
summary(fit9)
## Linear mixed model fit by REML ['lmerMod']
## Formula: humedad.suelo ~ 1 + (1 | lugar/sitio)
## 
## REML criterion at convergence: 433.6
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.75587 -0.81458  0.04952  0.73412  2.34772 
## 
## Random effects:
##  Groups      Name        Variance Std.Dev.
##  sitio:lugar (Intercept) 0.29798  0.5459  
##  lugar       (Intercept) 0.07808  0.2794  
##  Residual                0.68383  0.8269  
## Number of obs: 168, groups:  sitio:lugar, 9; lugar, 2
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept) -0.07699    0.28056  -0.274
summary(fit10)
## Linear mixed model fit by REML ['lmerMod']
## Formula: humedad.amb ~ 1 + (1 | lugar/sitio)
## 
## REML criterion at convergence: 452
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -7.2474 -0.4570  0.0117  0.4259  2.4314 
## 
## Random effects:
##  Groups      Name        Variance  Std.Dev. 
##  sitio:lugar (Intercept) 2.514e-01 5.014e-01
##  lugar       (Intercept) 5.716e-16 2.391e-08
##  Residual                7.763e-01 8.811e-01
## Number of obs: 168, groups:  sitio:lugar, 9; lugar, 2
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept) -0.09524    0.18151  -0.525
#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 = -1.986, df = 160.65, p-value = 0.04873
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.479266992 -0.004176135
## sample estimates:
##  mean in group chingaza mean in group encenillo 
##                15.22899                15.97071
fit12=t.test(temp.rocio~lugar)
fit12
## 
##  Welch Two Sample t-test
## 
## data:  temp.rocio by lugar
## t = 0.86941, df = 77.182, p-value = 0.3873
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.241367  3.165557
## sample estimates:
##  mean in group chingaza mean in group encenillo 
##                13.14391                12.18182
fit13=t.test(vel.viento~lugar)
fit13
## 
##  Welch Two Sample t-test
## 
## data:  vel.viento by lugar
## t = 2.9143, df = 84.505, p-value = 0.004562
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.2075403 1.0990034
## sample estimates:
##  mean in group chingaza mean in group encenillo 
##               0.8724638               0.2191919
fit14=t.test(luz~lugar)
fit14
## 
##  Welch Two Sample t-test
## 
## data:  luz by lugar
## t = 2.7795, df = 112.29, p-value = 0.006384
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   1.737572 10.363526
## sample estimates:
##  mean in group chingaza mean in group encenillo 
##                16.44348                10.39293
fit15=t.test(ph~lugar)
fit15
## 
##  Welch Two Sample t-test
## 
## data:  ph by lugar
## t = -8.3989, df = 93.994, p-value = 4.619e-13
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.911202 -0.562755
## sample estimates:
##  mean in group chingaza mean in group encenillo 
##                5.957971                6.694949
fit16=t.test(humedad.suelo~lugar)
fit16
## 
##  Welch Two Sample t-test
## 
## data:  humedad.suelo by lugar
## t = 4.7089, df = 140.32, p-value = 5.917e-06
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  10.76745 26.35157
## sample estimates:
##  mean in group chingaza mean in group encenillo 
##                67.24638                48.68687
fit17=t.test(humedad.amb~lugar)
fit17
## 
##  Welch Two Sample t-test
## 
## data:  humedad.amb by lugar
## t = 1.8799, df = 94.589, p-value = 0.0632
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.1973163  7.2319584
## sample estimates:
##  mean in group chingaza mean in group encenillo 
##                80.10116                76.58384