Analisis estadístico muestreo número 2

library(readxl)
library(ggplot2)
library(car)
## Loading required package: carData
DM_2 <- read_excel("C:/Users/USUARIO/Downloads/fisio/M2/muestreo_2.xlsx")
names(DM_2) <- c('DEF', 'N', 'T', 'E_A', 'E_C', 'E_T', 'CRC', 'N_H', 'Long', 'AF', 'CRA', 'Diam', 'PF', 'PS', 'PE', 'trt')
DM_2
## # A tibble: 16 x 16
##    DEF   N         T   E_A   E_C   E_T   CRC   N_H  Long    AF   CRA  Diam    PF
##    <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
##  1 SD    SN       17    21    18    39  36.1     5    11  72.5  91.4    21  7.21
##  2 SD    SN       18    22    17    39  35.8     4    11  75.1  90.0    20  7.16
##  3 SD    SN       18    21    17    38  35.7     5    11  74.3  95.9    23  7.3 
##  4 SD    SN       18    24    16    40  36.2     5    11  72.5  92.0    20  7.27
##  5 SD    CN       18    21    18    39  38.9     5    11  82.7  82.2    24  7.36
##  6 SD    CN       17    21    19    40  40.1     5    11  81.9  89.5    24  7.29
##  7 SD    CN       17    18    21    39  41.2     6    12  83.2  91.1    23  7.31
##  8 SD    CN       17    23    18    41  39.7     4    12  82.6  87.1    23  7.33
##  9 CD    SN       17    25    12    37  38.1     4    10  48.2  80.8    19  5.13
## 10 CD    SN       17    28    11    39  37.8     4    11  48.3  84.8    18  4.97
## 11 CD    SN       17    25    13    38  37.8     5    10  48.8  79.2    20  5.13
## 12 CD    SN       17    27    12    39  37.5     4    10  48.3  88.8    19  5.25
## 13 CD    CN       17    20    21    41  38.7     4    11  57.3  89.7    19  5.97
## 14 CD    CN       17    22    19    41  39.1     4    11  58.0  85.7    20  5.85
## 15 CD    CN       18    18    21    39  39.2     5    10  58.0  91.6    19  6.01
## 16 CD    CN       17    23    20    43  38.9     5    11  57.3  84.2    21  5.89
## # ... with 3 more variables: PS <dbl>, PE <dbl>, trt <chr>
DM_22 <- as.data.frame(DM_2)
ggplot(data = DM_2, aes(x = DEF, y = T, color = DEF)) +
    geom_boxplot() +
    theme_bw()

ggplot(data = DM_2, aes(x = N, y = T, color = N)) +
    geom_boxplot() +
    theme_bw()

ggplot(data = DM_2, aes(x = DEF, y = E_A , color = DEF)) +
    geom_boxplot() +
    theme_bw()

ggplot(data = DM_2, aes(x = N, y = E_A , color = N)) +
    geom_boxplot() +
    theme_bw()

ggplot(data = DM_2, aes(x = DEF, y = E_C, color = DEF)) +
    geom_boxplot() +
    theme_bw()

ggplot(data = DM_2, aes(x = DEF, y = E_T, color = DEF)) +
    geom_boxplot() +
    theme_bw()

ggplot(data = DM_2, aes(x = DEF, y = CRC, color = DEF)) +
    geom_boxplot() +
    theme_bw()

ggplot(data = DM_2, aes(x = DEF, y = N_H, color = DEF)) +
    geom_boxplot() +
    theme_bw()

ggplot(data = DM_2, aes(x = DEF, y = Long, color = DEF)) +
    geom_boxplot() +
    theme_bw()

ggplot(data = DM_2, aes(x = DEF, y = AF, color = DEF)) +
    geom_boxplot() +
    theme_bw()

ggplot(data = DM_2, aes(x = DEF, y = CRA, color = DEF)) +
    geom_boxplot() +
    theme_bw()

ggplot(data = DM_2, aes(x = DEF, y = Diam, color = DEF)) +
    geom_boxplot() +
    theme_bw()

ggplot(data = DM_2, aes(x = DEF, y = PF, color = DEF)) +
    geom_boxplot() +
    theme_bw()

ggplot(data = DM_2, aes(x = DEF, y = PS, color = DEF)) +
    geom_boxplot() +
    theme_bw()

ggplot(data = DM_2, aes(x = DEF, y = PE, color = DEF)) +
    geom_boxplot() +
    theme_bw()

