set.seed(123)
mu <- c(230,238,240)
ce<- rep(mu, each=40) + rnorm(120,10,4) #Ruido: las medidas dependen de si se toma al interior, en el medio o en el exteriorPosición en la hoja
fol <- gl(3,40,120,c('interior','medio','externo'))boxplot(ce~fol, col = c('#C6E2FF','#B9D3EE','#9FB6CD'))\[H_0: ce_{interior}=ce_{medio}=ce_{exterior} \\H_a: ce_{interior}\neq ce_{medio}\neq ce_{exterior}\]
data.frame(fol,ce) %>%
group_by(fol) %>%
summarise(media_ce=mean(ce),
desv_ce=sd(ce),
cv_ce=100*desv_ce/media_ce)## # A tibble: 3 x 4
## fol media_ce desv_ce cv_ce
## <fct> <dbl> <dbl> <dbl>
## 1 interior 240. 3.59 1.50
## 2 medio 248. 3.84 1.55
## 3 externo 250. 3.38 1.35
aov<- aov(ce~fol)
summary(aov)## Df Sum Sq Mean Sq F value Pr(>F)
## fol 2 2160 1080 83 <2e-16 ***
## Residuals 117 1522 13
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
NOTA: 83 veces mas grandes la varibilidad debida al los tratamientos que la debida a las repetición -> Rechazo \(H_0\)
Rediduales: las repeticiones y cualquier otra fuente de variación
\[\require{color} y_{ij}= \mu + \color{red} \phi_i + \color{blue}\epsilon_{ij}\\ i=1,2,3;\ j=1,...,40\] Una vez planteado el modelo se estiman los parametros del mismo
\(\mu\): Media global de conductancia estomatica
\(\phi_1\): Efecto del follaje interior
\(\phi_1\): Efecto del follaje medio
\(\phi_1\): Efecto del follaje externo
\(\epsilon_{ij}\): residuales
modelo -> estimar el efecto
Más ecuaciones que incognitas -> sistema de ecuaciones con multiples soluciones
\[\begin{matrix} 2x+y+3z &=& 6\\ x+y+z &=& 3\\ x+3y+2z &=& 6\\ 2x+4y+z &=& 7\\ \end{matrix}\]
mat_a1 <- matrix(c(2, 1, 1, 2,
1, 1, 3, 4,
3, 1, 2,1),
nrow = 4)
mat_a1 ## [,1] [,2] [,3]
## [1,] 2 1 3
## [2,] 1 1 1
## [3,] 1 3 2
## [4,] 2 4 1
mat_b1 <- matrix(c(6,
3,
6,
7),
nrow = 4)
mat_b1 ## [,1]
## [1,] 6
## [2,] 3
## [3,] 6
## [4,] 7
qr.solve(mat_a1, mat_b1) ## [,1]
## [1,] 1
## [2,] 1
## [3,] 1
\[\hat{\mu}= \bar{\bar{y}}\]
\[\hat{\phi_1}= \bar{y_1}-\bar{\bar{y}}\]
\[\hat{\phi_2}= \bar{y_2}-\bar{\bar{y}}\]
\[\hat{\phi_1}+\hat{\phi_2}+\hat{\phi_3}=0\]
## Efectos
tapply(ce,fol,mean)## interior medio externo
## 240.1807 247.9731 250.0314
tapply(ce,fol,mean)-mean(ce)## interior medio externo
## -5.881033 1.911370 3.969662
sum(tapply(ce,fol,mean)-mean(ce))## [1] 5.684342e-14
boxplot(ce~fol,col=c('#C6E2FF','#B9D3EE','#9FB6CD'))
abline(h=mean(ce), col='#63B8FF', lwd=2)
mce <-tapply(ce,fol,mean)
points(1:3,mce,pch=16,cex=1.1,
col=ifelse(mce<mean(ce),'red','green'))Efecto negativo(\(\neq\) malo) -> estar por debajo de la media global
Efecto positvo -> estar por encima de la media global
El ánalisis de varianza sirve para evaluar el efecto
El modelo permite estimar el efecto
res <- aov$residuals
hist(res,col = '#C6E2FF',border = '#9FB6CD')shapiro.test(res)##
## Shapiro-Wilk normality test
##
## data: res
## W = 0.99449, p-value = 0.9222
p-value > o.o5 -> los residuales son normales
Igualdad de varianzas (homocedasticidad)
bartlett.test(res,fol)##
## Bartlett test of homogeneity of variances
##
## data: res and fol
## Bartlett's K-squared = 0.63501, df = 2, p-value = 0.728
\[H_0: \mu_{R}ce_{interior}=\mu_{R}ce_{medio}=\mu_{R}ce_{exterior} \\H_a: ce_{interior}\neq ce_{medio}\neq ce_{exterior}\]
rang_grup = c(
rank(ce[fol=='interior']),
rank(ce[fol=='medio']),
rank(ce[fol=='externo'])
)
df = data.frame(fol, ce, rang_grup)
df$rang_tot = rank(ce)
df %>%
group_by(fol) %>%
summarise(med_rang_grup = mean(rang_grup),
med_rang_tot = mean(rang_tot))## # A tibble: 3 x 3
## fol med_rang_grup med_rang_tot
## <fct> <dbl> <dbl>
## 1 interior 20.5 23.6
## 2 medio 20.5 71.6
## 3 externo 20.5 86.2
kruskal.test(ce,fol)##
## Kruskal-Wallis rank sum test
##
## data: ce and fol
## Kruskal-Wallis chi-squared = 70.938, df = 2, p-value = 3.945e-16
perm.anova(ce~fol, nperm= 10000) #library(RVAideMemoire)##
|
| | 0%
|
|= | 1%
|
|= | 2%
|
|== | 3%
|
|=== | 4%
|
|==== | 5%
|
|==== | 6%
|
|===== | 7%
|
|====== | 8%
|
|====== | 9%
|
|======= | 10%
|
|======== | 11%
|
|======== | 12%
|
|========= | 13%
|
|========== | 14%
|
|========== | 15%
|
|=========== | 16%
|
|============ | 17%
|
|============= | 18%
|
|============= | 19%
|
|============== | 20%
|
|=============== | 21%
|
|=============== | 22%
|
|================ | 23%
|
|================= | 24%
|
|================== | 25%
|
|================== | 26%
|
|=================== | 27%
|
|==================== | 28%
|
|==================== | 29%
|
|===================== | 30%
|
|====================== | 31%
|
|====================== | 32%
|
|======================= | 33%
|
|======================== | 34%
|
|======================== | 35%
|
|========================= | 36%
|
|========================== | 37%
|
|=========================== | 38%
|
|=========================== | 39%
|
|============================ | 40%
|
|============================= | 41%
|
|============================= | 42%
|
|============================== | 43%
|
|=============================== | 44%
|
|================================ | 45%
|
|================================ | 46%
|
|================================= | 47%
|
|================================== | 48%
|
|================================== | 49%
|
|=================================== | 50%
|
|==================================== | 51%
|
|==================================== | 52%
|
|===================================== | 53%
|
|====================================== | 54%
|
|====================================== | 55%
|
|======================================= | 56%
|
|======================================== | 57%
|
|========================================= | 58%
|
|========================================= | 59%
|
|========================================== | 60%
|
|=========================================== | 61%
|
|=========================================== | 62%
|
|============================================ | 63%
|
|============================================= | 64%
|
|============================================== | 65%
|
|============================================== | 66%
|
|=============================================== | 67%
|
|================================================ | 68%
|
|================================================ | 69%
|
|================================================= | 70%
|
|================================================== | 71%
|
|================================================== | 72%
|
|=================================================== | 73%
|
|==================================================== | 74%
|
|==================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 77%
|
|======================================================= | 78%
|
|======================================================= | 79%
|
|======================================================== | 80%
|
|========================================================= | 81%
|
|========================================================= | 82%
|
|========================================================== | 83%
|
|=========================================================== | 84%
|
|============================================================ | 85%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|============================================================== | 88%
|
|============================================================== | 89%
|
|=============================================================== | 90%
|
|================================================================ | 91%
|
|================================================================ | 92%
|
|================================================================= | 93%
|
|================================================================== | 94%
|
|================================================================== | 95%
|
|=================================================================== | 96%
|
|==================================================================== | 97%
|
|===================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 100%
## Permutation Analysis of Variance Table
##
## Response: ce
## 10000 permutations
## Sum Sq Df Mean Sq F value Pr(>F)
## fol 2159.9 2 1079.96 83.004 9.999e-05 ***
## Residuals 1522.3 117 13.01
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
*Se rechaza \(H_0\)