Importación de datos
if (!requireNamespace("data.table", quietly = TRUE)) install.packages("data.table")
library(data.table)
library(data.table)
DCL <- fread("https://dn790006.ca.archive.org/0/items/byrong_DCL/DCL.txt", header = TRUE, sep = "\t", dec = ",")
print(head(DCL))
## Puntos Dia Hora ppm
## <char> <char> <int> <int>
## 1: Norte Lunes 8 124
## 2: Este Lunes 11 112
## 3: Sur Lunes 14 123
## 4: Oeste Lunes 17 118
## 5: Centro Lunes 20 102
## 6: Sur Miercoles 8 124
Definición de Variables
attach(DCL)
TRC<- factor(DCL$Puntos)
FILA<-factor(DCL$Dia)
COL<-factor(DCL$Hora)
Resp<-as.vector(DCL$ppm)
Resp1<-as.numeric(Resp)
boxplot(split(Resp1,TRC),xlab="Puntos de Ciudad", ylab="Concentraciones de monóxido de carbono")

#Análisis de varianza usando la función modelo lineal (lm) Linear model
DCL.lm <- lm(Resp1 ~ FILA + COL + TRC)
summary(DCL.lm)
##
## Call:
## lm(formula = Resp1 ~ FILA + COL + TRC)
##
## Residuals:
## Min 1Q Median 3Q Max
## -9.08 -2.28 -0.28 3.32 9.32
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 123.480 4.868 25.365 8.57e-12 ***
## FILAS\xe1bado -1.800 4.270 -0.422 0.68078
## FILALunes -11.800 4.270 -2.764 0.01716 *
## FILAMiercoles -9.400 4.270 -2.202 0.04800 *
## FILAViernes -4.200 4.270 -0.984 0.34468
## COL11 -6.200 4.270 -1.452 0.17211
## COL14 0.800 4.270 0.187 0.85450
## COL17 0.600 4.270 0.141 0.89057
## COL20 -2.400 4.270 -0.562 0.58438
## TRCEste 0.800 4.270 0.187 0.85450
## TRCNorte 13.800 4.270 3.232 0.00719 **
## TRCOeste 1.000 4.270 0.234 0.81877
## TRCSur 12.200 4.270 2.857 0.01442 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6.751 on 12 degrees of freedom
## Multiple R-squared: 0.7463, Adjusted R-squared: 0.4925
## F-statistic: 2.941 on 12 and 12 DF, p-value: 0.03678
anova(DCL.lm)
## Analysis of Variance Table
##
## Response: Resp1
## Df Sum Sq Mean Sq F value Pr(>F)
## FILA 4 502.56 125.640 2.7569 0.07757 .
## COL 4 174.16 43.540 0.9554 0.46626
## TRC 4 931.76 232.940 5.1113 0.01224 *
## Residuals 12 546.88 45.573
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Análisis de varianza usando la función (aov) Analysis of Variance
DCL.aov<-aov(Resp1 ~ FILA + COL + TRC)
anova(DCL.aov)
## Analysis of Variance Table
##
## Response: Resp1
## Df Sum Sq Mean Sq F value Pr(>F)
## FILA 4 502.56 125.640 2.7569 0.07757 .
## COL 4 174.16 43.540 0.9554 0.46626
## TRC 4 931.76 232.940 5.1113 0.01224 *
## Residuals 12 546.88 45.573
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(DCL.aov)
## Df Sum Sq Mean Sq F value Pr(>F)
## FILA 4 502.6 125.64 2.757 0.0776 .
## COL 4 174.2 43.54 0.955 0.4663
## TRC 4 931.8 232.94 5.111 0.0122 *
## Residuals 12 546.9 45.57
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(agricolae)
cv.model(DCL.aov)
## [1] 5.526197
Gráfico de Cajas
boxplot(split(Resp1, TRC), xlab = "Puntos de Ciudad", ylab = "Concentraciones de monóxido de carbono")