spT <- shapiro.test(DM_2$T)
spT
## 
##  Shapiro-Wilk normality test
## 
## data:  DM_2$T
## W = 0.59088, p-value = 1.33e-05
spE_A <- shapiro.test(DM_2$E_A)
spE_A
## 
##  Shapiro-Wilk normality test
## 
## data:  DM_2$E_A
## W = 0.95804, p-value = 0.6264
spE_C <- shapiro.test(DM_2$E_C)
spE_C
## 
##  Shapiro-Wilk normality test
## 
## data:  DM_2$E_C
## W = 0.8903, p-value = 0.05631
spE_T <- shapiro.test(DM_2$E_T)
spE_T
## 
##  Shapiro-Wilk normality test
## 
## data:  DM_2$E_T
## W = 0.91445, p-value = 0.1373
spCRC <- shapiro.test(DM_2$CRC)
spCRC
## 
##  Shapiro-Wilk normality test
## 
## data:  DM_2$CRC
## W = 0.95213, p-value = 0.5241
spN_H <- shapiro.test(DM_2$N_H)
spN_H
## 
##  Shapiro-Wilk normality test
## 
## data:  DM_2$N_H
## W = 0.76031, p-value = 0.0008479
spLong <- shapiro.test(DM_2$Long)
spLong
## 
##  Shapiro-Wilk normality test
## 
## data:  DM_2$Long
## W = 0.77824, p-value = 0.001421
spAF <- shapiro.test(DM_2$AF)
spAF
## 
##  Shapiro-Wilk normality test
## 
## data:  DM_2$AF
## W = 0.8583, p-value = 0.01809
spCRA <- shapiro.test(DM_2$CRA)
spCRA
## 
##  Shapiro-Wilk normality test
## 
## data:  DM_2$CRA
## W = 0.96172, p-value = 0.693
spDiam <- shapiro.test(DM_2$Diam)
spDiam
## 
##  Shapiro-Wilk normality test
## 
## data:  DM_2$Diam
## W = 0.88747, p-value = 0.05081
spPF <- shapiro.test(DM_2$PF)
spPF
## 
##  Shapiro-Wilk normality test
## 
## data:  DM_2$PF
## W = 0.80577, p-value = 0.003253
spPS <- shapiro.test(DM_2$PS)
spPS
## 
##  Shapiro-Wilk normality test
## 
## data:  DM_2$PS
## W = 0.92794, p-value = 0.2261
spPE <- shapiro.test(DM_2$PE)
spPE
## 
##  Shapiro-Wilk normality test
## 
## data:  DM_2$PE
## W = 0.89213, p-value = 0.06019
### PARA TEMPERATURA, NÚMERO DE HOJAS, LONGITUD, AREA FOLIAR, DIAMETRO, PESO FRESCO

# T
leveneTest(T ~ trt, data = DM_2, center = "median")
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = "median")
##       Df F value Pr(>F)
## group  3  0.3333 0.8015
##       12
kruskal.test(T ~ trt, data = DM_2)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  T by trt
## Kruskal-Wallis chi-squared = 5.1818, df = 3, p-value = 0.159
pairwise.wilcox.test(x = DM_2$T, g = DM_2$trt, p.adjust.method = "holm" )
## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties
## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties

## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties

## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties

## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties

## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties
## 
##  Pairwise comparisons using Wilcoxon rank sum test with continuity correction 
## 
## data:  DM_2$T and DM_2$trt 
## 
##    T1   T2   T3  
## T2 1.00 -    -   
## T3 0.36 1.00 -   
## T4 1.00 1.00 1.00
## 
## P value adjustment method: holm
# NH
leveneTest(N_H ~ trt, data = DM_2, center = "median")
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = "median")
##       Df F value Pr(>F)
## group  3     0.4 0.7555
##       12
kruskal.test(N_H ~ trt, data = DM_2)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  N_H by trt
## Kruskal-Wallis chi-squared = 3.0625, df = 3, p-value = 0.3821
pairwise.wilcox.test(x = DM_2$N_H, g = DM_2$trt, p.adjust.method = "holm" )
## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties

## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties

## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties

## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties

## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties

## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties
## 
##  Pairwise comparisons using Wilcoxon rank sum test with continuity correction 
## 
## data:  DM_2$N_H and DM_2$trt 
## 
##    T1 T2 T3
## T2 1  -  - 
## T3 1  1  - 
## T4 1  1  1 
## 
## P value adjustment method: holm
#LONGITUD
leveneTest(Long ~ trt, data = DM_2, center = "median")
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = "median")
##       Df F value Pr(>F)
## group  3  1.3333 0.3096
##       12
kruskal.test(Long ~ trt, data = DM_2)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  Long by trt
## Kruskal-Wallis chi-squared = 8.4821, df = 3, p-value = 0.03703
pairwise.wilcox.test(x = DM_2$Long, g = DM_2$trt, p.adjust.method = "holm" )
## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties

## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties

## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties

## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties

## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties

## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties
## 
##  Pairwise comparisons using Wilcoxon rank sum test with continuity correction 
## 
## data:  DM_2$Long and DM_2$trt 
## 
##    T1   T2   T3  
## T2 0.54 -    -   
## T3 0.30 0.28 -   
## T4 0.54 0.53 0.54
## 
## P value adjustment method: holm
#AREA FOLIAR
leveneTest(AF ~ trt, data = DM_2, center = "median")
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = "median")
##       Df F value   Pr(>F)   
## group  3  8.8267 0.002308 **
##       12                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
kruskal.test(AF ~ trt, data = DM_2)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  AF by trt
## Kruskal-Wallis chi-squared = 14.118, df = 3, p-value = 0.002749
pairwise.wilcox.test(x = DM_2$AF, g = DM_2$trt, p.adjust.method = "holm" )
## 
##  Pairwise comparisons using Wilcoxon rank sum exact test 
## 
## data:  DM_2$AF and DM_2$trt 
## 
##    T1   T2   T3  
## T2 0.17 -    -   
## T3 0.17 0.17 -   
## T4 0.17 0.17 0.17
## 
## P value adjustment method: holm
#DIAMETRO
leveneTest(Diam ~ trt, data = DM_2, center = "median")
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = "median")
##       Df F value Pr(>F)
## group  3  0.5789 0.6399
##       12
kruskal.test(Diam ~ trt, data = DM_2)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  Diam by trt
## Kruskal-Wallis chi-squared = 11.153, df = 3, p-value = 0.01093
pairwise.wilcox.test(x = DM_2$Diam, g = DM_2$trt, p.adjust.method = "holm" )
## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties

## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties

## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties

## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties

## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties

## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties
## 
##  Pairwise comparisons using Wilcoxon rank sum test with continuity correction 
## 
## data:  DM_2$Diam and DM_2$trt 
## 
##    T1   T2   T3  
## T2 0.21 -    -   
## T3 0.21 0.16 -   
## T4 0.46 0.16 0.46
## 
## P value adjustment method: holm
#PESO SECO
leveneTest(PS ~ trt, data = DM_2, center = "median")
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = "median")
##       Df F value Pr(>F)
## group  3  1.5927 0.2427
##       12
kruskal.test(PS ~ trt, data = DM_2)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  PS by trt
## Kruskal-Wallis chi-squared = 12.465, df = 3, p-value = 0.005949
pairwise.wilcox.test(x = DM_2$PS, g = DM_2$trt, p.adjust.method = "holm" )
## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot compute
## exact p-value with ties
## 
##  Pairwise comparisons using Wilcoxon rank sum exact test 
## 
## data:  DM_2$PS and DM_2$trt 
## 
##    T1   T2   T3  
## T2 0.17 -    -   
## T3 0.17 0.17 -   
## T4 0.34 0.17 0.17
## 
## P value adjustment method: holm
#############################

### TEST DE LEVENE
leveneTest(y = DM_2$T, group = DM_2$trt, center = "median")
## Warning in leveneTest.default(y = DM_2$T, group = DM_2$trt, center = "median"):
## DM_2$trt coerced to factor.
## Levene's Test for Homogeneity of Variance (center = "median")
##       Df F value Pr(>F)
## group  3  0.3333 0.8015
##       12
###GRÁFICAS DE INTERACCIÓN
#T
ggplot(data = DM_2, aes(x = N, y = T, colour = DEF,
                         group = DEF)) +
    stat_summary(fun = mean, geom = "point") +
    stat_summary(fun = mean, geom = "line") +
    labs(y  =  'Temperatura') +
    theme_bw()

ggplot(data = DM_2, aes(x = DEF, y = T, colour = N,
                         group = N)) +
    stat_summary(fun = mean, geom = "point") +
    stat_summary(fun = mean, geom = "line") +
    labs(y  =  'Temperatura') +
    theme_bw()

#E_A
ggplot(data = DM_2, aes(x = N, y = E_A, colour = DEF,
                         group = DEF)) +
    stat_summary(fun = mean, geom = "point") +
    stat_summary(fun = mean, geom = "line") +
    labs(y  =  'Temperatura') +
    theme_bw()

