PRUEBA DE ANDERSON DARLING

datos <- c(0.824, 0.216, 0.538, 0.685, 0.448, 0.348, 0.443, 0.722, 0.403, 0.268, 0.440, 0.087)
grupos <- c("z1", "z1", "z1", "z1", "z2", "z2", "z2", "z2", "z3", "z3", "z3", "z3")
library(kSamples)
ad.test(datos~grupos,method = "exact")
## 
## 
##  Anderson-Darling k-sample test.
## 
## Number of samples:  3
## Sample sizes:  4, 4, 4
## Number of ties: 0
## 
## Mean of  Anderson-Darling  Criterion: 2
## Standard deviation of  Anderson-Darling  Criterion: 0.88133
## 
## T.AD = ( Anderson-Darling  Criterion - mean)/sigma
## 
## Null Hypothesis: All samples come from a common population.
## 
## Based on Nsim = 10000 simulations
## 
##                AD    T.AD  asympt. P-value  sim. P-value
## version 1: 2.6367 0.72238          0.18525        0.2084
## version 2: 2.6200 0.70807          0.18819        0.2157
## 
## 
## Warning: At least one sample size is less than 5,
##   asymptotic p-values may not be very accurate.

PRUEBA DE LA MEDIANA

datos <- c(20, 24, 28, 24, 20, 16, 26, 18, 17, 20, 23, 20, 18, 21, 17)
grupos <- c("Marca 1", "Marca 1", "Marca 1", "Marca 1", "Marca 1", 
            "Marca 2", "Marca 2", "Marca 2", "Marca 2", "Marca 2", 
            "Marca 3", "Marca 3", "Marca 3", "Marca 3", "Marca 3")
library(agricolae)
Median.test(datos,grupos)
## 
## The Median Test for datos ~ grupos 
## 
## Chi Square = 1.666667   DF = 2   P.Value 0.4345982
## Median = 20 
## 
##         Median r Min Max Q25 Q75
## Marca 1     24 5  20  28  20  24
## Marca 2     18 5  16  26  17  20
## Marca 3     20 5  17  23  18  21
## 
## Post Hoc Analysis
## 
## Groups according to probability of treatment differences and alpha level.
## 
## Treatments with the same letter are not significantly different.
## 
##         datos groups
## Marca 1    24      a
## Marca 3    20      a
## Marca 2    18      a

PRUEBA DE KRUSKAL WALLIS

datos <- c(86, 79, 81, 70, 84, 90, 76, 88, 82, 89, 82, 68, 63, 71, 61)
grupos <- c("Método A1", "Método A1", "Método A1", "Método A1", "Método A1", 
            "Método A2", "Método A2", "Método A2", "Método A2", "Método A2", 
            "Método A3", "Método A3", "Método A3", "Método A3", "Método A3")

library(agricolae)
kruskal(datos,grupos,group = F,console = T)
## 
## Study: datos ~ grupos
## Kruskal-Wallis test's
## Ties or no Ties
## 
## Critical Value: 6.917352
## Degrees of freedom: 2
## Pvalue Chisq  : 0.0314714 
## 
## grupos,  means of the ranks
## 
##           datos r
## Método A1   8.4 5
## Método A2  11.5 5
## Método A3   4.1 5
## 
## Post Hoc Analysis
## 
## Comparison between treatments mean of the ranks.
## 
##                       Difference pvalue Signif.       LCL       UCL
## Método A1 - Método A2       -3.1 0.1788         -7.830249  1.630249
## Método A1 - Método A3        4.3 0.0710       . -0.430249  9.030249
## Método A2 - Método A3        7.4 0.0052      **  2.669751 12.130249

PRUEBA DE VAN DE WAERDEN

datos <- c(30, 35, 60, 61, 41, 32, 70, 55, 77, 62, 57, 35, 41)
grupos <- c("C1", "C1", "C1", "C1", 
            "C2", "C2", "C2", "C2", "C2", 
            "C3", "C3", "C3", "C3")
library(agricolae)
waerden.test(datos,grupos,group = F,console = T)
## 
## Study: datos ~ grupos
## Van der Waerden (Normal Scores) test's
## 
## Value : 0.8951296
## Pvalue: 0.6391828
## Degrees of Freedom:  2 
## 
## grupos,  means of the normal score
## 
##           datos       std r
## C1 -0.302818951 0.9483235 4
## C2  0.239375069 1.0271414 5
## C3  0.006385294 0.6294832 4
## 
## Post Hoc Analysis
## 
## Comparison between treatments
## mean of the normal score
## 
##         difference pvalue signif.       LCL       UCL
## C1 - C2 -0.5421940 0.3905         -1.887970 0.8035815
## C1 - C3 -0.3092042 0.6377         -1.727776 1.1093677
## C2 - C3  0.2329898 0.7078         -1.112786 1.5787653