Análisis de Varianza
DCL.lm <- lm(Resp1 ~ FILA + COL + TRC)
summary(DCL.lm)
##
## Call:
## lm(formula = Resp1 ~ FILA + COL + TRC)
##
## Residuals:
## Min 1Q Median 3Q Max
## -9.08 -2.28 -0.28 3.32 9.32
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 123.480 4.868 25.365 8.57e-12 ***
## FILAS\xe1bado -1.800 4.270 -0.422 0.68078
## FILALunes -11.800 4.270 -2.764 0.01716 *
## FILAMiercoles -9.400 4.270 -2.202 0.04800 *
## FILAViernes -4.200 4.270 -0.984 0.34468
## COL11 -6.200 4.270 -1.452 0.17211
## COL14 0.800 4.270 0.187 0.85450
## COL17 0.600 4.270 0.141 0.89057
## COL20 -2.400 4.270 -0.562 0.58438
## TRCEste 0.800 4.270 0.187 0.85450
## TRCNorte 13.800 4.270 3.232 0.00719 **
## TRCOeste 1.000 4.270 0.234 0.81877
## TRCSur 12.200 4.270 2.857 0.01442 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6.751 on 12 degrees of freedom
## Multiple R-squared: 0.7463, Adjusted R-squared: 0.4925
## F-statistic: 2.941 on 12 and 12 DF, p-value: 0.03678
anova(DCL.lm)
## Analysis of Variance Table
##
## Response: Resp1
## Df Sum Sq Mean Sq F value Pr(>F)
## FILA 4 502.56 125.640 2.7569 0.07757 .
## COL 4 174.16 43.540 0.9554 0.46626
## TRC 4 931.76 232.940 5.1113 0.01224 *
## Residuals 12 546.88 45.573
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
DCL.aov <- aov(Resp1 ~ FILA + COL + TRC)
anova(DCL.aov)
## Analysis of Variance Table
##
## Response: Resp1
## Df Sum Sq Mean Sq F value Pr(>F)
## FILA 4 502.56 125.640 2.7569 0.07757 .
## COL 4 174.16 43.540 0.9554 0.46626
## TRC 4 931.76 232.940 5.1113 0.01224 *
## Residuals 12 546.88 45.573
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(DCL.aov)
## Df Sum Sq Mean Sq F value Pr(>F)
## FILA 4 502.6 125.64 2.757 0.0776 .
## COL 4 174.2 43.54 0.955 0.4663
## TRC 4 931.8 232.94 5.111 0.0122 *
## Residuals 12 546.9 45.57
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Coeficiente de Variación
library(agricolae)
cv.model(DCL.aov)
## [1] 5.526197
Evaluación de Supuestos del Modelo
Prueba de Normalidad Shapiro-Wilk
shapiro.test(DCL.lm$residuals)
##
## Shapiro-Wilk normality test
##
## data: DCL.lm$residuals
## W = 0.97948, p-value = 0.8746
Gráfico QQ Plot
library(car)
## Cargando paquete requerido: carData
qqPlot(DCL.aov)

## [1] 10 13
Gráfico de Valores Predichos vs Residuos Estandarizados
fitc <- fitted(DCL.aov)
res_stc <- rstandard(DCL.aov)
plot(fitc, res_stc, xlab = "Valores predichos", ylab = "Residuos estandarizados")
abline(h = 0)

