Este análisis tiene como objetivo comparar el rendimiento de diferentes variedades de arroz a través de un diseño en bloques completos aleatorios. Se emplea un análisis de varianza (ANOVA) para determinar si existen diferencias significativas entre los tratamientos, y una prueba de comparación de medias de Duncan para identificar cuáles variedades son estadísticamente diferentes entre sí.
Los datos de rendimiento de arroz en toneladas por hectárea están organizados en un diseño en bloques:
rendimientos <- data.frame(
Variedad = rep(c("BR-SI-46-5", "IET-1785", "IR2823-399", "BG-375-1", "CICA"), each = 3),
Bloque = rep(1:3, times = 5),
Rendimiento = c(6.2, 3.1, 7.3,
9.2, 5.7, 8.1,
2.3, 1.4, 2.3,
8.4, 8.4, 8.5,
2.7, 5.4, 7.7)
)
print(rendimientos)
## Variedad Bloque Rendimiento
## 1 BR-SI-46-5 1 6.2
## 2 BR-SI-46-5 2 3.1
## 3 BR-SI-46-5 3 7.3
## 4 IET-1785 1 9.2
## 5 IET-1785 2 5.7
## 6 IET-1785 3 8.1
## 7 IR2823-399 1 2.3
## 8 IR2823-399 2 1.4
## 9 IR2823-399 3 2.3
## 10 BG-375-1 1 8.4
## 11 BG-375-1 2 8.4
## 12 BG-375-1 3 8.5
## 13 CICA 1 2.7
## 14 CICA 2 5.4
## 15 CICA 3 7.7
library(ggplot2)
ggplot(rendimientos, aes(x = Variedad, y = Rendimiento)) +
geom_boxplot(fill = "lightblue", color = "black") +
labs(title = "Diagrama de Cajas por Variedad", y = "Rendimiento (ton/ha)", x = "Variedad") +
theme_minimal()
ggplot(rendimientos, aes(x = factor(Bloque), y = Rendimiento)) +
geom_boxplot(fill = "lightgreen", color = "black") +
labs(title = "Diagrama de Cajas por Bloque", y = "Rendimiento (ton/ha)", x = "Bloque") +
theme_minimal()
modelo <- aov(Rendimiento ~ Variedad + factor(Bloque), data = rendimientos)
summary(modelo)
## Df Sum Sq Mean Sq F value Pr(>F)
## Variedad 4 75.64 18.909 7.894 0.007 **
## factor(Bloque) 2 9.80 4.902 2.046 0.192
## Residuals 8 19.16 2.395
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(agricolae)
duncan_test <- duncan.test(modelo, "Variedad", group = TRUE)
duncan_test$groups
## Rendimiento groups
## BG-375-1 8.433333 a
## IET-1785 7.666667 ab
## BR-SI-46-5 5.533333 ab
## CICA 5.266667 b
## IR2823-399 2.000000 c
bar.group(duncan_test$groups, main = "Prueba de Duncan - Grupos de Medias",
ylab = "Rendimiento (ton/ha)", col = "lightblue")
#Punto 2
if (!requireNamespace("ggplot2", quietly = TRUE)) install.packages("ggplot2")
if (!requireNamespace("dplyr", quietly = TRUE)) install.packages("dplyr")
if (!requireNamespace("knitr", quietly = TRUE)) install.packages("knitr")
if (!requireNamespace("rmarkdown", quietly = TRUE)) install.packages("rmarkdown")
if (!requireNamespace("multcomp", quietly = TRUE)) install.packages("multcomp")
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(knitr)
library(rmarkdown)
library(multcomp)
## Loading required package: mvtnorm
## Loading required package: survival
## Loading required package: TH.data
## Loading required package: MASS
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
##
## Attaching package: 'TH.data'
## The following object is masked from 'package:MASS':
##
## geyser
data <- data.frame(
Temperature = rep(c(20, 30, 40), each = 9),
Sacarosa = rep(c(20, 40, 60), times = 9),
Energy = c(3.1, 3.7, 4.7, 6, 6.9, 7.5, 7.7, 8.3, 9.5,
5.5, 6.7, 7.3, 11.5, 12.9, 13.4, 15.7, 14.3, 15.9,
7.9, 9.2, 9.3, 17.5, 15.8, 14.7, 19.1, 18, 19.9)
)
ggplot(data, aes(x = factor(Sacarosa), y = Energy, fill = factor(Temperature))) +
geom_boxplot() +
labs(title = "Diagrama de Cajas: Energía Gastada por las Abejas",
x = "Concentración de Sacarosa (%)",
y = "Energía (Joules/segundo)",
fill = "Temperatura (°C)") +
theme_minimal()
anova_result <- aov(Energy ~ factor(Temperature) * factor(Sacarosa), data = data)
summary(anova_result)
## Df Sum Sq Mean Sq F value Pr(>F)
## factor(Temperature) 2 310.0 154.98 8.466 0.00256 **
## factor(Sacarosa) 2 4.1 2.06 0.113 0.89401
## factor(Temperature):factor(Sacarosa) 4 2.9 0.74 0.040 0.99664
## Residuals 18 329.5 18.31
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
if (any(summary(anova_result)[[1]]$`Pr(>F)` < 0.05)) {
tukey_result <- TukeyHSD(anova_result)
print(tukey_result)
}
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = Energy ~ factor(Temperature) * factor(Sacarosa), data = data)
##
## $`factor(Temperature)`
## diff lwr upr p adj
## 30-20 5.088889 -0.05863092 10.236409 0.0529600
## 40-20 8.222222 3.07470241 13.369742 0.0019468
## 40-30 3.133333 -2.01418648 8.280853 0.2907125
##
## $`factor(Sacarosa)`
## diff lwr upr p adj
## 40-20 0.2000000 -4.947520 5.347520 0.9945953
## 60-20 0.9111111 -4.236409 6.058631 0.8942626
## 60-40 0.7111111 -4.436409 5.858631 0.9340225
##
## $`factor(Temperature):factor(Sacarosa)`
## diff lwr upr p adj
## 30:20-20:20 5.3000000 -6.940445 17.540445 0.8338222
## 40:20-20:20 9.2333333 -3.007112 21.473779 0.2355367
## 20:40-20:20 0.7000000 -11.540445 12.940445 0.9999999
## 30:40-20:20 5.7000000 -6.540445 17.940445 0.7766663
## 40:40-20:20 8.7333333 -3.507112 20.973779 0.2938678
## 20:60-20:20 1.6333333 -10.607112 13.873779 0.9999010
## 30:60-20:20 6.6000000 -5.640445 18.840445 0.6285562
## 40:60-20:20 9.0333333 -3.207112 21.273779 0.2577536
## 40:20-30:20 3.9333333 -8.307112 16.173779 0.9621211
## 20:40-30:20 -4.6000000 -16.840445 7.640445 0.9134238
## 30:40-30:20 0.4000000 -11.840445 12.640445 1.0000000
## 40:40-30:20 3.4333333 -8.807112 15.673779 0.9828955
## 20:60-30:20 -3.6666667 -15.907112 8.573779 0.9746694
## 30:60-30:20 1.3000000 -10.940445 13.540445 0.9999825
## 40:60-30:20 3.7333333 -8.507112 15.973779 0.9718651
## 20:40-40:20 -8.5333333 -20.773779 3.707112 0.3197920
## 30:40-40:20 -3.5333333 -15.773779 8.707112 0.9796599
## 40:40-40:20 -0.5000000 -12.740445 11.740445 1.0000000
## 20:60-40:20 -7.6000000 -19.840445 4.640445 0.4586490
## 30:60-40:20 -2.6333333 -14.873779 9.607112 0.9969188
## 40:60-40:20 -0.2000000 -12.440445 12.040445 1.0000000
## 30:40-20:40 5.0000000 -7.240445 17.240445 0.8714023
## 40:40-20:40 8.0333333 -4.207112 20.273779 0.3907829
## 20:60-20:40 0.9333333 -11.307112 13.173779 0.9999987
## 30:60-20:40 5.9000000 -6.340445 18.140445 0.7455904
## 40:60-20:40 8.3333333 -3.907112 20.573779 0.3471587
## 40:40-30:40 3.0333333 -9.207112 15.273779 0.9921339
## 20:60-30:40 -4.0666667 -16.307112 8.173779 0.9544453
## 30:60-30:40 0.9000000 -11.340445 13.140445 0.9999990
## 40:60-30:40 3.3333333 -8.907112 15.573779 0.9857297
## 20:60-40:40 -7.1000000 -19.340445 5.140445 0.5423055
## 30:60-40:40 -2.1333333 -14.373779 10.107112 0.9992941
## 40:60-40:40 0.3000000 -11.940445 12.540445 1.0000000
## 30:60-20:60 4.9666667 -7.273779 17.207112 0.8752668
## 40:60-20:60 7.4000000 -4.840445 19.640445 0.4915681
## 40:60-30:60 2.4333333 -9.807112 14.673779 0.9982101
if (!requireNamespace("dplyr", quietly = TRUE)) install.packages("dplyr")
if (!requireNamespace("ggplot2", quietly = TRUE)) install.packages("ggplot2")
library(dplyr)
library(ggplot2)
data_cruda <- read.csv("dm_data.csv")
data_limpia <- data_cruda %>%
filter(!is.na(DM_raw), !is.na(DM_gravity))
correlacion <- cor(data_limpia$DM_raw, data_limpia$DM_gravity, use = "complete.obs")
print(paste("Correlación entre DM_raw y DM_gravity:", correlacion))
## [1] "Correlación entre DM_raw y DM_gravity: 0.656877667803645"
modelo <- lm(DM_gravity ~ DM_raw, data = data_limpia)
summary(modelo)
##
## Call:
## lm(formula = DM_gravity ~ DM_raw, data = data_limpia)
##
## Residuals:
## Min 1Q Median 3Q Max
## -20.3221 -1.6741 0.2114 1.9882 18.1538
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 12.59566 0.86654 14.54 <2e-16 ***
## DM_raw 0.58912 0.02328 25.31 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.327 on 844 degrees of freedom
## Multiple R-squared: 0.4315, Adjusted R-squared: 0.4308
## F-statistic: 640.6 on 1 and 844 DF, p-value: < 2.2e-16
predicciones <- predict(modelo, newdata = data_limpia, interval = "confidence")
resultado_final <- data_limpia %>%
bind_cols(as.data.frame(predicciones)) %>%
rename(Prediccion = fit, Inferior = lwr, Superior = upr)
ggplot(resultado_final, aes(x = DM_raw, y = DM_gravity)) +
geom_point() + # Puntos de datos
geom_smooth(method = "lm", se = TRUE, color = "blue") + # Línea de regresión
geom_line(aes(y = Inferior), linetype = "dashed", color = "red") + # Banda inferior
geom_line(aes(y = Superior), linetype = "dashed", color = "red") + # Banda superior
labs(title = "Regresión Lineal entre DM_raw y DM_gravity",
x = "Materia Seca (DM_raw)",
y = "Materia Seca (DM_gravity)") + theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'