PRUEBA DE JONCKHEERE TERPSTRA

datos <- c(8.82, 11.27, 15.78, 17.39, 24.99, 39.05, 47.54, 48.85, 71.66, 72.77, 90.38, 103.13,
           13.53, 28.42, 48.11, 48.64, 51.40, 59.91, 67.98, 79.13, 103.05,
           19.23, 67.83, 73.68, 75.22, 77.71, 83.67, 86.83, 93.25,
           73.51, 85.25, 85.82, 88.88, 90.33, 118.11)

grupos <- c(rep("80", 12), 
            rep("50", 9), 
            rep("17", 8), 
            rep("10", 6))



x1 <- datos[grupos == "80"]
x2 <- datos[grupos == "50"]
x3 <- datos[grupos == "17"]
x4 <- datos[grupos == "10"]

jt.test(x1, x2, x3, x4, method = "asymptotic")
## 
## 
##  Jonckheere-Terpstra k-sample test.
## 
## Number of samples:  4
## Sample sizes:  12, 9, 8, 6
## Number of ties: 0
## 
## Null Hypothesis: All samples come from a common population.
## Alternative: Samples indicate a positive trend.
## 
##   test statistic               mu              sig  asympt. P-value 
##       3.3700e+02       2.2500e+02       3.3764e+01       4.5470e-04

PRUEVA DE LEVENE

datos <- c(86, 79, 81, 70, 84, 90, 76, 88, 82, 89, 82, 68, 63, 71, 61)
grupos <- c("Método A1", "Método A1", "Método A1", "Método A1", "Método A1", 
            "Método A2", "Método A2", "Método A2", "Método A2", "Método A2", 
            "Método A3", "Método A3", "Método A3", "Método A3", "Método A3")
library(lawstat)
levene.test(datos,grupos)
## 
##  Modified robust Brown-Forsythe Levene-type test based on the absolute
##  deviations from the median
## 
## data:  datos
## Test Statistic = 0.18391, p-value = 0.8343

PRUEBA DE FLIGNER KILLEEN

datos <- c(86, 79, 81, 70, 84, 90, 76, 88, 82, 89, 82, 68, 63, 71, 61)
grupos <- c("Método A1", "Método A1", "Método A1", "Método A1", "Método A1", 
            "Método A2", "Método A2", "Método A2", "Método A2", "Método A2", 
            "Método A3", "Método A3", "Método A3", "Método A3", "Método A3")
fligner.test(datos,grupos)
## 
##  Fligner-Killeen test of homogeneity of variances
## 
## data:  datos and grupos
## Fligner-Killeen:med chi-squared = 0.70427, df = 2, p-value = 0.7032

PRUEBA DE KLOTZ

datos <- c(6, 9, 15, 14, 5, 8, 8, 14, 11, 15,
           11, 15, 9, 4, 16, 18, 11, 6, 10, 19,
           8, 19, 14, 18, 4, 13, 20, 3, 7, 17,
           16, 17, 12, 10, 16, 18, 5, 7, 7, 5,
           5, 6, 12, 6, 3, 5, 12, 5, 10, 13)

grupos <- c(rep("Programa 1", 10),
            rep("Programa 2", 10),
            rep("Programa 3", 10),
            rep("Programa 4", 10),
            rep("Programa 5", 10))

library(coin)
klotz_test(datos ~ as.factor(grupos))
## 
##  Asymptotic K-Sample Klotz Test
## 
## data:  datos by
##   as.factor(grupos) (Programa 1, Programa 2, Programa 3, Programa 4, Programa 5)
## chi-squared = 8.3487, df = 4, p-value = 0.07961

PRUEBA DE CONOVER

datos <- c(86, 79, 81, 70, 84, 90, 76, 88, 82, 89, 82, 68, 63, 71, 61)
grupos <- c("Método A1", "Método A1", "Método A1", "Método A1", "Método A1", 
            "Método A2", "Método A2", "Método A2", "Método A2", "Método A2", 
            "Método A3", "Método A3", "Método A3", "Método A3", "Método A3")