Prueba de Independencia de Residuos
library(lmtest)
## Cargando paquete requerido: zoo
##
## Adjuntando el paquete: 'zoo'
## The following objects are masked from 'package:data.table':
##
## yearmon, yearqtr
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
dwtest(DCL.lm, order.by = ~ Puntos, data = DCL, alternative = "two.sided")
##
## Durbin-Watson test
##
## data: DCL.lm
## DW = 2.2798, p-value = 0.9786
## alternative hypothesis: true autocorrelation is not 0
Pruebas de Comparación Múltiple de Medias
outLSD <- LSD.test(DCL.aov, "TRC", console = TRUE)
##
## Study: DCL.aov ~ "TRC"
##
## LSD t Test for Resp1
##
## Mean Square Error: 45.57333
##
## TRC, means and individual ( 95 %) CI
##
## Resp1 std r se LCL UCL Min Max Q25 Q50 Q75
## Centro 116.6 14.724130 5 3.019051 110.0221 123.1779 100 133 102 124 124
## Este 117.4 5.366563 5 3.019051 110.8221 123.9779 112 124 112 118 121
## Norte 130.4 3.911521 5 3.019051 123.8221 136.9779 124 134 130 131 133
## Oeste 117.6 4.560702 5 3.019051 111.0221 124.1779 112 122 114 118 122
## Sur 128.8 4.919350 5 3.019051 122.2221 135.3779 123 133 124 131 133
##
## Alpha: 0.05 ; DF Error: 12
## Critical Value of t: 2.178813
##
## least Significant Difference: 9.302621
##
## Treatments with the same letter are not significantly different.
##
## Resp1 groups
## Norte 130.4 a
## Sur 128.8 a
## Oeste 117.6 b
## Este 117.4 b
## Centro 116.6 b
outHSD <- HSD.test(DCL.aov, "TRC", console = TRUE)
##
## Study: DCL.aov ~ "TRC"
##
## HSD Test for Resp1
##
## Mean Square Error: 45.57333
##
## TRC, means
##
## Resp1 std r se Min Max Q25 Q50 Q75
## Centro 116.6 14.724130 5 3.019051 100 133 102 124 124
## Este 117.4 5.366563 5 3.019051 112 124 112 118 121
## Norte 130.4 3.911521 5 3.019051 124 134 130 131 133
## Oeste 117.6 4.560702 5 3.019051 112 122 114 118 122
## Sur 128.8 4.919350 5 3.019051 123 133 124 131 133
##
## Alpha: 0.05 ; DF Error: 12
## Critical Value of Studentized Range: 4.50771
##
## Minimun Significant Difference: 13.609
##
## Treatments with the same letter are not significantly different.
##
## Resp1 groups
## Norte 130.4 a
## Sur 128.8 ab
## Oeste 117.6 ab
## Este 117.4 ab
## Centro 116.6 b
SNK.test(DCL.aov, "TRC", console = TRUE)
##
## Study: DCL.aov ~ "TRC"
##
## Student Newman Keuls Test
## for Resp1
##
## Mean Square Error: 45.57333
##
## TRC, means
##
## Resp1 std r se Min Max Q25 Q50 Q75
## Centro 116.6 14.724130 5 3.019051 100 133 102 124 124
## Este 117.4 5.366563 5 3.019051 112 124 112 118 121
## Norte 130.4 3.911521 5 3.019051 124 134 130 131 133
## Oeste 117.6 4.560702 5 3.019051 112 122 114 118 122
## Sur 128.8 4.919350 5 3.019051 123 133 124 131 133
##
## Alpha: 0.05 ; DF Error: 12
##
## Critical Range
## 2 3 4 5
## 9.302621 11.390664 12.675968 13.609004
##
## Means with the same letter are not significantly different.
##
## Resp1 groups
## Norte 130.4 a
## Sur 128.8 a
## Oeste 117.6 b
## Este 117.4 b
## Centro 116.6 b
scheffe.test(DCL.aov, "TRC", console = TRUE)
##
## Study: DCL.aov ~ "TRC"
##
## Scheffe Test for Resp1
##
## Mean Square Error : 45.57333
##
## TRC, means
##
## Resp1 std r se Min Max Q25 Q50 Q75
## Centro 116.6 14.724130 5 3.019051 100 133 102 124 124
## Este 117.4 5.366563 5 3.019051 112 124 112 118 121
## Norte 130.4 3.911521 5 3.019051 124 134 130 131 133
## Oeste 117.6 4.560702 5 3.019051 112 122 114 118 122
## Sur 128.8 4.919350 5 3.019051 123 133 124 131 133
##
## Alpha: 0.05 ; DF Error: 12
## Critical Value of F: 3.259167
##
## Minimum Significant Difference: 15.41589
##
## Means with the same letter are not significantly different.
##
## Resp1 groups
## Norte 130.4 a
## Sur 128.8 a
## Oeste 117.6 a
## Este 117.4 a
## Centro 116.6 a
duncan.test(DCL.aov, "TRC", console = TRUE)
##
## Study: DCL.aov ~ "TRC"
##
## Duncan's new multiple range test
## for Resp1
##
## Mean Square Error: 45.57333
##
## TRC, means
##
## Resp1 std r se Min Max Q25 Q50 Q75
## Centro 116.6 14.724130 5 3.019051 100 133 102 124 124
## Este 117.4 5.366563 5 3.019051 112 124 112 118 121
## Norte 130.4 3.911521 5 3.019051 124 134 130 131 133
## Oeste 117.6 4.560702 5 3.019051 112 122 114 118 122
## Sur 128.8 4.919350 5 3.019051 123 133 124 131 133
##
## Alpha: 0.05 ; DF Error: 12
##
## Critical Range
## 2 3 4 5
## 9.302621 9.737174 10.000463 10.174719
##
## Means with the same letter are not significantly different.
##
## Resp1 groups
## Norte 130.4 a
## Sur 128.8 a
## Oeste 117.6 b
## Este 117.4 b
## Centro 116.6 b
LSD.test(DCL.aov, "TRC", p.adj= "bon", console = TRUE)
##
## Study: DCL.aov ~ "TRC"
##
## LSD t Test for Resp1
## P value adjustment method: bonferroni
##
## Mean Square Error: 45.57333
##
## TRC, means and individual ( 95 %) CI
##
## Resp1 std r se LCL UCL Min Max Q25 Q50 Q75
## Centro 116.6 14.724130 5 3.019051 110.0221 123.1779 100 133 102 124 124
## Este 117.4 5.366563 5 3.019051 110.8221 123.9779 112 124 112 118 121
## Norte 130.4 3.911521 5 3.019051 123.8221 136.9779 124 134 130 131 133
## Oeste 117.6 4.560702 5 3.019051 111.0221 124.1779 112 122 114 118 122
## Sur 128.8 4.919350 5 3.019051 122.2221 135.3779 123 133 124 131 133
##
## Alpha: 0.05 ; DF Error: 12
## Critical Value of t: 3.428444
##
## Minimum Significant Difference: 14.63802
##
## Treatments with the same letter are not significantly different.
##
## Resp1 groups
## Norte 130.4 a
## Sur 128.8 a
## Oeste 117.6 a
## Este 117.4 a
## Centro 116.6 a
Prueba de Scott-Knott
library(ScottKnott)
sk <- SK(DCL.aov, which = "TRC", dispersion = "se", sig.level = 0.05)
summary(sk)
## Goups of means at sig.level = 0.05
## Means G1 G2
## Norte 130.40 a
## Sur 128.80 a
## Oeste 117.60 b
## Este 117.40 b
## Centro 116.60 b
Limpieza de Memoria
detach(DCL)
rm(list=ls())