El conjunto de datos cancer.csv contiene los resultados de un estudio que mide las capacidades orales de enfermos de cáncer de garganta. Las medidas están tomadas inicialmente y a las 2, 4 y 6 semanas de tratamiento. Además las variables edad, peso inicial y estado inicial del cáncer (del 1 al 4) fueron medidas para cada paciente. En el hospital, a un grupo se le administra un placebo (0) y al otro un tratamiento (1).
Determina si hay diferencias en la media de la capacidad oral de los enfermos en la segunda semana (Variable TOTALCW2) según el grupo de edad (AGE) al que pertenece el enfermo y el tratamiento que se le da (TRT)
Determina si la semana de tratamiento influye en las capacidades orales de aquellos que están sometidos al tratamiento 1.
Determina si la semana de tratamiento y el grupo de edad al que pertenece el enfermo influyen en las capacidades orales.
Solución
cancer <- read.table( "../files/cancer.csv", header = T, sep = ";")
head( cancer )
## ID TRT AGE WEIGHIN STAGE TOTALCIN TOTALCW2
## 1 1 0 1 124 2 6 6
## 2 5 0 2 160 1 9 6
## 3 6 0 2 136 5 4 7
## 4 9 0 2 179 6 1 6
## 5 11 0 1 175 8 2 6
## 6 15 0 2 167 6 1 6
## TOTALCW4 TOTALCW6 X
## 1 6 7 NA
## 2 10 9 NA
## 3 9 10 13
## 4 7 9 3
## 5 7 16 13
## 6 6 6 9
TRT y AGETOTALCW2Estudiamos la normalidad:
shapiro.test( cancer$TOTALCW2[cancer$TRT == 0])
##
## Shapiro-Wilk normality test
##
## data: cancer$TOTALCW2[cancer$TRT == 0]
## W = 0.80479, p-value = 0.01063
shapiro.test( cancer$TOTALCW2[cancer$TRT == 1])
##
## Shapiro-Wilk normality test
##
## data: cancer$TOTALCW2[cancer$TRT == 1]
## W = 0.93808, p-value = 0.4982
shapiro.test( cancer$TOTALCW2[cancer$AGE == 1])
##
## Shapiro-Wilk normality test
##
## data: cancer$TOTALCW2[cancer$AGE == 1]
## W = 0.85859, p-value = 0.0552
shapiro.test( cancer$TOTALCW2[cancer$AGE == 2])
##
## Shapiro-Wilk normality test
##
## data: cancer$TOTALCW2[cancer$AGE == 2]
## W = 0.82096, p-value = 0.01638
No hay normalidad en dos casos pero continúamos por ser el ANOVA robusto a la falta de normalidad.
Estudiamos la homocedasticidad:
fligner.test( TOTALCW2 ~ TRT, data = cancer)
##
## Fligner-Killeen test of homogeneity of
## variances
##
## data: TOTALCW2 by TRT
## Fligner-Killeen:med chi-squared = 0.030806,
## df = 1, p-value = 0.8607
fligner.test( TOTALCW2 ~ AGE, data = cancer)
##
## Fligner-Killeen test of homogeneity of
## variances
##
## data: TOTALCW2 by AGE
## Fligner-Killeen:med chi-squared = 0.083237,
## df = 1, p-value = 0.773
Anova de 2 vías:
fitCanc <- aov( TOTALCW2 ~ AGE * TRT, data = cancer )
summary( fitCanc )
## Df Sum Sq Mean Sq F value Pr(>F)
## AGE 1 9.63 9.631 2.760 0.113
## TRT 1 0.26 0.263 0.075 0.787
## AGE:TRT 1 10.41 10.414 2.984 0.100
## Residuals 19 66.30 3.489
La interacción AGE:TRT no es significativa.
library( reshape2 )
cancRe <- melt( cancer, id = c( "ID", "TRT", "AGE" ),
measure = c( "TOTALCW2", "TOTALCW4", "TOTALCW6" ),
variable.name = "SEMANA",
value.name = "CAP.ORAL" )
head( cancRe )
## ID TRT AGE SEMANA CAP.ORAL
## 1 1 0 1 TOTALCW2 6
## 2 5 0 2 TOTALCW2 6
## 3 6 0 2 TOTALCW2 7
## 4 9 0 2 TOTALCW2 6
## 5 11 0 1 TOTALCW2 6
## 6 15 0 2 TOTALCW2 6
shapiro.test( cancRe$CAP.ORAL[cancRe$SEMANA == "TOTALCW2"])
##
## Shapiro-Wilk normality test
##
## data: cancRe$CAP.ORAL[cancRe$SEMANA == "TOTALCW2"]
## W = 0.86093, p-value = 0.004322
shapiro.test( cancRe$CAP.ORAL[cancRe$SEMANA == "TOTALCW4"])
##
## Shapiro-Wilk normality test
##
## data: cancRe$CAP.ORAL[cancRe$SEMANA == "TOTALCW4"]
## W = 0.90258, p-value = 0.02858
shapiro.test( cancRe$CAP.ORAL[cancRe$SEMANA == "TOTALCW6"])
##
## Shapiro-Wilk normality test
##
## data: cancRe$CAP.ORAL[cancRe$SEMANA == "TOTALCW6"]
## W = 0.90432, p-value = 0.03106
No hay normalidad, pero seguimos igual que antes por ser el ANOVA robusto a la falta de normalidad.
ezANOVA()La función ezANOVA() del paquete ez además del modelo ANOVA lleva a cabo el análisis de supuestos previo:
library( ez )
options( contrasts = c( "contr.sum", "contr.poly" ) )
ezANOVA( data = cancRe[cancRe$TRT == "1",], dv = CAP.ORAL,
wid = ID, within = SEMANA,
type = 3 )
## Warning: Converting "ID" to factor for ANOVA.
## $ANOVA
## Effect DFn DFd F p p<.05
## 2 SEMANA 2 20 13.66157 0.0001817878 *
## ges
## 2 0.2231766
##
## $`Mauchly's Test for Sphericity`
## Effect W p p<.05
## 2 SEMANA 0.5359066 0.0603811
##
## $`Sphericity Corrections`
## Effect GGe p[GG] p[GG]<.05
## 2 SEMANA 0.6830165 0.001303836 *
## HFe p[HF] p[HF]<.05
## 2 0.7543673 0.0008344518 *
El test de Mauchly es significativo por lo que no podemos aceptar la hipótesis de esfericidad.
Como GGe < 0.75 usamos la corrección de Greenhouse-Geisser.
\(p\)-valor significativo \(\Rightarrow\) Aceptamos que el mes tiene un efecto significativo.
cancRe$AGE <- factor( cancRe$AGE ) #Convertimos la edad en factor
shapiro.test( cancRe$CAP.ORAL[cancRe$AGE == "1"] )
##
## Shapiro-Wilk normality test
##
## data: cancRe$CAP.ORAL[cancRe$AGE == "1"]
## W = 0.88513, p-value = 0.00224
shapiro.test( cancRe$CAP.ORAL[cancRe$AGE == "2"])
##
## Shapiro-Wilk normality test
##
## data: cancRe$CAP.ORAL[cancRe$AGE == "2"]
## W = 0.87711, p-value = 0.0008554
ezANOVA().ezANOVA( data = cancRe[cancRe$TRT == "1",], dv = CAP.ORAL,
wid = ID, within = SEMANA, between = AGE,
type = 3 )
## $ANOVA
## Effect DFn DFd F p
## 2 AGE 1 9 3.9450249 0.0782731623
## 3 SEMANA 2 18 12.3146248 0.0004266614
## 4 AGE:SEMANA 2 18 0.2587614 0.7748301997
## p<.05 ges
## 2 0.242087594
## 3 * 0.270724145
## 4 0.007739965
##
## $`Mauchly's Test for Sphericity`
## Effect W p p<.05
## 3 SEMANA 0.5052949 0.06518982
## 4 AGE:SEMANA 0.5052949 0.06518982
##
## $`Sphericity Corrections`
## Effect GGe p[GG] p[GG]<.05
## 3 SEMANA 0.6690283 0.002596476 *
## 4 AGE:SEMANA 0.6690283 0.687906210
## HFe p[HF] p[HF]<.05
## 3 0.7426684 0.001732208 *
## 4 0.7426684 0.710920137
Aceptamos la esfericidad por el test de Mauchly, luego el \(p\)-valor es 0.7748 por lo que el efecto de la interacción no es significativo.