library(coin)
conover_test(datos ~ as.factor(grupos))
## 
##  Asymptotic K-Sample Conover-Iman Test
## 
## data:  datos by
##   as.factor(grupos) (Método A1, Método A2, Método A3)
## chi-squared = 0.42077, df = 2, p-value = 0.8103

PRUEBA DE Q DE COCHRAN

res <- c(1, 1, 1, 1,
         1, 0, 0, 0,
         1, 0, 1, 0,
         1, 1, 1, 0,
         0, 0, 1, 0,
         0, 1, 1, 0,
         1, 0, 1, 1,
         0, 0, 1, 0,
         1, 1, 1, 0,
         0, 1, 1, 0)

tra <- gl(4, 1, 40, labels = c("Pregunta 1", "Pregunta 2", "Pregunta 3", "Pregunta 4"))
blo <- gl(10, 4, 40, labels = paste("Sujeto", 1:10))
library(RVAideMemoire)
cochran.qtest(res ~ tra | blo, p.method = "none")
## 
##  Cochran's Q test
## 
## data:  res by tra, block = blo 
## Q = 10, df = 3, p-value = 0.01857
## alternative hypothesis: true difference in probabilities is not equal to 0 
## sample estimates:
## proba in group Pregunta 1 proba in group Pregunta 2 proba in group Pregunta 3 
##                       0.6                       0.5                       0.9 
## proba in group Pregunta 4 
##                       0.2 
## 
##         Pairwise comparisons using Wilcoxon sign test
## 
##            Pregunta 1 Pregunta 2 Pregunta 3
## Pregunta 2      1.000          -          -
## Pregunta 3      0.375      0.125          -
## Pregunta 4      0.125      0.375    0.01563
## 
## P value adjustment method: none
# Con ajuste por comparaciones múltiples (ej. Bonferroni o Holm)
cochran.qtest(res ~ tra | blo, p.method = "bonferroni")
## 
##  Cochran's Q test
## 
## data:  res by tra, block = blo 
## Q = 10, df = 3, p-value = 0.01857
## alternative hypothesis: true difference in probabilities is not equal to 0 
## sample estimates:
## proba in group Pregunta 1 proba in group Pregunta 2 proba in group Pregunta 3 
##                       0.6                       0.5                       0.9 
## proba in group Pregunta 4 
##                       0.2 
## 
##         Pairwise comparisons using Wilcoxon sign test
## 
##            Pregunta 1 Pregunta 2 Pregunta 3
## Pregunta 2       1.00          -          -
## Pregunta 3       1.00       0.75          -
## Pregunta 4       0.75       1.00    0.09375
## 
## P value adjustment method: bonferroni

PRUEBA DE FRIEDMAN

datos <- c(5, 4, 5, 5, 5,
           2, 1, 2, 1, 2,
           3, 3, 2, 3, 3,
           2, 4, 3, 2, 3)

marca <- rep(c("Cola 1", "Cola 2", "Cola 3", "Nueva Cola"), each = 5)
jueces <- rep(paste("Juez", 1:5), times = 4)
library(agricolae)
friedman(jueces, marca, datos,console = T,group = F)
## 
## Study: datos ~ jueces + marca 
## 
## marca,  Sum of the ranks
## 
##            datos r
## Cola 1      19.5 5
## Cola 2       6.0 5
## Cola 3      12.0 5
## Nueva Cola  12.5 5
## 
## Friedman's Test
## ===============
## Adjusted for ties
## Critical Value: 11.93478
## P.Value Chisq: 0.00760994
## F Value: 15.57447
## P.Value F: 0.0001939151 
## 
## Post Hoc Analysis
## 
## Comparison between treatments
## Sum of the ranks
## 
##                     difference pvalue signif.    LCL   UCL
## Cola 1 - Cola 2           13.5 0.0000     ***   9.19 17.81
## Cola 1 - Cola 3            7.5 0.0026      **   3.19 11.81
## Cola 1 - Nueva Cola        7.0 0.0041      **   2.69 11.31
## Cola 2 - Cola 3           -6.0 0.0104       * -10.31 -1.69
## Cola 2 - Nueva Cola       -6.5 0.0065      ** -10.81 -2.19
## Cola 3 - Nueva Cola       -0.5 0.8048          -4.81  3.81

PRUEBA DE QUADE