ggplot(data = DM_2, aes(x = DEF, y = E_A, colour = N,
                         group = N)) +
    stat_summary(fun = mean, geom = "point") +
    stat_summary(fun = mean, geom = "line") +
    labs(y  =  'Temperatura') +
    theme_bw()

#E_C
ggplot(data = DM_2, aes(x = N, y = E_C, colour = DEF,
                         group = DEF)) +
    stat_summary(fun = mean, geom = "point") +
    stat_summary(fun = mean, geom = "line") +
    labs(y  =  'Temperatura') +
    theme_bw()

ggplot(data = DM_2, aes(x = DEF, y = E_C, colour = N,
                         group = N)) +
    stat_summary(fun = mean, geom = "point") +
    stat_summary(fun = mean, geom = "line") +
    labs(y  =  'Temperatura') +
    theme_bw()

#E_T
ggplot(data = DM_2, aes(x = N, y = E_T, colour = DEF,
                         group = DEF)) +
    stat_summary(fun = mean, geom = "point") +
    stat_summary(fun = mean, geom = "line") +
    labs(y  =  'Temperatura') +
    theme_bw()

ggplot(data = DM_2, aes(x = DEF, y = E_T, colour = N,
                         group = N)) +
    stat_summary(fun = mean, geom = "point") +
    stat_summary(fun = mean, geom = "line") +
    labs(y  =  'Temperatura') +
    theme_bw()

### Anovas
#T
anovaT <- aov(DM_2$T ~ DM_2$N * DM_2$DEF)
summary(anovaT) ########## esta mal, porque los datos no tienen normalidad
##                 Df Sum Sq Mean Sq F value Pr(>F)
## DM_2$N           1 0.0625  0.0625   0.333  0.574
## DM_2$DEF         1 0.5625  0.5625   3.000  0.109
## DM_2$N:DM_2$DEF  1 0.5625  0.5625   3.000  0.109
## Residuals       12 2.2500  0.1875
#E_A
anovaE_A <- aov(DM_2$E_A ~ DM_2$N * DM_2$DEF)
summary(anovaE_A)
##                 Df Sum Sq Mean Sq F value  Pr(>F)   
## DM_2$N           1  45.56   45.56  13.584 0.00312 **
## DM_2$DEF         1  18.06   18.06   5.385 0.03873 * 
## DM_2$N:DM_2$DEF  1  18.06   18.06   5.385 0.03873 * 
## Residuals       12  40.25    3.35                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#E_C
anovaE_C <- aov(DM_2$E_C ~ DM_2$N * DM_2$DEF)
summary(anovaE_C)
##                 Df Sum Sq Mean Sq F value   Pr(>F)    
## DM_2$N           1 105.06  105.06   98.88 3.81e-07 ***
## DM_2$DEF         1  14.06   14.06   13.23   0.0034 ** 
## DM_2$N:DM_2$DEF  1  39.06   39.06   36.77 5.64e-05 ***
## Residuals       12  12.75    1.06                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#E_T
anovaE_T <- aov(DM_2$E_T ~ DM_2$N * DM_2$DEF)
summary(anovaE_T)
##                 Df Sum Sq Mean Sq F value  Pr(>F)   
## DM_2$N           1  12.25  12.250   9.484 0.00955 **
## DM_2$DEF         1   0.25   0.250   0.194 0.66780   
## DM_2$N:DM_2$DEF  1   4.00   4.000   3.097 0.10389   
## Residuals       12  15.50   1.292                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#### comprobar supuestos
#T
plot(anovaT, 1)

plot(anovaT, 2)

#E_A
plot(anovaE_A, 1)

plot(anovaE_A, 2)

#E_C
plot(anovaE_C, 1)

plot(anovaE_C, 2)

#E_T
plot(anovaE_T, 1)

plot(anovaE_T, 2)

resistencia <- c(15.29, 15.89, 16.02, 16.56, 15.46, 16.91, 16.99, 17.27, 16.85,
                 16.35, 17.23, 17.81, 17.74, 18.02, 18.37, 12.07, 12.42, 12.73,
                 13.02, 12.05, 12.92, 13.01, 12.21, 13.49, 14.01, 13.30, 12.82,
                 12.49, 13.55, 14.53)
templado <- c(rep(c("rapido", "lento"), c(15,15)))
grosor <- rep(c(8, 16, 24), each = 5, times = 2)
datos <- data.frame(templado = templado, grosor = as.factor(grosor),
                    resistencia = resistencia)
head(datos)
##   templado grosor resistencia
## 1   rapido      8       15.29
## 2   rapido      8       15.89
## 3   rapido      8       16.02
## 4   rapido      8       16.56
## 5   rapido      8       15.46
## 6   rapido     16       16.91