peso_in= c(runif(120, 1.5,2.0))
hum= c(runif(120, 40, 70))
#Variedad
genotipo= gl(2, 60, 120, c('varied1', 'varieda2'))
tiempo= gl(2, 30, 120, c('10', '12'))
df=data.frame(genotipo, tiempo, hum, peso_in )
library(ggplot2)
library(viridis)
## Loading required package: viridisLite
ggplot(data= df, aes( x= genotipo , y=tiempo, color=hum))+
geom_point(size =15, shape=20)+
scale_color_viridis(option = "A")
tapply(df$peso_in, df$tiempo, mean)
## 10 12
## 1.740066 1.740146
tapply(df$peso_in, df$genotipo , mean)
## varied1 varieda2
## 1.716191 1.764021
boxplot(df$peso_in ~ df$tiempo)
lattice::bwplot(df$peso_in ~ df$tiempo | df$genotipo)
modav= aov(peso_in ~ tiempo * genotipo , df)
summary(modav)
## Df Sum Sq Mean Sq F value Pr(>F)
## tiempo 1 0.0000 0.00000 0.000 0.9975
## genotipo 1 0.0686 0.06863 3.628 0.0593 .
## tiempo:genotipo 1 0.0004 0.00039 0.021 0.8854
## Residuals 116 2.1945 0.01892
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
TukeyHSD(modav, 'tiempo')
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = peso_in ~ tiempo * genotipo, data = df)
##
## $tiempo
## diff lwr upr p adj
## 12-10 8.027455e-05 -0.04965731 0.04981786 0.9974549
res1 = modav$residuals
shapiro.test(res1)
##
## Shapiro-Wilk normality test
##
## data: res1
## W = 0.9697, p-value = 0.008262
trat=interaction(df$tiempo, df$genotipo)
bartlett.test(res1, trat)
##
## Bartlett test of homogeneity of variances
##
## data: res1 and trat
## Bartlett's K-squared = 1.0885, df = 3, p-value = 0.7798
Las varianzas de los tratameintos no son diferentes ya que son de 6%
plot(res1)
plot( modav$fitted.values, res1)
Ajustando el modelo
modavb= aov(peso_in ~ tiempo+genotipo, df)
summary(modavb)
## Df Sum Sq Mean Sq F value Pr(>F)
## tiempo 1 0.0000 0.00000 0.000 0.9974
## genotipo 1 0.0686 0.06863 3.658 0.0582 .
## Residuals 117 2.1949 0.01876
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
shapiro.test(modavb$residuals)
##
## Shapiro-Wilk normality test
##
## data: modavb$residuals
## W = 0.96962, p-value = 0.008126
bartlett.test(modavb$residuals, trat)
##
## Bartlett test of homogeneity of variances
##
## data: modavb$residuals and trat
## Bartlett's K-squared = 1.0885, df = 3, p-value = 0.7798
ANCOVA <- aov(df$peso_in ~ df$hum+ df$tiempo)
summary(ANCOVA)
## Df Sum Sq Mean Sq F value Pr(>F)
## df$hum 1 0.0006 0.000623 0.032 0.858
## df$tiempo 1 0.0000 0.000004 0.000 0.989
## Residuals 117 2.2629 0.019341
shapiro.test(ANCOVA$residuals)
##
## Shapiro-Wilk normality test
##
## data: ANCOVA$residuals
## W = 0.965, p-value = 0.003256