datos <- c(5, 4, 7, 10, 12,
           1, 3, 1, 0, 2,
           16, 12, 22, 22, 35,
           5, 4, 3, 5, 4,
           10, 9, 7, 13, 10,
           19, 18, 28, 37, 58,
           10, 7, 6, 8, 7)

marca <- rep(c("A", "B", "C", "D", "E"), times = 7)
tienda <- rep(paste("Tienda", 1:7), each = 5)


quade.test(datos, marca, tienda)
## 
##  Quade test
## 
## data:  datos, marca and tienda
## Quade F = 3.8293, num df = 4, denom df = 24, p-value = 0.01519

PRUEBA DE PAGE

datos <- c(0.797, 0.873, 0.888, 0.923, 0.942, 0.956,
           0.794, 0.772, 0.908, 0.982, 0.946, 0.913,
           0.838, 0.801, 0.853, 0.951, 0.883, 0.837,
           0.815, 0.801, 0.747, 0.859, 0.887, 0.902)

eia <- factor(rep(c("204", "104", "56", "30", "13", "0"), times = 4),
              levels = c("204", "104", "56", "30", "13", "0"),
              ordered = TRUE)

sujeto <- factor(rep(c("A", "B", "C", "D"), each = 6))

library(DescTools)
PageTest(datos, eia, sujeto)
## 
##  Page test for ordered alternatives
## 
## data:  datos, eia and sujeto
## L = 342, p-value = 0.0005661

PRUEBA DE DURBIN

library(agricolae)
estudiantes<-gl(14,4)
definicion<-
c(1,3,4,6,2,3,5,6,1,2,6,7,4,5,6,7,2,5,7,8,1,4,7,8,3,4,5,8,1
,2,3,8,3,6,7,8,1,5,6,8,2,4,6,8,1,2,4,5,2,3,4,7,1,3,5,7)
puntajes<-
c(3,1,4,2,4,1,3,2,2,4,1,3,2,4,1,3,4,3,2,1,1,2,4,3,1,3,4,2,2
,4,1,3,1,2,3,4,1,4,2,3,4,2,1,3,1,3,2,4,4,2,1,3,2,1,4,3)
durbin.test(estudiantes,definicion,puntajes,group=T,console
=T)
## 
## Study: puntajes ~ estudiantes + definicion 
## definicion,  Sum of ranks
## 
##   sum
## 1  12
## 2  27
## 3   8
## 4  16
## 5  26
## 6  11
## 7  21
## 8  19
## 
## Durbin Test
## ===========
## Value      : 34.2
## DF 1       : 7
## P-value    : 1.580183e-05
## Alpha      : 0.05
## DF 2       : 35
## t-Student  : 2.030108
## 
## Least Significant Difference
## between the sum of ranks:  4.629358 
## 
## Parameters BIB
## Lambda     : 3
## Treatmeans : 8
## Block size : 4
## Blocks     : 14
## Replication: 7 
## 
## Treatments with the same letter are not significantly different.
## 
##   Sum of ranks groups
## 2           27      a
## 5           26      a
## 7           21      b
## 8           19     bc
## 4           16     cd
## 1           12     de
## 6           11      e
## 3            8      e

PRUEBA DE SKILLING MACK

# Valores por auto (filas 1 a 9) y aditivo (A, B, C, D)
# Nota: los guiones "-" en la tabla corresponden a valores perdidos (NA)
datos <- c(3.2, 4.1, 3.8, 4.2,   # Auto 1
           3.1, 3.9, 3.4, 4.0,   # Auto 2
           4.3, 3.5, 4.6, 4.8,   # Auto 3
           3.5, 3.6, 3.9, 4.0,   # Auto 4
           3.6, 4.2, 3.7, 3.9,   # Auto 5
           4.5, 4.7, 3.7, NA,    # Auto 6
           NA,  4.2, 3.4, NA,    # Auto 7
           4.3, 4.6, 4.4, 4.9,   # Auto 8
           3.5, NA,  3.7, 3.9)   # Auto 9

aditivo <- factor(rep(c("A", "B", "C", "D"), times = 9),
                  levels = c("A", "B", "C", "D"))

auto <- factor(rep(1:9, each = 4))
library(PMCMRplus)
skillingsMackTest(datos,aditivo,auto)
## 
##  Skillings-Mack test
## 
## data:  datos , aditivo and auto
## Skillings-Mack chi-squared = 15.493, df = 3, p-value = 0.00144