Anova dla zmiennych zależnych

Dane odpowiadają eksperymentowi, w którym badane jest leczenie depresji. Dwie grupy pacjentów (1: kontrola / 2: leczenie) były obserwowane w pięciu różnych terminach (0: przed badaniem, 1: miesiąc po badaniu, 3: 3 miesiące obserwacji i 6: 6 miesięcy obserwacji ). Zmienną zależną jest skala depresji. W celu określenia wpływu leczenia i wpływu czasu na wynik depresji można przeprowadzić powtarzaną analizę ANOVA.

Dane

depression <- depression %>%
  gather(key = "time", value = "score",t0, t1, t2, t3) %>%
  convert_as_factor(id, time,treatment)
head(depression, 3)
## # A tibble: 3 x 4
##   id    treatment time  score
##   <fct> <fct>     <fct> <dbl>
## 1 1     ctr       t0      296
## 2 2     ctr       t0      376
## 3 3     ctr       t0      309

Statystyki opisowe

ggboxplot(depression, x = "time", y = "score", color = "treatment")

ggplot(depression, aes(x=score)) +
  geom_histogram(bins=10) 

### Założenia H0: “Wynik depresji” nie różni się istotnie dla różnych wariantów czasowych i leczenia. H1: “Wynik depresji” różni się istotnie dla różnych wariantów czasowych i leczenia. ## Założenie o normalności:

depression%>%
  group_by(time,treatment)%>%
  shapiro_test(score)
## # A tibble: 8 x 5
##   treatment time  variable statistic      p
##   <fct>     <fct> <chr>        <dbl>  <dbl>
## 1 ctr       t0    score        0.945 0.572 
## 2 treated   t0    score        0.836 0.0248
## 3 ctr       t1    score        0.918 0.268 
## 4 treated   t1    score        0.953 0.680 
## 5 ctr       t2    score        0.951 0.652 
## 6 treated   t2    score        0.957 0.734 
## 7 ctr       t3    score        0.873 0.0706
## 8 treated   t3    score        0.932 0.398
ggqqplot(depression, "score") + facet_grid(time~treatment)

Jedynie w przypadku osób leczoych w okresie t0 ,p<alfa. Dla reszty zachododzi normalność. ##Założenie o braku wartości odstających:

depression%>%
  group_by(time,treatment)%>%
  identify_outliers(score)
## # A tibble: 4 x 6
##   treatment time  id    score is.outlier is.extreme
##   <fct>     <fct> <fct> <dbl> <lgl>      <lgl>     
## 1 ctr       t0    5       150 TRUE       FALSE     
## 2 ctr       t0    8       447 TRUE       FALSE     
## 3 treated   t0    18      138 TRUE       FALSE     
## 4 treated   t0    22      150 TRUE       FALSE

Występują 4 odchylenia, jednak nie są one bardzo istotne. ## Anova

wyniki<-anova_test(data=depression, formula = score~treatment*time,wid = id, within = time)
## Coefficient covariances computed by hccm()
get_anova_table(wyniki)
## ANOVA Table (type II tests)
## 
##           Effect DFn DFd      F        p p<.05   ges
## 1      treatment   1  88 43.423 3.13e-09     * 0.330
## 2           time   3  88 19.713 7.31e-10     * 0.402
## 3 treatment:time   3  88  3.755 1.40e-02     * 0.113
wyniki$`Mauchly's Test for Sphericity`
## NULL

Wyniki istotnie różnią się dla różnych wariantów czasowych oraz leczenia. ## Testy post-hoc

depression %>%
  group_by(treatment) %>%
  emmeans_test(score~time)
## # A tibble: 12 x 10
##    treatment term  .y.   group1 group2    df statistic            p        p.adj
##  * <chr>     <chr> <chr> <chr>  <chr>  <dbl>     <dbl>        <dbl>        <dbl>
##  1 ctr       time  score t0     t1        88     1.60  0.113        0.676       
##  2 ctr       time  score t0     t2        88     2.98  0.00375      0.0225      
##  3 ctr       time  score t0     t3        88     3.60  0.000520     0.00312     
##  4 ctr       time  score t1     t2        88     1.38  0.172        1           
##  5 ctr       time  score t1     t3        88     2.00  0.0485       0.291       
##  6 ctr       time  score t2     t3        88     0.625 0.534        1           
##  7 treated   time  score t0     t1        88     6.25  0.0000000142 0.0000000855
##  8 treated   time  score t0     t2        88     6.05  0.0000000338 0.000000203 
##  9 treated   time  score t0     t3        88     5.84  0.0000000854 0.000000513 
## 10 treated   time  score t1     t2        88    -0.196 0.845        1           
## 11 treated   time  score t1     t3        88    -0.409 0.683        1           
## 12 treated   time  score t2     t3        88    -0.213 0.832        1           
## # ... with 1 more variable: p.adj.signif <chr>
  • W każdym teście odrzucona jest H0 o braku różnic między zmiennymi
  • Wszystkie pary różnią się między sobą istotnie!

Wnioski i podsumowanie

ggwithinstats(data=depression,x=time, y=score,grouping.var=treatment, type="P")